-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Description
Link to the code that reproduces this issue
https://codesandbox.io/p/github/Donggggg/nextjs-router-cache-test-app/main
To Reproduce
1.Visit a dynamic page (e.g., /posts/[id]).
→ RSC payload is fetched as expected.
- Navigate to the same page with a query parameter (e.g., /posts/[id]?tab=recent).
- back
- Visit same page using with prefetch
→ No RSC payload request is sent over the network. It appears to reuse a cached payload from the Router Cache.
However, if I start from the plain /posts/[id] page (without any query) or /posts/[id]?tab=recent (already have query) and re-enter it again via client navigation, the RSC payload is fetched every time as expected.
So this behavior only happens after a query parameter was added.
Current vs. Expected behavior
Because the page is declared dynamic (revalidate = 0), adding query parameters should not make it static or cached by the Router Cache.
Each navigation should trigger a fresh RSC payload request.
Provide environment information
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 24.2.0: Fri Dec 6 18:51:28 PST 2024; root:xnu-11215.61.5~2/RELEASE_ARM64_T8112
Available memory (MB): 16384
Available CPU cores: 8
Binaries:
Node: 22.17.0
npm: 10.9.2
Yarn: 4.5.0
pnpm: 10.7.0
Relevant Packages:
next: 15.5.6
eslint-config-next: N/A
react: 19.2.0
react-dom: 19.2.0
typescript: 5.4.5
Next.js Config:
output: N/AWhich area(s) are affected? (Select all that apply)
Dynamic Routes
Which stage(s) are affected? (Select all that apply)
Other (Deployed), next start (local)
Additional context
When I set the following experimental config:
experimental: {
staleTimes: {
dynamic: 0,
static: 0,
},
},
…the RSC payload is fetched on every navigation as expected (no cache reuse).
That suggests the page was being mistakenly treated as static once query params were added, and the Router Cache then reused it on re-entry.
Additionally, when I disabled prefetch by setting prefetch={false} on the <Link> component and tested the same navigation scenario, the RSC payload was correctly requested again.
This indicates that the issue only occurs when the navigation is prefetched and subsequently cached by the Router Cache.