Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
41c4ca5b
Unverified
Commit
41c4ca5b
authored
Sep 15, 2026
by
Arya
Committed by
Hendrik Liebau
Sep 16, 2026
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(use-cache): track root params read in "use cache" as vary params
parent
52788bdf
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
80 additions
and
4 deletions
+80
-4
use-cache-wrapper.ts
packages/next/src/server/use-cache/use-cache-wrapper.ts
+19
-4
layout.tsx
...he/vary-params/app/cached-root-params/[locale]/layout.tsx
+28
-0
page.tsx
...ache/vary-params/app/cached-root-params/[locale]/page.tsx
+7
-0
vary-params.test.ts
...e2e/app-dir/segment-cache/vary-params/vary-params.test.ts
+26
-0
No files found.
packages/next/src/server/use-cache/use-cache-wrapper.ts
View file @
41c4ca5b
...
...
@@ -28,6 +28,7 @@ import type {
import
{
getHmrRefreshHash
,
getResumeDataCache
,
getVaryParamsAccumulator
,
workUnitAsyncStorage
,
getDraftModeProviderForCacheScope
,
getCacheSignal
,
...
...
@@ -35,6 +36,7 @@ import {
getServerComponentsHmrCache
,
willConsumerServerCache
,
}
from
'../app-render/work-unit-async-storage.external'
import
{
accumulateVaryParam
}
from
'../app-render/vary-params'
import
{
applyOwnerStack
,
...
...
@@ -1029,6 +1031,17 @@ function propagateCacheEntryMetadata(
cacheContext
.
outerWorkUnitStore
satisfies
never
}
}
if
(
metadata
.
readRootParamNames
)
{
const
varyParamsAccumulator
=
getVaryParamsAccumulator
(
cacheContext
.
outerWorkUnitStore
)
if
(
varyParamsAccumulator
)
{
for
(
const
paramName
of
metadata
.
readRootParamNames
)
{
accumulateVaryParam
(
varyParamsAccumulator
.
rootParams
,
paramName
)
}
}
}
}
/**
...
...
@@ -1041,10 +1054,12 @@ function propagateCacheEntryMetadata(
* `propagateCacheEntryMetadata` is called unconditionally (after the omission
* checks have already filtered out short-lived entries).
*
* Note: Root param names are only propagated when the outer context is a
* `cache` store (i.e. an enclosing `"use cache"` function), which is never
* deferred. For prerender contexts, root param names are tracked separately
* via `addKnownRootParamNames` in the resume data cache read path.
* Note: Root param names are only propagated to `readRootParamNames` when the
* outer context is a `cache` store (i.e. an enclosing `"use cache"` function),
* which is never deferred. For prerender contexts, root param names are
* tracked separately via `addKnownRootParamNames` in the resume data cache
* read path. They're also recorded as root vary params (if tracked), so that
* the client doesn't reuse the segment across different values.
*/
function
maybePropagateCacheEntryMetadata
(
cacheContext
:
CacheContext
,
...
...
test/e2e/app-dir/segment-cache/vary-params/app/cached-root-params/[locale]/layout.tsx
0 → 100644
View file @
41c4ca5b
'use cache'
import
Link
from
'next/link'
import
{
locale
}
from
'next/root-params'
export
async
function
generateStaticParams
()
{
return
[{
locale
:
'en'
},
{
locale
:
'de'
}]
}
export
default
async
function
Layout
({
children
,
}:
{
children
:
React
.
ReactNode
})
{
return
(
<
html
lang=
{
await
locale
()
}
>
<
body
>
<
Link
href=
"/cached-root-params/en"
prefetch=
{
false
}
>
en
</
Link
>
<
Link
href=
"/cached-root-params/de"
prefetch=
{
false
}
>
de
</
Link
>
{
children
}
</
body
>
</
html
>
)
}
test/e2e/app-dir/segment-cache/vary-params/app/cached-root-params/[locale]/page.tsx
0 → 100644
View file @
41c4ca5b
'use cache'
import
{
locale
}
from
'next/root-params'
export
default
async
function
Page
()
{
return
<
div
id=
"cached-root-param"
>
{
`Locale: ${await locale()}`
}
</
div
>
}
test/e2e/app-dir/segment-cache/vary-params/vary-params.test.ts
View file @
41c4ca5b
...
...
@@ -822,4 +822,30 @@ describe('segment cache - vary params', () => {
{
includes
:
'Root param page content - param: bbb'
}
)
})
it
(
'does not reuse a "use cache" segment across root param values'
,
async
()
=>
{
let
act
:
ReturnType
<
typeof
createRouterAct
>
const
browser
=
await
next
.
browser
(
'/cached-root-params/en'
,
{
beforePageLoad
(
p
:
Playwright
.
Page
)
{
act
=
createRouterAct
(
p
)
},
})
expect
(
await
browser
.
elementById
(
'cached-root-param'
).
text
()).
toBe
(
'Locale: en'
)
// Not prefetched, so the navigation fetches /de and must not reuse the
// page segment cached for /en.
await
act
(
async
()
=>
{
const
link
=
await
browser
.
elementByCss
(
'a[href="/cached-root-params/de"]'
)
await
link
.
click
()
})
expect
(
await
browser
.
elementById
(
'cached-root-param'
).
text
()).
toBe
(
'Locale: de'
)
})
})
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment