vercel / vercel/next.js

`use cache: private` not working during client-side navigation

Open
#85,672 21 comments 28 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Cache Components linear: next
Dominant language
JavaScript
Stars
142k
Forks
32.4k
Avg merge
2d 14h
Merged PRs (30d)
351

Description

Link to the code that reproduces this issue

https://github.com/ajaykarthikr/next-16-use-cache-private-bug

To Reproduce
  1. Create a cached function with "use cache: private" that uses cookies():

    // lib/user.ts
    import { cookies } from "next/headers";
    import { cacheTag, cacheLife } from "next/cache";
    
    export async function getUser() {
        "use cache: private";
        cacheTag(`userdata`);
        cacheLife({ stale: 30 });
        
        const sessionId = (await cookies()).get('session-id')?.value || 'guest'
        
        console.log("Fetching user data"); // This logs on every navigation
        await new Promise((resolve) => setTimeout(resolve, 5000));
        const timestamp = new Date().toISOString();
    
        return {
            user: {
                name: "Ajay",
                email: "ajay@example.com"
            },
            timestamp: timestamp,
        }
    }
    
  2. Use this function in a Server Component page:

    // app/about/page.tsx
    import { Suspense } from "react";
    import { getUser } from "../../lib/user";
    
    export default async function Page() {
        return (
            <div>
                <h1>About Page</h1>
                <Suspense fallback={<p>Loading...</p>}>
                    <Content />
                </Suspense>
            </div>
        )
    }
    
    async function Content() {
        const data = await getUser();
        return (
            <div>
                <h1>{data.user.name}</h1>
                <p>Fetched at: {data.timestamp}</p>
            </div>
        );
    }
    
  3. Configure next.config.ts:

    import type { NextConfig } from "next";
    
    const nextConfig: NextConfig = {
    cacheComponents: true,
    };
    
    export default nextConfig;
    
  4. Navigate to the page (e.g., /about), then navigate away, then navigate back using client-side navigation (using component)

Current vs. Expected behavior

Expected: The cached function should return the cached result during the 30-second stale period, showing the same timestamp and not logging "Fetching user data" on subsequent navigations.

Actual: The function re-executes on every client-side navigation, showing a new timestamp each time and logging "Fetching user data" in the console.

Demo: https://next-16-use-cache-private-bug.vercel.app/

Provide environment information
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.0.0: Wed Sep 17 21:42:08 PDT 2025; root:xnu-12377.1.9~141/RELEASE_ARM64_T8132
  Available memory (MB): 24576
  Available CPU cores: 10
Binaries:
  Node: 22.20.0
  npm: 10.9.3
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 16.0.2-canary.3 // Latest available version is detected (16.0.2-canary.3).
  eslint-config-next: N/A
  react: 19.2.0
  react-dom: 19.2.0
  typescript: 5.9.3
Next.js Config:
  output: N/A
Which area(s) are affected? (Select all that apply)

Use Cache

Which stage(s) are affected? (Select all that apply)

next start (local), Vercel (Deployed)

Additional context
  • The "use cache: private" directive is supposed to work with cookies() API according to the documentation
  • This appears to be related to Router Cache interaction with function-level caching during client-side navigation
  • The 2-second artificial delay in the reproduction makes it easy to observe when the function re-executes

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked reproduction, especially lib/user.ts, app/about/page.tsx, and next.config.ts. Run it with client-side navigation and compare the timestamp and “Fetching user data” log across revisits. Done means the private cached function reuses its result during the 30-second stale period instead of executing on every navigation.

Written by the indexing model from the issue text.

Assessment

Tech stack
nextjs, react, typescript
Domain
full-stack, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.