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
1d3554af
Commit
1d3554af
authored
Jan 14, 2026
by
Zack Tanner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: RDC data should be merged when generating fallback shells
parent
9725c47a
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
322 additions
and
8 deletions
+322
-8
errors.json
packages/next/errors.json
+4
-1
index.ts
packages/next/src/export/index.ts
+39
-5
resume-data-cache-utils.ts
packages/next/src/export/resume-data-cache-utils.ts
+39
-0
module.ts
packages/next/src/server/route-modules/app-route/module.ts
+7
-2
page.tsx
...ppr-root-param-fallback/app/[locale]/blog/[slug]/page.tsx
+84
-0
layout.tsx
...e/app-dir/ppr-root-param-fallback/app/[locale]/layout.tsx
+83
-0
page.tsx
...e2e/app-dir/ppr-root-param-fallback/app/[locale]/page.tsx
+28
-0
next.config.js
test/e2e/app-dir/ppr-root-param-fallback/next.config.js
+8
-0
ppr-root-param-fallback.test.ts
...r/ppr-root-param-fallback/ppr-root-param-fallback.test.ts
+30
-0
No files found.
packages/next/errors.json
View file @
1d3554af
...
...
@@ -977,5 +977,8 @@
"976"
:
"Decompressed resume data cache exceeded %s byte limit"
,
"977"
:
"maxPostponedStateSize must be a valid number (bytes) or filesize format string (e.g.,
\"
5mb
\"
)"
,
"978"
:
"Next.js has blocked a javascript: URL as a security precaution."
,
"979"
:
"invariant: expected %s bytes of postponed state but only received %s bytes"
"979"
:
"invariant: expected %s bytes of postponed state but only received %s bytes"
,
"980"
:
"`parseSerializedResumeDataCache` should not be called in edge runtime."
,
"981"
:
"`mergeResumeDataCaches` should not be called in edge runtime."
,
"982"
:
"`stringifyParsedResumeDataCache` should not be called in edge runtime."
}
packages/next/src/export/index.ts
View file @
1d3554af
...
...
@@ -68,6 +68,11 @@ import { isInterceptionRouteRewrite } from '../lib/generate-interception-routes-
import
type
{
ActionManifest
}
from
'../build/webpack/plugins/flight-client-entry-plugin'
import
{
extractInfoFromServerReferenceId
}
from
'../shared/lib/server-reference-info'
import
{
convertSegmentPathToStaticExportFilename
}
from
'../shared/lib/segment-cache/segment-value-encoding'
import
{
parseSerializedResumeDataCache
,
stringifyParsedResumeDataCache
,
type
ResumeStoreSerialized
,
}
from
'./resume-data-cache-utils'
import
{
getNextBuildDebuggerPortOffset
}
from
'../lib/worker'
export
class
ExportError
extends
Error
{
...
...
@@ -663,7 +668,10 @@ async function exportAppImpl(
results
=
await
exportPagesInBatches
(
worker
,
initialPhaseExportPaths
)
if
(
finalPhaseExportPaths
.
length
>
0
)
{
const
renderResumeDataCachesByPage
:
Record
<
string
,
string
>
=
{}
// Collect and merge RDC entries from all routes for each page.
// Different routes (e.g., /en/blog/hello-world and /fr/blog/hello-world)
// may have populated different cache entries that the fallback shell needs.
const
parsedCachesByPage
:
Record
<
string
,
ResumeStoreSerialized
>
=
{}
for
(
const
{
page
,
result
}
of
results
)
{
if
(
!
result
)
{
...
...
@@ -671,16 +679,42 @@ async function exportAppImpl(
}
if
(
'renderResumeDataCache'
in
result
&&
result
.
renderResumeDataCache
)
{
// The last RDC for each page is used. We only need one. It should have
// all the entries that the fallback shell also needs. We don't need to
// merge them per page.
renderResumeDataCachesByPage
[
page
]
=
result
.
renderResumeDataCache
const
parsed
=
parseSerializedResumeDataCache
(
result
.
renderResumeDataCache
)
if
(
parsed
)
{
const
existing
=
parsedCachesByPage
[
page
]
if
(
existing
)
{
// Merge entries (later entries win for duplicates)
existing
.
store
.
cache
=
{
...
existing
.
store
.
cache
,
...
parsed
.
store
.
cache
,
}
existing
.
store
.
fetch
=
{
...
existing
.
store
.
fetch
,
...
parsed
.
store
.
fetch
,
}
existing
.
store
.
encryptedBoundArgs
=
{
...
existing
.
store
.
encryptedBoundArgs
,
...
parsed
.
store
.
encryptedBoundArgs
,
}
}
else
{
parsedCachesByPage
[
page
]
=
parsed
}
}
// Remove the RDC string from the result so that it can be garbage
// collected, when there are more results for the same page.
result
.
renderResumeDataCache
=
undefined
}
}
// Serialize merged caches once for the final phase
const
renderResumeDataCachesByPage
:
Record
<
string
,
string
>
=
{}
for
(
const
[
page
,
parsed
]
of
Object
.
entries
(
parsedCachesByPage
))
{
renderResumeDataCachesByPage
[
page
]
=
stringifyParsedResumeDataCache
(
parsed
)
}
const
finalPhaseResults
=
await
exportPagesInBatches
(
worker
,
finalPhaseExportPaths
,
...
...
packages/next/src/export/resume-data-cache-utils.ts
0 → 100644
View file @
1d3554af
/**
* Utilities for parsing and serializing Resume Data Cache during build.
*/
export
type
ResumeStoreSerialized
=
{
store
:
{
cache
:
{
[
key
:
string
]:
any
}
fetch
:
{
[
key
:
string
]:
any
}
encryptedBoundArgs
:
{
[
key
:
string
]:
string
}
}
}
/**
* Parses a compressed serialized resume data cache string into a JSON object.
* Used during build to collect and merge RDCs from multiple routes.
*/
export
function
parseSerializedResumeDataCache
(
serialized
:
string
):
ResumeStoreSerialized
|
null
{
if
(
serialized
===
'null'
||
!
serialized
)
return
null
const
{
inflateSync
}
=
require
(
'node:zlib'
)
as
typeof
import
(
'node:zlib'
)
return
JSON
.
parse
(
inflateSync
(
Buffer
.
from
(
serialized
,
'base64'
),
{
maxOutputLength
:
500
*
1024
*
1024
,
// 500MB limit for zip bomb protection
}).
toString
(
'utf-8'
)
)
}
/**
* Compresses a ResumeStoreSerialized object into a base64 string.
* Used during build after merging RDCs from multiple routes.
*/
export
function
stringifyParsedResumeDataCache
(
parsed
:
ResumeStoreSerialized
):
string
{
const
{
deflateSync
}
=
require
(
'node:zlib'
)
as
typeof
import
(
'node:zlib'
)
return
deflateSync
(
JSON
.
stringify
(
parsed
)).
toString
(
'base64'
)
}
packages/next/src/server/route-modules/app-route/module.ts
View file @
1d3554af
...
...
@@ -87,7 +87,7 @@ import { INFINITE_CACHE } from '../../../lib/constants'
import
{
executeRevalidates
}
from
'../../revalidation-utils'
import
{
trackPendingModules
}
from
'../../app-render/module-loading/track-module-loading.external'
import
{
InvariantError
}
from
'../../../shared/lib/invariant-error'
import
{
create
PrerenderResumeDataCache
}
from
'../../resume-data-cache/resume-data-cache'
import
type
{
PrerenderResumeDataCache
}
from
'../../resume-data-cache/resume-data-cache'
export
class
WrappedNextRouterError
{
constructor
(
...
...
@@ -395,7 +395,12 @@ export class AppRouteRouteModule extends RouteModule<
// `renderResumeDataCache` with a single `dataCache` property that is
// conceptually not tied to resuming, and also avoids the unnecessary
// complexity of using a mutable and an immutable resume data cache.
const
prerenderResumeDataCache
=
createPrerenderResumeDataCache
()
const
prerenderResumeDataCache
:
PrerenderResumeDataCache
=
{
cache
:
new
Map
(),
fetch
:
new
Map
(),
encryptedBoundArgs
:
new
Map
(),
decryptedBoundArgs
:
new
Map
(),
}
const
prospectiveRoutePrerenderStore
:
PrerenderStore
=
(
prerenderStore
=
{
...
...
test/e2e/app-dir/ppr-root-param-fallback/app/[locale]/blog/[slug]/page.tsx
0 → 100644
View file @
1d3554af
import
{
Suspense
}
from
'react'
import
{
cookies
}
from
'next/headers'
import
Link
from
'next/link'
async
function
getBlogPost
(
locale
:
string
,
slug
:
string
)
{
'use cache'
// Simulate expensive operation like fetching from a CMS
await
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
700
))
return
{
title
:
`Blog Post:
${
slug
}
`
,
locale
,
content
:
'This content was fetched from the CMS...'
,
relatedPosts
:
[
'Related Post 1'
,
'Related Post 2'
,
'Related Post 3'
],
}
}
export
default
async
function
BlogPost
({
params
,
}:
{
params
:
Promise
<
{
locale
:
string
;
slug
:
string
}
>
})
{
return
(
<
main
>
<
div
id=
"static-blog-header"
>
Blog Article
</
div
>
<
div
id=
"static-reading-time"
>
Estimated reading time: 5 minutes
</
div
>
<
Suspense
fallback=
{
<
div
id=
"blog-loading"
>
Loading article...
</
div
>
}
>
<
BlogContent
params=
{
params
}
/>
</
Suspense
>
<
Suspense
fallback=
{
<
div
id=
"dynamic-loading"
>
Loading comments...
</
div
>
}
>
<
DynamicComments
/>
</
Suspense
>
</
main
>
)
}
// This component depends on locale and slug, so it's in Suspense
async
function
BlogContent
({
params
,
}:
{
params
:
Promise
<
{
locale
:
string
;
slug
:
string
}
>
})
{
const
{
locale
,
slug
}
=
await
params
const
post
=
await
getBlogPost
(
locale
,
slug
)
return
(
<>
<
article
id=
"blog-content"
>
<
h1
>
{
post
.
title
}
</
h1
>
<
p
>
Locale:
{
post
.
locale
}
</
p
>
<
p
>
{
post
.
content
}
</
p
>
</
article
>
<
aside
id=
"related-posts"
>
<
h2
>
Related Posts (
{
post
.
locale
}
)
</
h2
>
<
ul
>
{
post
.
relatedPosts
.
map
((
title
,
i
)
=>
(
<
li
key=
{
i
}
>
<
Link
href=
{
`/en/blog/${i}`
}
>
{
title
}
</
Link
>
</
li
>
))
}
</
ul
>
</
aside
>
</>
)
}
async
function
DynamicComments
()
{
// This is truly dynamic (uses cookies), always renders at request time
const
cookieStore
=
await
cookies
()
const
user
=
cookieStore
.
get
(
'user'
)?.
value
||
'anonymous'
return
(
<
section
id=
"comments"
>
<
h3
>
Comments
</
h3
>
<
p
>
Viewing as:
{
user
}
</
p
>
</
section
>
)
}
// Generate some slugs for each locale
// This means for 'en' and 'fr', we have route shells for specific slugs
// But for 'de' (not in parent generateStaticParams), we have nothing
export
function
generateStaticParams
()
{
return
[{
slug
:
'hello-world'
},
{
slug
:
'getting-started'
}]
}
test/e2e/app-dir/ppr-root-param-fallback/app/[locale]/layout.tsx
0 → 100644
View file @
1d3554af
import
{
Suspense
}
from
'react'
import
{
cookies
}
from
'next/headers'
// Simulate an expensive cached operation (like fetching translations, config, etc.)
async
function
getLocaleConfig
(
localeParam
:
string
)
{
'use cache'
// Simulate expensive operation like fetching from a CMS or database
await
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
800
))
return
{
locale
:
localeParam
,
translations
:
{
home
:
`Home (
${
localeParam
}
)`
,
blog
:
`Blog (
${
localeParam
}
)`
,
about
:
`About (
${
localeParam
}
)`
,
},
}
}
export
default
async
function
LocaleLayout
({
children
,
params
,
}:
{
children
:
React
.
ReactNode
params
:
Promise
<
{
locale
:
string
}
>
})
{
return
(
<
html
>
<
body
>
{
/* STATIC CONTENT - This does NOT depend on params and can be pre-rendered */
}
<
div
id=
"static-header"
>
Welcome to our Blog Platform
</
div
>
<
nav
id=
"static-nav"
>
<
ul
>
<
li
>
Home
</
li
>
<
li
>
Blog
</
li
>
<
li
>
About
</
li
>
</
ul
>
</
nav
>
{
/* DYNAMIC CONTENT - This depends on locale and is wrapped in Suspense */
}
<
Suspense
fallback=
{
<
div
id=
"locale-loading"
>
Loading locale info...
</
div
>
}
>
<
LocaleInfo
params=
{
params
}
/>
</
Suspense
>
<
Suspense
fallback=
{
<
div
id=
"dynamic-loading"
>
Loading user...
</
div
>
}
>
<
UserInfo
/>
</
Suspense
>
{
children
}
</
body
>
</
html
>
)
}
// This component depends on locale, so it's in Suspense
async
function
LocaleInfo
({
params
}:
{
params
:
Promise
<
{
locale
:
string
}
>
})
{
const
{
locale
}
=
await
params
const
config
=
await
getLocaleConfig
(
locale
)
return
(
<
header
id=
"locale-header"
>
<
span
>
Locale:
{
config
.
locale
}
</
span
>
<
div
id=
"translations"
>
{
config
.
translations
.
home
}
|
{
config
.
translations
.
blog
}
|
{
' '
}
{
config
.
translations
.
about
}
</
div
>
</
header
>
)
}
async
function
UserInfo
()
{
// This is truly dynamic (uses cookies), so it's always in Suspense
const
cookieStore
=
await
cookies
()
const
user
=
cookieStore
.
get
(
'user'
)?.
value
||
'anonymous'
return
<
div
id=
"user-info"
>
Logged in as:
{
user
}
</
div
>
}
// Partial generateStaticParams - only 'en' and 'fr' are pregenerated
// 'de', 'es', etc. are NOT pregenerated
export
function
generateStaticParams
()
{
return
[{
locale
:
'en'
},
{
locale
:
'fr'
}]
}
test/e2e/app-dir/ppr-root-param-fallback/app/[locale]/page.tsx
0 → 100644
View file @
1d3554af
import
{
Suspense
}
from
'react'
export
default
function
LocaleHome
({
params
,
}:
{
params
:
Promise
<
{
locale
:
string
}
>
})
{
return
(
<
main
>
<
Suspense
fallback=
{
<
div
id=
"home-loading"
>
Loading...
</
div
>
}
>
<
HomeContent
params=
{
params
}
/>
</
Suspense
>
</
main
>
)
}
async
function
HomeContent
({
params
,
}:
{
params
:
Promise
<
{
locale
:
string
}
>
})
{
return
(
<
div
id=
"home-content"
>
<
h1
>
Home
</
h1
>
<
p
>
Welcome.
</
p
>
</
div
>
)
}
test/e2e/app-dir/ppr-root-param-fallback/next.config.js
0 → 100644
View file @
1d3554af
/**
* @type {import('next').NextConfig}
*/
const
nextConfig
=
{
cacheComponents
:
true
,
}
module
.
exports
=
nextConfig
test/e2e/app-dir/ppr-root-param-fallback/ppr-root-param-fallback.test.ts
0 → 100644
View file @
1d3554af
import
{
nextTestSetup
}
from
'e2e-utils'
describe
(
'ppr-root-param-fallback'
,
()
=>
{
const
{
next
}
=
nextTestSetup
({
files
:
__dirname
,
})
it
(
'should have use-cache content in fallback shells for all pregenerated locales'
,
async
()
=>
{
// Setup: The app has a [locale] param with generateStaticParams returning
// ['en', 'fr'], and a nested /[locale]/blog/[slug] route. The layout uses
// a 'use cache' function to fetch locale-specific translations.
//
// This test ensures that we generate fallback shells with the correct locale
// filled in for all pregenerated locales.
for
(
const
locale
of
[
'en'
,
'fr'
])
{
// next.render$ doesn't stream, so we get just the shell content
const
$
=
await
next
.
render$
(
`/
${
locale
}
/blog/new-post`
)
// The shell should have the locale-header with cached content,
// NOT the locale-loading Suspense fallback
expect
(
$
(
'#locale-header'
).
length
).
toBe
(
1
)
expect
(
$
(
'#locale-header'
).
text
()).
toContain
(
`Locale:
${
locale
}
`
)
expect
(
$
(
'#translations'
).
text
()).
toContain
(
`Home (
${
locale
}
)`
)
// The Suspense fallback should NOT be in the shell
expect
(
$
(
'#locale-loading'
).
length
).
toBe
(
0
)
}
})
})
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