@@ -20,7 +20,7 @@ All flags need: `config-shared.ts` (type) → `config-schema.ts` (zod). If the f
...
@@ -20,7 +20,7 @@ All flags need: `config-shared.ts` (type) → `config-schema.ts` (zod). If the f
## Where the Flag Is Consumed
## Where the Flag Is Consumed
**Client/bundled code only** (e.g. `__NEXT_CACHE_COMPONENTS` in client components): `define-env.ts` is sufficient. Webpack/Turbopack replaces `process.env.X` at the user's build time.
**Client/bundled code only** (e.g. `__NEXT_PPR` in client components): `define-env.ts` is sufficient. Webpack/Turbopack replaces `process.env.X` at the user's build time.
**Pre-compiled runtime bundles** (e.g. code in `app-render.tsx`): The flag must also be set as a real `process.env` var at runtime, because `app-render.tsx` runs from pre-compiled bundles where `define-env.ts` doesn't reach. Two approaches:
**Pre-compiled runtime bundles** (e.g. code in `app-render.tsx`): The flag must also be set as a real `process.env` var at runtime, because `app-render.tsx` runs from pre-compiled bundles where `define-env.ts` doesn't reach. Two approaches:
controller.abort(newBailoutToCSRError('Render in Browser'))
controller.abort(newBailoutToCSRError('Render in Browser'))
...
@@ -505,6 +600,7 @@ export function createHangingInputAbortSignal(
...
@@ -505,6 +600,7 @@ export function createHangingInputAbortSignal(
returncontroller.signal
returncontroller.signal
case'prerender-client':
case'prerender-client':
case'validation-client':
case'validation-client':
case'prerender-ppr':
case'prerender-legacy':
case'prerender-legacy':
case'request':
case'request':
case'cache':
case'cache':
...
@@ -559,6 +655,17 @@ export function useDynamicRouteParams(expression: string) {
...
@@ -559,6 +655,17 @@ export function useDynamicRouteParams(expression: string) {
thrownewInvariantError(
thrownewInvariantError(
`\`${expression}\` was called from a Server Component. Next.js should be preventing ${expression} from being included in server components statically, but did not in this case.`
`\`${expression}\` was called from a Server Component. Next.js should be preventing ${expression} from being included in server components statically, but did not in this case.`
@@ -575,7 +575,7 @@ function assignDefaultsAndValidate(
...
@@ -575,7 +575,7 @@ function assignDefaultsAndValidate(
}
}
}
}
if((result.experimentalasany).ppr){
if(result.experimental.ppr){
thrownewHardDeprecatedConfigError(
thrownewHardDeprecatedConfigError(
`\`experimental.ppr\` has been merged into \`cacheComponents\`. The Partial Prerendering feature is still available, but is now enabled via \`cacheComponents\`. Please update your ${configFileName} accordingly.`
`\`experimental.ppr\` has been merged into \`cacheComponents\`. The Partial Prerendering feature is still available, but is now enabled via \`cacheComponents\`. Please update your ${configFileName} accordingly.`
)
)
...
@@ -1570,6 +1570,11 @@ function assignDefaultsAndValidate(
...
@@ -1570,6 +1570,11 @@ function assignDefaultsAndValidate(
result.experimental.mcpServer=true
result.experimental.mcpServer=true
}
}
if(result.cacheComponents){
// TODO: remove once we've finished migrating internally to cacheComponents.
result.experimental.ppr=true
}
// "use cache" was originally implicitly enabled with the cacheComponents flag, so
// "use cache" was originally implicitly enabled with the cacheComponents flag, so
// we transfer the value for cacheComponents to the explicit useCache flag to ensure
// we transfer the value for cacheComponents to the explicit useCache flag to ensure
@@ -95,6 +96,14 @@ export function connection(): Promise<void> {
...
@@ -95,6 +96,14 @@ export function connection(): Promise<void> {
`${exportName} must not be used within a Client Component. Next.js should be preventing ${exportName} from being included in Client Components statically, but did not in this case.`
`${exportName} must not be used within a Client Component. Next.js should be preventing ${exportName} from being included in Client Components statically, but did not in this case.`
)
)
}
}
case'prerender-ppr':
// We use React's postpone API to interrupt rendering here to create a
// dynamic hole
returnpostponeWithTracking(
workStore.route,
'connection',
workUnitStore.dynamicTracking
)
case'prerender-legacy':
case'prerender-legacy':
// We throw an error here to interrupt prerendering to mark the route
// We throw an error here to interrupt prerendering to mark the route
@@ -82,6 +83,14 @@ export function cookies(): Promise<ReadonlyRequestCookies> {
...
@@ -82,6 +83,14 @@ export function cookies(): Promise<ReadonlyRequestCookies> {
thrownewInvariantError(
thrownewInvariantError(
`${exportName} must not be used within a Client Component. Next.js should be preventing ${exportName} from being included in Client Components statically, but did not in this case.`
`${exportName} must not be used within a Client Component. Next.js should be preventing ${exportName} from being included in Client Components statically, but did not in this case.`
)
)
case'prerender-ppr':
// We need track dynamic access here eagerly to keep continuity with
// how cookies has worked in PPR without cacheComponents.
returnpostponeWithTracking(
workStore.route,
callingExpression,
workUnitStore.dynamicTracking
)
case'prerender-legacy':
case'prerender-legacy':
// We track dynamic access here so we don't need to wrap the cookies
// We track dynamic access here so we don't need to wrap the cookies
@@ -68,6 +69,7 @@ export function draftMode(): Promise<DraftMode> {
...
@@ -68,6 +69,7 @@ export function draftMode(): Promise<DraftMode> {
// Otherwise, we fall through to providing an empty draft mode.
// Otherwise, we fall through to providing an empty draft mode.
// eslint-disable-next-line no-fallthrough
// eslint-disable-next-line no-fallthrough
case'prerender':
case'prerender':
case'prerender-ppr':
case'prerender-legacy':
case'prerender-legacy':
// Return empty draft mode
// Return empty draft mode
returncreateOrGetCachedDraftMode(null,workStore)
returncreateOrGetCachedDraftMode(null,workStore)
...
@@ -241,6 +243,12 @@ function trackDynamicDraftMode(expression: string, constructorOpt: Function) {
...
@@ -241,6 +243,12 @@ function trackDynamicDraftMode(expression: string, constructorOpt: Function) {
thrownewInvariantError(
thrownewInvariantError(
`${exportName} must not be used within a Client Component. Next.js should be preventing ${exportName} from being included in Client Components statically, but did not in this case.`
`${exportName} must not be used within a Client Component. Next.js should be preventing ${exportName} from being included in Client Components statically, but did not in this case.`
@@ -81,6 +82,7 @@ export function headers(): Promise<ReadonlyHeaders> {
...
@@ -81,6 +82,7 @@ export function headers(): Promise<ReadonlyHeaders> {
case'validation-client':
case'validation-client':
case'private-cache':
case'private-cache':
case'prerender-runtime':
case'prerender-runtime':
case'prerender-ppr':
case'prerender-legacy':
case'prerender-legacy':
case'request':
case'request':
break
break
...
@@ -105,6 +107,16 @@ export function headers(): Promise<ReadonlyHeaders> {
...
@@ -105,6 +107,16 @@ export function headers(): Promise<ReadonlyHeaders> {
thrownewInvariantError(
thrownewInvariantError(
`${exportName} must not be used within a client component. Next.js should be preventing ${exportName} from being included in client components statically, but did not in this case.`
`${exportName} must not be used within a client component. Next.js should be preventing ${exportName} from being included in client components statically, but did not in this case.`
)
)
case'prerender-ppr':
// PPR Prerender (no cacheComponents)
// We are prerendering with PPR. We need track dynamic access here eagerly
// to keep continuity with how headers has worked in PPR without cacheComponents.
// TODO consider switching the semantic to throw on property access instead
returnpostponeWithTracking(
workStore.route,
callingExpression,
workUnitStore.dynamicTracking
)
case'prerender-legacy':
case'prerender-legacy':
// Legacy Prerender
// Legacy Prerender
// We are in a legacy static generation mode while prerendering
// We are in a legacy static generation mode while prerendering
`${expression} must not be used within a client component. Next.js should be preventing ${expression} from being included in client components statically, but did not in this case.`
`${expression} must not be used within a client component. Next.js should be preventing ${expression} from being included in client components statically, but did not in this case.`
@@ -16,7 +16,7 @@ export function markCurrentScopeAsDynamic(store, expression) {
...
@@ -16,7 +16,7 @@ export function markCurrentScopeAsDynamic(store, expression) {
}elseif(store.dynamicShouldError){
}elseif(store.dynamicShouldError){
thrownewStaticGenBailoutError(`Route ${pathname} with \`dynamic = "error"\` couldn't be rendered statically because it used \`${expression}\`. See more info here: https://nextjs.org/docs/app/building-your-application/rendering/static-and-dynamic#dynamic-rendering`);
thrownewStaticGenBailoutError(`Route ${pathname} with \`dynamic = "error"\` couldn't be rendered statically because it used \`${expression}\`. See more info here: https://nextjs.org/docs/app/building-your-application/rendering/static-and-dynamic#dynamic-rendering`);
@@ -34,7 +34,7 @@ export function trackDynamicDataAccessed(store, expression) {
...
@@ -34,7 +34,7 @@ export function trackDynamicDataAccessed(store, expression) {
}elseif(store.dynamicShouldError){
}elseif(store.dynamicShouldError){
thrownewStaticGenBailoutError(`Route ${pathname} with \`dynamic = "error"\` couldn't be rendered statically because it used \`${expression}\`. See more info here: https://nextjs.org/docs/app/building-your-application/rendering/static-and-dynamic#dynamic-rendering`);
thrownewStaticGenBailoutError(`Route ${pathname} with \`dynamic = "error"\` couldn't be rendered statically because it used \`${expression}\`. See more info here: https://nextjs.org/docs/app/building-your-application/rendering/static-and-dynamic#dynamic-rendering`);
constreason=`Route ${pathname} needs to bail out of prerendering at this point because it used ${expression}. `+`React throws this special object to indicate where. It should not be caught by `+`your own try/catch. Learn more: https://nextjs.org/docs/messages/ppr-caught-error`;
constreason=`Route ${pathname} needs to bail out of prerendering at this point because it used ${expression}. `+`React throws this special object to indicate where. It should not be caught by `+`your own try/catch. Learn more: https://nextjs.org/docs/messages/ppr-caught-error`;