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
6ae4ff03
Unverified
Commit
6ae4ff03
authored
Sep 08, 2026
by
Hendrik Liebau
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reuse prerendered variant shells for partially resolved routes
parent
21336477
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
271 additions
and
4 deletions
+271
-4
app-page-runtime.ts
packages/next/src/build/templates/app-page-runtime.ts
+5
-4
page.tsx
...pp-dir/variants-partial-shells/app/[lang]/[slug]/page.tsx
+49
-0
layout.tsx
...e2e/app-dir/variants-partial-shells/app/[lang]/layout.tsx
+23
-0
page.tsx
test/e2e/app-dir/variants-partial-shells/app/[lang]/page.tsx
+7
-0
link-accordion.tsx
...2e/app-dir/variants-partial-shells/app/link-accordion.tsx
+20
-0
next.config.js
test/e2e/app-dir/variants-partial-shells/next.config.js
+16
-0
proxy.ts
test/e2e/app-dir/variants-partial-shells/proxy.ts
+8
-0
variants-partial-shells-base-path.test.ts
...-partial-shells/variants-partial-shells-base-path.test.ts
+3
-0
variants-partial-shells.test.ts
...r/variants-partial-shells/variants-partial-shells.test.ts
+132
-0
variants.ts
test/e2e/app-dir/variants-partial-shells/variants.ts
+8
-0
No files found.
packages/next/src/build/templates/app-page-runtime.ts
View file @
6ae4ff03
...
@@ -317,13 +317,14 @@ export function createAppPageEntrypoint({
...
@@ -317,13 +317,14 @@ export function createAppPageEntrypoint({
const
outputPathname
=
toOutputPathname
(
resolvedPathname
)
const
outputPathname
=
toOutputPathname
(
resolvedPathname
)
// Select the matched shell's combination-specific entry. The canonical page
// can name a broader fallback.
const
matchedVariantsPrerenderInfo
=
matchedVariants
const
matchedVariantsPrerenderInfo
=
matchedVariants
?
prerenderManifest
.
dynamicRoutes
[
toOutputPathname
(
normalizedSrcPage
)]
?
prerenderManifest
.
dynamicRoutes
[
toOutputPathname
(
prerenderMatch
?.
source
??
normalizedSrcPage
)
]
:
undefined
:
undefined
// This reads the entry directly by key. Route matching here runs on the
// pathname with the prefix already removed, while this entry's key and
// `routeRegex` describe the prefixed path, so matching would not find it.
const
prerenderInfo
=
const
prerenderInfo
=
matchedVariantsPrerenderInfo
??
prerenderMatch
?.
route
??
null
matchedVariantsPrerenderInfo
??
prerenderMatch
?.
route
??
null
...
...
test/e2e/app-dir/variants-partial-shells/app/[lang]/[slug]/page.tsx
0 → 100644
View file @
6ae4ff03
import
{
Suspense
,
type
JSX
}
from
'react'
import
{
lang
}
from
'next/root-params'
import
{
connection
}
from
'next/server'
import
{
PHASE_PRODUCTION_BUILD
}
from
'next/constants'
import
{
theme
}
from
'../../../variants'
export
function
unstable_generateStaticVariants
():
[
typeof
theme
,
string
][][]
{
return
[[[
theme
,
'dark'
]],
[[
theme
,
'light'
]]]
}
async
function
VariantShell
():
Promise
<
JSX
.
Element
>
{
const
language
=
await
lang
()
const
currentTheme
=
await
theme
()
const
phase
=
process
.
env
.
NEXT_PHASE
===
PHASE_PRODUCTION_BUILD
?
'buildtime'
:
'runtime'
return
(
<
p
id=
"variant-shell"
data
-
language=
{
language
}
data
-
theme=
{
currentTheme
}
>
{
`shell:${language}:${currentTheme}:${phase}`
}
</
p
>
)
}
async
function
Slug
({
params
,
}:
{
params
:
Promise
<
{
lang
:
string
;
slug
:
string
}
>
}):
Promise
<
JSX
.
Element
>
{
await
connection
()
const
{
slug
}
=
await
params
return
<
p
id=
"slug"
>
{
slug
}
</
p
>
}
export
default
function
Page
({
params
,
}:
{
params
:
Promise
<
{
lang
:
string
;
slug
:
string
}
>
}):
JSX
.
Element
{
return
(
<>
<
Suspense
fallback=
{
<
p
id=
"variant-fallback"
>
pending variant
</
p
>
}
>
<
VariantShell
/>
</
Suspense
>
<
Suspense
fallback=
{
<
p
id=
"slug-fallback"
>
pending slug
</
p
>
}
>
<
Slug
params=
{
params
}
/>
</
Suspense
>
</>
)
}
test/e2e/app-dir/variants-partial-shells/app/[lang]/layout.tsx
0 → 100644
View file @
6ae4ff03
import
type
{
JSX
,
ReactNode
}
from
'react'
import
{
lang
}
from
'next/root-params'
export
function
generateStaticParams
():
Array
<
{
lang
:
string
}
>
{
return
[{
lang
:
'en'
},
{
lang
:
'de'
}]
}
export
default
async
function
RootLayout
({
children
,
}:
{
children
:
ReactNode
}):
Promise
<
JSX
.
Element
>
{
const
language
=
await
lang
()
return
(
<
html
lang=
{
language
}
>
<
body
>
<
p
id=
"layout-language"
>
{
language
}
</
p
>
{
children
}
</
body
>
</
html
>
)
}
test/e2e/app-dir/variants-partial-shells/app/[lang]/page.tsx
0 → 100644
View file @
6ae4ff03
import
type
{
JSX
}
from
'react'
import
{
lang
}
from
'next/root-params'
import
{
LinkAccordion
}
from
'../link-accordion'
export
default
async
function
Page
():
Promise
<
JSX
.
Element
>
{
return
<
LinkAccordion
href=
{
`/${await lang()}/prefetched`
}
/>
}
test/e2e/app-dir/variants-partial-shells/app/link-accordion.tsx
0 → 100644
View file @
6ae4ff03
'use client'
import
Link
from
'next/link'
import
{
useState
,
type
JSX
}
from
'react'
export
function
LinkAccordion
({
href
}:
{
href
:
string
}):
JSX
.
Element
{
const
[
isVisible
,
setIsVisible
]
=
useState
(
false
)
return
(
<>
<
input
type=
"checkbox"
checked=
{
isVisible
}
onChange=
{
()
=>
setIsVisible
(
!
isVisible
)
}
data
-
link
-
accordion=
{
href
}
/>
{
isVisible
?
<
Link
href=
{
href
}
>
Partial shell
</
Link
>
:
null
}
</>
)
}
test/e2e/app-dir/variants-partial-shells/next.config.js
0 → 100644
View file @
6ae4ff03
/**
* @type {import('next').NextConfig}
*/
const
nextConfig
=
{
cacheComponents
:
true
,
partialPrefetching
:
true
,
experimental
:
{
variants
:
true
,
},
}
if
(
process
.
env
.
BASE_PATH
)
{
nextConfig
.
basePath
=
process
.
env
.
BASE_PATH
}
module
.
exports
=
nextConfig
test/e2e/app-dir/variants-partial-shells/proxy.ts
0 → 100644
View file @
6ae4ff03
import
{
wrapProxy
}
from
'next/dist/server/variants/wrap-proxy'
import
{
theme
}
from
'./variants'
export
const
proxy
=
wrapProxy
({
'/[lang]/[slug]'
:
[
theme
]
})
export
const
config
=
{
matcher
:
[
'/((?!_next/|favicon
\\
.ico$).*)'
],
}
test/e2e/app-dir/variants-partial-shells/variants-partial-shells-base-path.test.ts
0 → 100644
View file @
6ae4ff03
process
.
env
.
BASE_PATH
=
'/base'
require
(
'./variants-partial-shells.test'
)
test/e2e/app-dir/variants-partial-shells/variants-partial-shells.test.ts
0 → 100644
View file @
6ae4ff03
import
{
nextTestSetup
}
from
'e2e-utils'
import
{
splitResponseWithPPRSentinel
}
from
'e2e-utils/ppr'
import
{
load
}
from
'cheerio'
import
type
*
as
Playwright
from
'playwright'
import
{
createRouterAct
}
from
'router-act'
import
{
basePath
,
url
}
from
'../variants/base-path'
// The assertions distinguish build-time preludes from request-time rendering.
// TODO(variants): Add deployment coverage for partially resolved shells.
// @force-gate start && turbopack
describe
(
'Variants on partially resolved shells'
,
()
=>
{
const
{
next
,
skipped
}
=
nextTestSetup
({
files
:
__dirname
,
env
:
{
BASE_PATH
:
basePath
,
},
})
if
(
skipped
)
{
return
}
async
function
fetchShell
(
pathname
:
string
,
theme
:
string
)
{
const
[
staticPart
,
dynamicPart
]
=
await
splitResponseWithPPRSentinel
(
async
()
=>
{
const
response
=
await
next
.
fetch
(
url
(
pathname
),
{
headers
:
{
cookie
:
`theme=
${
theme
}
`
},
})
expect
(
response
.
status
).
toBe
(
200
)
if
(
!
response
.
body
)
{
throw
new
Error
(
'Expected a streamed response body.'
)
}
return
response
.
body
}
)
expect
(
dynamicPart
).
not
.
toBe
(
''
)
return
{
static
$
:
load
(
staticPart
),
dynamic
$
:
load
(
dynamicPart
)
}
}
it
(
'should serve the build-time shell for each resolved root and combination'
,
async
()
=>
{
for
(
const
language
of
[
'de'
,
'en'
])
{
for
(
const
theme
of
[
'dark'
,
'light'
])
{
for
(
const
slug
of
[
'first'
,
'second'
])
{
const
{
static
$
,
dynamic$
}
=
await
fetchShell
(
`/
${
language
}
/
${
slug
}
`
,
theme
)
expect
(
static
$
(
'html'
).
attr
(
'lang'
)).
toBe
(
language
)
expect
(
static
$
(
'#layout-language'
).
text
()).
toBe
(
language
)
expect
(
static
$
(
'#variant-shell'
).
text
()).
toBe
(
`shell:
${
language
}
:
${
theme
}
:buildtime`
)
expect
(
static
$
(
'#variant-fallback'
).
length
).
toBe
(
0
)
expect
(
static
$
(
'#slug-fallback'
).
text
()).
toBe
(
'pending slug'
)
expect
(
static
$
(
'#slug'
).
length
).
toBe
(
0
)
expect
(
dynamic$
(
'#slug'
).
text
()).
toBe
(
slug
)
}
}
}
})
it
(
'should leave an undeclared combination in the dynamic response'
,
async
()
=>
{
const
{
static
$
,
dynamic$
}
=
await
fetchShell
(
'/en/undeclared'
,
'blue'
)
expect
(
static
$
(
'#layout-language'
).
text
()).
toBe
(
'en'
)
expect
(
static
$
(
'#variant-shell'
).
length
).
toBe
(
0
)
expect
(
static
$
(
'#variant-fallback'
).
text
()).
toBe
(
'pending variant'
)
expect
(
dynamic$
(
'#variant-shell'
).
text
()).
toBe
(
'shell:en:blue:runtime'
)
expect
(
dynamic$
(
'#slug'
).
text
()).
toBe
(
'undeclared'
)
})
it
(
'should prefetch the build-time variant shell before resolving the slug'
,
async
()
=>
{
for
(
const
language
of
[
'de'
,
'en'
])
{
for
(
const
theme
of
[
'dark'
,
'light'
])
{
const
pathname
=
`/
${
language
}
/prefetched`
let
page
:
Playwright
.
Page
|
undefined
const
browser
=
await
next
.
browser
(
url
(
`/
${
language
}
`
),
{
async
beforePageLoad
(
capturedPage
:
Playwright
.
Page
)
{
page
=
capturedPage
await
capturedPage
.
context
()
.
addCookies
([{
name
:
'theme'
,
value
:
theme
,
url
:
next
.
url
}])
},
})
await
using
_
=
defer
(
async
()
=>
{
await
browser
.
deleteCookies
()
await
browser
.
close
()
})
if
(
!
page
)
{
throw
new
Error
(
'The page was not captured before it loaded.'
)
}
const
act
=
createRouterAct
(
page
,
{
includeAppShellRequests
:
true
})
await
act
(
async
()
=>
{
await
browser
.
elementByCss
(
`input[data-link-accordion="
${
pathname
}
"]`
)
.
click
()
},
[
{
includes
:
`shell:
${
language
}
:
${
theme
}
:buildtime`
,
kind
:
'static'
},
{
includes
:
`shell:
${
language
}
:
${
theme
}
:runtime`
,
block
:
'reject'
},
{
includes
:
'"id":"slug","children":"prefetched"'
,
block
:
'reject'
},
])
await
act
(
async
()
=>
{
await
browser
.
elementByCss
(
`a[href="
${
url
(
pathname
)}
"]`
).
click
()
},
{
includes
:
'"id":"slug","children":"prefetched"'
}
)
expect
(
await
browser
.
elementByCss
(
'#slug'
).
text
()).
toBe
(
'prefetched'
)
expect
(
await
browser
.
elementByCss
(
'#variant-shell'
)
.
getAttribute
(
'data-language'
)
).
toBe
(
language
)
expect
(
await
browser
.
elementByCss
(
'#variant-shell'
)
.
getAttribute
(
'data-theme'
)
).
toBe
(
theme
)
expect
(
await
browser
.
eval
(
'location.pathname'
)).
toBe
(
url
(
pathname
))
}
}
})
})
function
defer
(
callback
:
()
=>
Promise
<
void
>
)
{
return
{
[
Symbol
.
asyncDispose
]:
callback
}
}
test/e2e/app-dir/variants-partial-shells/variants.ts
0 → 100644
View file @
6ae4ff03
'use variants'
import
{
unstable_variant
}
from
'next/variants'
export
const
theme
=
unstable_variant
(
(
request
)
=>
request
.
cookies
.
get
(
'theme'
)?.
value
??
'light'
,
'theme@variants.ts'
)
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