Avoid legacy prerenders with runtime variant values

parent 89a9ad12
...@@ -613,14 +613,12 @@ export function createAppPageEntrypoint({ ...@@ -613,14 +613,12 @@ export function createAppPageEntrypoint({
const supportsRDCForNavigations = const supportsRDCForNavigations =
isRoutePPREnabled && nextConfig.cacheComponents === true isRoutePPREnabled && nextConfig.cacheComponents === true
// A static variant combination no page declared is served from the // A non-PPR prerender cannot leave runtime-tier variant values as holes. A
// prerender that omits the variants, and a route that is not partially // request that carries any must use a request render, even when it matched
// prerendered has none: omitting a variant leaves a hole only a resume can // a static combination. Otherwise a legacy prerender finds no static value
// fill. Such a request is rendered dynamically instead. Without this it // for the variant and interrupts the render.
// would take the static path, where a variant read finds no value and
// interrupts the render.
const requiresDynamicResponseForVariants = Boolean( const requiresDynamicResponseForVariants = Boolean(
!isRoutePPREnabled && variantCombinationGroups?.length && !matchedVariants !isRoutePPREnabled && runtimeVariants !== undefined
) )
// In development, we always want to generate dynamic HTML. // In development, we always want to generate dynamic HTML.
......
import { Suspense } from 'react'
import { banner, theme } from '../../../variants'
export function generateStaticParams() {
return [{ slug: 'built' }]
}
export function unstable_generateStaticVariants() {
return [[[theme, 'dark']], [[theme, 'light']]]
}
async function Banner() {
return <p id="banner">{await banner()}</p>
}
export default async function Page({
params,
}: {
params: Promise<{ slug: string }>
}) {
const { slug } = await params
return (
<>
<p id="slug">{slug}</p>
<Suspense fallback={<p id="theme">pending</p>}>
<p id="theme">{theme()}</p>
</Suspense>
{slug === 'runtime' ? (
<Suspense fallback={<p id="banner">pending</p>}>
<Banner />
</Suspense>
) : null}
</>
)
}
...@@ -12,6 +12,7 @@ import { banner, locale, theme } from './variants' ...@@ -12,6 +12,7 @@ import { banner, locale, theme } from './variants'
// route renders. // route renders.
const variantsByRoute = { const variantsByRoute = {
'/': [banner, locale, theme], '/': [banner, locale, theme],
'/conditional-runtime/[slug]': [banner, theme],
'/enumerated/[slug]': [locale, theme], '/enumerated/[slug]': [locale, theme],
'/on-demand/[slug]': [banner, theme], '/on-demand/[slug]': [banner, theme],
'/paramless': [locale, theme], '/paramless': [locale, theme],
...@@ -54,6 +55,7 @@ export const config = { ...@@ -54,6 +55,7 @@ export const config = {
'/', '/',
'/rewrite-source', '/rewrite-source',
'/external', '/external',
'/conditional-runtime/:slug',
'/enumerated/:slug', '/enumerated/:slug',
'/shell/:slug', '/shell/:slug',
'/on-demand/:slug', '/on-demand/:slug',
......
...@@ -480,6 +480,34 @@ describe('variants', () => { ...@@ -480,6 +480,34 @@ describe('variants', () => {
expect(light('#theme').text()).toBe('light') expect(light('#theme').text()).toBe('light')
}) })
it('should render an unknown param dynamically when it reads a runtime variant', async () => {
if (isNextStart) {
const response = await next.fetch(url('/conditional-runtime/built'), {
headers: { cookie: 'theme=dark' },
})
expect(response.headers.get('x-nextjs-cache')).toBe('HIT')
}
for (const banner of ['first', 'second']) {
const browser = await next.browser(url('/conditional-runtime/runtime'), {
async beforePageLoad(page: Playwright.Page) {
await page.context().addCookies([
{ name: 'theme', value: 'dark', url: next.url },
{ name: 'banner', value: banner, url: next.url },
])
},
})
await retry(async () => {
expect(await browser.elementByCss('#theme').text()).toBe('dark')
expect(await browser.elementByCss('#banner').text()).toBe(banner)
})
expect(await browser.elementByCss('#slug').text()).toBe('runtime')
}
})
it('should prerender a fallback shell per variant combination', async () => { it('should prerender a fallback shell per variant combination', async () => {
// `shell/[slug]` declares no static params, so its fallback shell is the // `shell/[slug]` declares no static params, so its fallback shell is the
// only thing prerendered for it. That shell reads a variant above the // only thing prerendered for it. That shell reads a variant above the
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment