Unverified Commit e7f4e336 authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

Remove legacy PPR codepaths (#94955)

parent ae62a6f7
......@@ -20,7 +20,7 @@ All flags need: `config-shared.ts` (type) → `config-schema.ts` (zod). If the f
## Where the Flag Is Consumed
**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.
**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.
**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:
......
......@@ -1372,5 +1372,7 @@
"1371": "Route %s used \\`io()\\` inside \\`after()\\`. The \\`io()\\` function is not allowed in this scope. See more info here: https://nextjs.org/docs/app/api-reference/functions/after",
"1372": "Route %s used \\`io()\\` inside \\`after()\\` while rendering. The \\`io()\\` function is not allowed in this scope. See more info here: https://nextjs.org/docs/app/api-reference/functions/after",
"1373": "Route %s used \\`cookies()\\` inside \\`after()\\` while rendering. This is not supported. If you need this data inside an \\`after()\\` callback, use \\`cookies()\\` outside of the callback. See more info here: https://nextjs.org/docs/app/api-reference/functions/after",
"1374": "Expected a work store while caching an `ImageResponse` during prerendering."
"1374": "Expected a work store while caching an `ImageResponse` during prerendering.",
"1375": "Route segment config \"dynamic\" is not compatible with \\`nextConfig.cacheComponents\\`. Please remove it.",
"1376": "Invariant: Cache Components cannot be enabled in export mode"
}
......@@ -2109,7 +2109,6 @@ export async function handleBuildComplete({
onMatchHeaders: [],
rewrites,
restrictedRedirectPaths: [],
isAppPPREnabled: config.cacheComponents,
}).routesManifest.rsc,
},
outputs,
......
......@@ -13,7 +13,6 @@ import { discoverRoutes } from '../route-discovery'
import { findPagesDir } from '../../lib/find-pages-dir'
import loadCustomRoutes from '../../lib/load-custom-routes'
import { generateRoutesManifest } from '../generate-routes-manifest'
import { checkIsAppPPREnabled } from '../../server/lib/experimental/ppr'
import { normalizeAppPath } from '../../shared/lib/router/utils/app-paths'
import http from 'node:http'
......@@ -167,8 +166,6 @@ async function collectRoutesForAnalyze(
config.basePath ? `${config.basePath}${pathPrefix}` : pathPrefix
)
const isAppPPREnabled = checkIsAppPPREnabled(config.experimental.ppr)
// Generate routes manifest
const { routesManifest } = generateRoutesManifest({
appType,
......@@ -179,7 +176,6 @@ async function collectRoutesForAnalyze(
onMatchHeaders,
rewrites,
restrictedRedirectPaths,
isAppPPREnabled,
})
return routesManifest.dynamicRoutes
......
......@@ -7,7 +7,6 @@ import type { ProxyMatcher } from './analysis/get-page-static-info'
import type { Rewrite } from '../lib/load-custom-routes'
import path from 'node:path'
import { needsExperimentalReact } from '../lib/needs-experimental-react'
import { checkIsAppPPREnabled } from '../server/lib/experimental/ppr'
import {
getNextConfigEnv,
getNextPublicEnvironmentVariables,
......@@ -121,7 +120,6 @@ export function getDefineEnv({
const nextPublicEnv = getNextPublicEnvironmentVariables()
const nextConfigEnv = getNextConfigEnv(config)
const isPPREnabled = checkIsAppPPREnabled(config.experimental.ppr)
const isCacheComponentsEnabled = !!config.cacheComponents
const isUseCacheEnabled = !!config.experimental.useCache
......@@ -173,7 +171,6 @@ export function getDefineEnv({
'process.env.__NEXT_APP_NEW_SCROLL_HANDLER': Boolean(
config.experimental.appNewScrollHandler
),
'process.env.__NEXT_PPR': isPPREnabled,
'process.env.__NEXT_CACHE_COMPONENTS': isCacheComponentsEnabled,
'process.env.__NEXT_EXPERIMENTAL_CACHED_NAVIGATIONS': Boolean(
config.experimental.cachedNavigations
......
......@@ -34,7 +34,6 @@ export interface GenerateRoutesManifestOptions {
onMatchHeaders: CustomRoutes['headers']
rewrites: CustomRoutes['rewrites']
restrictedRedirectPaths: string[]
isAppPPREnabled: boolean
appType: 'pages' | 'app' | 'hybrid'
deploymentId?: string
}
......@@ -61,7 +60,6 @@ export function generateRoutesManifest(
onMatchHeaders,
rewrites,
restrictedRedirectPaths,
isAppPPREnabled,
appType,
deploymentId,
} = options
......@@ -94,6 +92,8 @@ export function generateRoutesManifest(
}
}
const enableCacheComponents = Boolean(config.cacheComponents)
const routesManifest: RoutesManifest = {
version: 3,
pages404: true,
......@@ -130,9 +130,9 @@ export function generateRoutesManifest(
prefetchSegmentHeader: NEXT_ROUTER_SEGMENT_PREFETCH_HEADER,
prefetchSegmentSuffix: RSC_SEGMENT_SUFFIX,
prefetchSegmentDirSuffix: RSC_SEGMENTS_DIR_SUFFIX,
clientParamParsing: config.cacheComponents ?? false,
clientParamParsing: enableCacheComponents,
clientParamParsingOrigins: config.experimental.clientParamParsingOrigins,
dynamicRSCPrerender: isAppPPREnabled && config.cacheComponents === true,
dynamicRSCPrerender: enableCacheComponents,
},
rewriteHeaders: {
pathHeader: NEXT_REWRITTEN_PATH_HEADER,
......@@ -140,7 +140,7 @@ export function generateRoutesManifest(
},
skipProxyUrlNormalize: config.skipProxyUrlNormalize,
deploymentId: deploymentId || undefined,
ppr: isAppPPREnabled
ppr: enableCacheComponents
? {
chain: {
headers: {
......
......@@ -191,10 +191,6 @@ import { traceMemoryUsage } from '../lib/memory/trace'
import { generateEncryptionKeyBase64 } from '../server/app-render/encryption-utils-server'
import type { DeepReadonly } from '../shared/lib/deep-readonly'
import uploadTrace from '../trace/upload-trace'
import {
checkIsAppPPREnabled,
checkIsRoutePPREnabled,
} from '../server/lib/experimental/ppr'
import { FallbackMode, fallbackModeToFallbackField } from '../lib/fallback'
import { RenderingMode } from './rendering-mode'
import { InvariantError } from '../shared/lib/invariant-error'
......@@ -1524,7 +1520,6 @@ export default async function build(
const isAuthInterruptsEnabled = Boolean(
config.experimental.authInterrupts
)
const isAppPPREnabled = checkIsAppPPREnabled(config.experimental.ppr)
const routesManifestPath = path.join(distDir, ROUTES_MANIFEST)
......@@ -1541,7 +1536,6 @@ export default async function build(
onMatchHeaders,
rewrites,
restrictedRedirectPaths,
isAppPPREnabled,
deploymentId: config.deploymentId,
})
)
......@@ -2111,7 +2105,6 @@ export default async function build(
locales: config.i18n?.locales,
defaultLocale: config.i18n?.defaultLocale,
nextConfigOutput: config.output,
pprConfig: config.experimental.ppr,
cacheLifeProfiles: config.cacheLife,
buildId,
deploymentId: config.deploymentId,
......@@ -2344,7 +2337,6 @@ export default async function build(
: config.experimental.isrFlushToDisk,
cacheMaxMemorySize: config.cacheMaxMemorySize,
nextConfigOutput: config.output,
pprConfig: config.experimental.ppr,
cacheLifeProfiles: config.cacheLife,
buildId,
deploymentId: config.deploymentId,
......@@ -2749,10 +2741,6 @@ export default async function build(
featureName: 'experimental/nextScriptWorkers',
invocationCount: config.experimental.nextScriptWorkers ? 1 : 0,
},
{
featureName: 'experimental/ppr',
invocationCount: config.experimental.ppr ? 1 : 0,
},
{
featureName: 'turbopackFileSystemCache',
invocationCount: config.experimental?.turbopackFileSystemCacheForBuild
......@@ -2942,10 +2930,6 @@ export default async function build(
const appConfig = appDefaultConfigs.get(originalAppPath)
const isDynamicError = appConfig?.dynamic === 'error'
const isRoutePPREnabled: boolean = appConfig
? checkIsRoutePPREnabled(config.experimental.ppr)
: false
routes.forEach((route) => {
// If the route has any dynamic root segments, we need to skip
// rendering the route. This is because we don't support
......@@ -2970,7 +2954,6 @@ export default async function build(
_fallbackRouteParams: route.fallbackRouteParams,
_isDynamicError: isDynamicError,
_isAppDir: true,
_isRoutePPREnabled: isRoutePPREnabled,
_allowEmptyStaticShell: !route.throwOnEmptyStaticShell,
}
})
......@@ -3137,8 +3120,7 @@ export default async function build(
// When this is an app page and PPR is enabled, the route supports
// partial pre-rendering.
const isRoutePPREnabled: true | undefined =
!isAppRouteHandler &&
checkIsRoutePPREnabled(config.experimental.ppr)
!isAppRouteHandler && Boolean(config.cacheComponents)
? true
: undefined
......@@ -3320,7 +3302,7 @@ export default async function build(
prerenderManifest.routes[route.pathname] = {
initialStatus: status,
initialHeaders: meta.headers,
renderingMode: isAppPPREnabled
renderingMode: isAppCacheComponentsEnabled
? isRoutePPREnabled
? RenderingMode.PARTIALLY_STATIC
: RenderingMode.STATIC
......@@ -3418,7 +3400,7 @@ export default async function build(
let dynamicRoute = routesManifest.dynamicRoutes.find(
(r) => r.page === route.pathname
)
if (!isAppRouteHandler && isAppPPREnabled) {
if (!isAppRouteHandler && isAppCacheComponentsEnabled) {
// If the dynamic route wasn't found, then we need to create
// it. This ensures that for each fallback shell there's an
// entry in the app routes manifest which enables routing for
......@@ -3553,7 +3535,7 @@ export default async function build(
experimentalPPR: isRoutePPREnabled,
remainingPrerenderableParams:
route.remainingPrerenderableParams,
renderingMode: isAppPPREnabled
renderingMode: isAppCacheComponentsEnabled
? isRoutePPREnabled
? RenderingMode.PARTIALLY_STATIC
: RenderingMode.STATIC
......
......@@ -789,7 +789,7 @@ export async function buildAppStaticPaths({
fetchCacheKeyPrefix,
nextConfigOutput,
ComponentMod,
isRoutePPREnabled = false,
isRoutePPREnabled,
buildId,
deploymentId,
rootParamKeys,
......
......@@ -29,7 +29,6 @@ import {
NodeNextRequest,
NodeNextResponse,
} from '../../server/base-http/node' with { 'turbopack-transition': 'next-server-utility' }
import { checkIsAppPPREnabled } from '../../server/lib/experimental/ppr' with { 'turbopack-transition': 'next-server-utility' }
import { isRSCRequestHeader } from '../../server/lib/is-rsc-request' with { 'turbopack-transition': 'next-server-utility' }
import {
getFallbackRouteParams,
......@@ -119,7 +118,6 @@ import * as entryBase from '../../server/app-render/entry-base' with { 'turbopac
import { RedirectStatusCode } from '../../client/components/redirect-status-code' with { 'turbopack-transition': 'next-server-utility' }
import { InvariantError } from '../../shared/lib/invariant-error' with { 'turbopack-transition': 'next-server-utility' }
import { scheduleOnNextTick } from '../../lib/scheduler' with { 'turbopack-transition': 'next-server-utility' }
import { isInterceptionRouteAppPath } from '../../shared/lib/router/utils/interception-routes' with { 'turbopack-transition': 'next-server-utility' }
import { getSegmentParam } from '../../shared/lib/router/utils/get-segment-param' with { 'turbopack-transition': 'next-server-utility' }
export * from '../../server/app-render/entry-base' with { 'turbopack-transition': 'next-server-utility' }
......@@ -272,16 +270,8 @@ export async function handler(
// We use the resolvedPathname instead of the parsedUrl.pathname because it
// is not rewritten as resolvedPathname is. This will ensure that the correct
// prerender info is used instead of using the original pathname as the
// source. If however PPR is enabled and cacheComponents is disabled, we
// treat the pathname as dynamic. Currently, there's a bug in the PPR
// implementation that incorrectly leaves %%drp placeholders in the output of
// parallel routes. This is addressed with cacheComponents.
const prerenderMatch =
nextConfig.experimental.ppr &&
!nextConfig.cacheComponents &&
isInterceptionRouteAppPath(resolvedPathname)
? null
: routeModule.match(resolvedPathname, prerenderManifest)
// source.
const prerenderMatch = routeModule.match(resolvedPathname, prerenderManifest)
const prerenderInfo = prerenderMatch?.route ?? null
const isPrerendered = !!prerenderManifest.routes[resolvedPathname]
......@@ -310,9 +300,7 @@ export async function handler(
* If the route being rendered is an app page, and the ppr feature has been
* enabled, then the given route _could_ support PPR.
*/
const couldSupportPPR: boolean = checkIsAppPPREnabled(
nextConfig.experimental.ppr
)
const couldSupportPPR = Boolean(nextConfig.cacheComponents)
// Stash postponed state for server actions when in minimal mode.
// We extract it here so the RDC is available for the re-render after the action completes.
......@@ -906,7 +894,6 @@ export async function handler(
validationLevel:
nextConfig.experimental.instantInsights.validationLevel,
experimental: {
isRoutePPREnabled,
expireTime: nextConfig.expireTime,
staleTimes: nextConfig.experimental.staleTimes,
dynamicOnHover: Boolean(nextConfig.experimental.dynamicOnHover),
......
......@@ -166,7 +166,6 @@ async function requestHandler(
cacheComponents: Boolean(nextConfig.cacheComponents),
validationLevel: nextConfig.experimental.instantInsights.validationLevel,
experimental: {
isRoutePPREnabled: false,
expireTime: nextConfig.expireTime,
staleTimes: nextConfig.experimental.staleTimes,
dynamicOnHover: Boolean(nextConfig.experimental.dynamicOnHover),
......
......@@ -2,8 +2,6 @@ import type {
NextConfigComplete,
NextConfigRuntime,
} from '../server/config-shared'
import type { ExperimentalPPRConfig } from '../server/lib/experimental/ppr'
import { checkIsRoutePPREnabled } from '../server/lib/experimental/ppr'
import type { AssetBinding } from './webpack/loaders/get-module-build-info'
import type { ServerRuntime } from '../types'
import type { BuildManifest } from '../server/get-page-files'
......@@ -705,7 +703,6 @@ export async function isPageStatic({
cacheHandler,
cacheHandlers,
cacheLifeProfiles,
pprConfig,
buildId,
deploymentId,
clientAssetToken,
......@@ -735,7 +732,6 @@ export async function isPageStatic({
[profile: string]: import('../server/use-cache/cache-life').CacheLife
}
nextConfigOutput: 'standalone' | 'export' | undefined
pprConfig: ExperimentalPPRConfig | undefined
buildId: string
deploymentId: string
clientAssetToken: string
......@@ -863,12 +859,8 @@ export async function isPageStatic({
rootParamKeys = collectRootParamKeys(routeModule)
// A page supports partial prerendering if it is an app page and either
// the whole app has PPR enabled or this page has PPR enabled when we're
// in incremental mode.
isRoutePPREnabled =
routeModule.definition.kind === RouteKind.APP_PAGE &&
checkIsRoutePPREnabled(pprConfig)
routeModule.definition.kind === RouteKind.APP_PAGE && cacheComponents
// If force dynamic was set and we don't have PPR enabled, then set the
// revalidate to 0.
......
......@@ -20,7 +20,6 @@ function hasFallbackRouteParams(): boolean {
switch (workUnitStore.type) {
case 'prerender':
case 'prerender-client':
case 'prerender-ppr':
case 'validation-client':
const fallbackParams = workUnitStore.fallbackRouteParams
return fallbackParams ? fallbackParams.size > 0 : false
......
......@@ -190,10 +190,7 @@ export async function fetchServerResponse(
// Typically, during a navigation, we decode the response using Flight's
// `createFromFetch` API, which accepts a `fetch` promise.
// TODO: Remove this check once the old PPR flag is removed
const isLegacyPPR =
process.env.__NEXT_PPR && !process.env.__NEXT_CACHE_COMPONENTS
const shouldImmediatelyDecode = !isLegacyPPR
const shouldImmediatelyDecode = true
const res = await createFetch<NavigationFlightResponse>(
url,
headers,
......
import { isHangingPromiseRejectionError } from '../../server/dynamic-rendering-utils'
import { isPostpone } from '../../server/lib/router-utils/is-postpone'
import { isBailoutToCSRError } from '../../shared/lib/lazy-dynamic/bailout-to-csr'
import { isNextRouterError } from './is-next-router-error'
import {
isDynamicPostpone,
isPrerenderInterruptedError,
} from '../../server/app-render/dynamic-rendering'
import { isPrerenderInterruptedError } from '../../server/app-render/dynamic-rendering'
import { isDynamicServerError } from './hooks-server-context'
export function unstable_rethrow(error: unknown): void {
......@@ -13,8 +9,6 @@ export function unstable_rethrow(error: unknown): void {
isNextRouterError(error) ||
isBailoutToCSRError(error) ||
isDynamicServerError(error) ||
isDynamicPostpone(error) ||
isPostpone(error) ||
isHangingPromiseRejectionError(error) ||
isPrerenderInterruptedError(error)
) {
......
import { isDynamicServerError } from '../../client/components/hooks-server-context'
import { isBailoutToCSRError } from '../../shared/lib/lazy-dynamic/bailout-to-csr'
import { isNextRouterError } from '../../client/components/is-next-router-error'
import { isDynamicPostpone } from '../../server/app-render/dynamic-rendering'
export const isDynamicUsageError = (err: unknown) =>
isDynamicServerError(err) ||
isBailoutToCSRError(err) ||
isNextRouterError(err) ||
isDynamicPostpone(err)
isNextRouterError(err)
......@@ -880,9 +880,11 @@ async function exportAppImpl(
}
// Export mode provide static outputs that are not compatible with PPR mode.
if (!options.buildExport && nextConfig.experimental.ppr) {
if (!options.buildExport && nextConfig.cacheComponents) {
// TODO: add message
throw new Error('Invariant: PPR cannot be enabled in export mode')
throw new Error(
'Invariant: Cache Components cannot be enabled in export mode'
)
}
// copy prerendered routes to outDir
......
......@@ -105,7 +105,7 @@ export async function exportAppPage(
} = metadata
// Ensure we don't postpone without having PPR enabled.
if (postponed && !renderOpts.experimental.isRoutePPREnabled) {
if (postponed && !renderOpts.cacheComponents) {
throw new Error('Invariant: page postponed without PPR being enabled')
}
......@@ -145,8 +145,7 @@ export async function exportAppPage(
const hasFallbackParams =
fallbackRouteParams != null && fallbackRouteParams.size > 0
const shouldWriteRsc =
!renderOpts.experimental.isRoutePPREnabled ||
(!postponed && !hasFallbackParams)
!renderOpts.cacheComponents || (!postponed && !hasFallbackParams)
hasStaticRsc = shouldWriteRsc
// With PPR enabled, we normally skip writing .rsc because it may contain
......@@ -198,7 +197,7 @@ export async function exportAppPage(
// When PPR is enabled, we don't always send 200 for routes that have been
// pregenerated, so we should grab the status code from the mocked
// response.
let status: number | undefined = renderOpts.experimental.isRoutePPREnabled
let status: number | undefined = renderOpts.cacheComponents
? res.statusCode
: undefined
......
......@@ -36,7 +36,6 @@ import { exportAppPage } from './routes/app-page'
import { exportPagesPage } from './routes/pages'
import { getParams } from './helpers/get-params'
import { createIncrementalCache } from './helpers/create-incremental-cache'
import { isPostpone } from '../server/lib/router-utils/is-postpone'
import { isDynamicUsageError } from './helpers/is-dynamic-usage-error'
import { isBailoutToCSRError } from '../shared/lib/lazy-dynamic/bailout-to-csr'
import {
......@@ -109,10 +108,6 @@ async function exportPageImpl(
// Check if this should error when dynamic usage is detected.
_isDynamicError: isDynamicError = false,
// If this page supports partial prerendering, then we need to pass that to
// the renderOpts.
_isRoutePPREnabled: isRoutePPREnabled,
// Configure the rendering of the page to allow that an empty static shell
// is generated while rendering using PPR and Cache Components.
_allowEmptyStaticShell: allowEmptyStaticShell = false,
......@@ -275,10 +270,6 @@ async function exportPageImpl(
serveStreamingMetadata: true,
allowEmptyStaticShell,
runInstantValidation,
experimental: {
...commonRenderOpts.experimental,
isRoutePPREnabled,
},
renderResumeDataCache,
}
......@@ -614,12 +605,6 @@ async function exportPage(
}
process.on('unhandledRejection', (err: unknown) => {
// if it's a postpone error, it'll be handled later
// when the postponed promise is actually awaited.
if (isPostpone(err)) {
return
}
// we don't want to log these errors
if (isDynamicUsageError(err)) {
return
......
......@@ -16,7 +16,6 @@ import { isHTTPAccessFallbackError } from '../../client/components/http-access-f
import type { MetadataContext } from './types/resolvers'
import { createServerSearchParamsForMetadata } from '../../server/request/search-params'
import { createServerPathnameForMetadata } from '../../server/request/pathname'
import { isPostpone } from '../../server/lib/router-utils/is-postpone'
import {
workUnitAsyncStorage,
getStagedRenderingController,
......@@ -91,12 +90,6 @@ export function createMetadataComponents({
isRuntimePrefetchable,
errorType
).catch((viewportErr) => {
// When Legacy PPR is enabled viewport can reject with a Postpone type
// This will go away once Legacy PPR is removed and dynamic metadata will
// stay pending until after the prerender is complete when it is dynamic
if (isPostpone(viewportErr)) {
throw viewportErr
}
if (!errorType && isHTTPAccessFallbackError(viewportErr)) {
return getNotFoundViewport(
tree,
......@@ -144,12 +137,6 @@ export function createMetadataComponents({
isRuntimePrefetchable,
errorType
).catch((metadataErr) => {
// When Legacy PPR is enabled metadata can reject with a Postpone type
// This will go away once Legacy PPR is removed and dynamic metadata will
// stay pending until after the prerender is complete when it is dynamic
if (isPostpone(metadataErr)) {
throw metadataErr
}
if (!errorType && isHTTPAccessFallbackError(metadataErr)) {
return getNotFoundMetadata(
tree,
......
......@@ -119,7 +119,7 @@ async function createComponentTreeInternal(
isRoot: boolean
): Promise<CacheNodeSeedData> {
const {
renderOpts: { nextConfigOutput, experimental, cacheComponents },
renderOpts: { nextConfigOutput, cacheComponents },
workStore,
componentMod: {
createElement,
......@@ -135,7 +135,6 @@ async function createComponentTreeInternal(
createServerParamsForServerSegment,
createPrerenderParamsForClientSegment,
serverHooks: { DynamicServerError },
Postpone,
},
pagePath,
getDynamicParamFromSegment,
......@@ -264,6 +263,15 @@ async function createComponentTreeInternal(
: []
let dynamic = layoutOrPageMod?.dynamic
if (typeof dynamic === 'string') {
if (cacheComponents) {
// TODO: Remove this since this should be caught during compilation.
// Left as a guard in case usage of Postpone was attempted
throw new Error(
`Route segment config "dynamic" is not compatible with \`nextConfig.cacheComponents\`. Please remove it.`
)
}
}
if (nextConfigOutput === 'export') {
if (!dynamic || dynamic === 'auto') {
......@@ -277,6 +285,14 @@ async function createComponentTreeInternal(
}
if (typeof dynamic === 'string') {
if (cacheComponents) {
// TODO: Remove this since this should be caught during compilation.
// Left as a guard in case usage of Postpone was attempted
throw new Error(
`Route segment config "dynamic" is not compatible with \`nextConfig.cacheComponents\`. Please remove it.`
)
}
// the nested most config wins so we only force-static
// if it's configured above any parent that configured
// otherwise
......@@ -285,10 +301,7 @@ async function createComponentTreeInternal(
} else if (dynamic === 'force-dynamic') {
workStore.forceDynamic = true
// TODO: (PPR) remove this bailout once PPR is the default
if (workStore.isStaticGeneration && !experimental.isRoutePPREnabled) {
// If the postpone API isn't available, we can't postpone the render and
// therefore we can't use the dynamic API.
if (workStore.isStaticGeneration) {
const err = new DynamicServerError(
`Page with \`dynamic = "force-dynamic"\` won't be rendered statically.`
)
......@@ -320,7 +333,6 @@ async function createComponentTreeInternal(
case 'prerender':
case 'prerender-runtime':
case 'prerender-legacy':
case 'prerender-ppr':
if (workUnitStore.revalidate > defaultRevalidate) {
workUnitStore.revalidate = defaultRevalidate
}
......@@ -347,7 +359,7 @@ async function createComponentTreeInternal(
defaultRevalidate === 0 &&
// If the postpone API isn't available, we can't postpone the render and
// therefore we can't use the dynamic API.
!experimental.isRoutePPREnabled
!cacheComponents
) {
const dynamicUsageDescription = `revalidate: 0 configured ${segment}`
workStore.dynamicUsageDescription = dynamicUsageDescription
......@@ -371,7 +383,6 @@ async function createComponentTreeInternal(
case 'prerender':
case 'prerender-runtime':
case 'prerender-legacy':
case 'prerender-ppr':
if (workUnitStore.stale > pageStaleTime) {
workUnitStore.stale = pageStaleTime
}
......@@ -414,7 +425,7 @@ async function createComponentTreeInternal(
// For dynamic requests, this must always be `false` because dynamic responses
// are never partial.
const isPossiblyPartialResponse =
isStaticGeneration && experimental.isRoutePPREnabled === true
isStaticGeneration && cacheComponents === true
const LayoutOrPage: ComponentType<any> | undefined = layoutOrPageMod
? interopDefault(layoutOrPageMod)
......@@ -576,7 +587,7 @@ async function createComponentTreeInternal(
// possible during both prefetches and dynamic navigations. But during
// the beta period, we should be clear about this trade off in our
// communications.
!experimental.isRoutePPREnabled
!cacheComponents
) {
// Don't prefetch this child. This will trigger a lazy fetch by the
// client router.
......@@ -771,43 +782,15 @@ async function createComponentTreeInternal(
}
const Component = MaybeComponent
// If force-dynamic is used and the current render supports postponing, we
// replace it with a node that will postpone the render. This ensures that the
// postpone is invoked during the react render phase and not during the next
// render phase.
// @TODO this does not actually do what it seems like it would or should do. The idea is that
// if we are rendering in a force-dynamic mode and we can postpone we should only make the segments
// that ask for force-dynamic to be dynamic, allowing other segments to still prerender. However
// because this comes after the children traversal and the static generation store is mutated every segment
// along the parent path of a force-dynamic segment will hit this condition effectively making the entire
// render force-dynamic. We should refactor this function so that we can correctly track which segments
// need to be dynamic
if (
workStore.isStaticGeneration &&
workStore.forceDynamic &&
experimental.isRoutePPREnabled
cacheComponents
) {
return createSeedData(
ctx,
createElement(
Fragment,
{
key: cacheNodeKey,
},
createElement(Postpone, {
reason: 'dynamic = "force-dynamic" was used',
route: workStore.route,
}),
layerAssets
),
parallelRouteCacheNodeSeedData,
loadingData,
true,
isRuntimePrefetchable,
// force-dynamic postpones without rendering the component, so no params
// are accessed. The vary params are empty.
emptyVaryParamsAccumulator
// TODO: Remove this since this should be caught during compilation.
// Left as a guard in case usage of Postpone was attempted
throw new Error(
`Route segment config "dynamic" is not compatible with \`nextConfig.cacheComponents\`. Please remove it.`
)
}
......@@ -1331,7 +1314,6 @@ function createSeedData(
case 'prerender':
case 'prerender-client':
case 'validation-client':
case 'prerender-ppr':
case 'prerender-legacy':
case 'cache':
case 'private-cache':
......
......@@ -29,7 +29,6 @@ import type {
PrerenderStoreModernServer,
} from '../app-render/work-unit-async-storage.external'
// Once postpone is in stable we should switch to importing the postpone export directly
import React from 'react'
import { DynamicServerError } from '../../client/components/hooks-server-context'
......@@ -80,8 +79,6 @@ import {
} from './instant-validation/boundary-tracking'
import type { InstantValidationSampleTracking } from './instant-validation/instant-samples'
const hasPostpone = typeof React.unstable_postpone === 'function'
export type DynamicAccess = {
/**
* If debugging, this will contain the stack trace of where the dynamic access
......@@ -183,7 +180,6 @@ export function markCurrentScopeAsDynamic(
// A private cache scope is already dynamic by definition.
return
case 'prerender-legacy':
case 'prerender-ppr':
case 'request':
case 'generate-static-params':
break
......@@ -205,12 +201,6 @@ export function markCurrentScopeAsDynamic(
if (workUnitStore) {
switch (workUnitStore.type) {
case 'prerender-ppr':
return postponeWithTracking(
store.route,
expression,
workUnitStore.dynamicTracking
)
case 'prerender-legacy':
workUnitStore.revalidate = 0
......@@ -282,7 +272,6 @@ export function trackDynamicDataInDynamicRender(workUnitStore: WorkUnitStore) {
case 'prerender':
case 'prerender-runtime':
case 'prerender-legacy':
case 'prerender-ppr':
case 'prerender-client':
case 'validation-client':
case 'generate-static-params':
......@@ -380,78 +369,6 @@ export function abortAndThrowOnSynchronousRequestDataAccess(
)
}
/**
* This component will call `React.postpone` that throws the postponed error.
*/
type PostponeProps = {
reason: string
route: string
}
export function Postpone({ reason, route }: PostponeProps): never {
const prerenderStore = workUnitAsyncStorage.getStore()
const dynamicTracking =
prerenderStore && prerenderStore.type === 'prerender-ppr'
? prerenderStore.dynamicTracking
: null
postponeWithTracking(route, reason, dynamicTracking)
}
export function postponeWithTracking(
route: string,
expression: string,
dynamicTracking: null | DynamicTrackingState
): never {
assertPostpone()
if (dynamicTracking) {
dynamicTracking.dynamicAccesses.push({
// When we aren't debugging, we don't need to create another error for the
// stack trace.
stack: dynamicTracking.isDebugDynamicAccesses
? new Error().stack
: undefined,
expression,
})
}
React.unstable_postpone(createPostponeReason(route, expression))
}
function createPostponeReason(route: string, expression: string) {
return (
`Route ${route} 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`
)
}
export function isDynamicPostpone(err: unknown) {
if (
typeof err === 'object' &&
err !== null &&
typeof (err as any).message === 'string'
) {
return isDynamicPostponeReason((err as any).message)
}
return false
}
function isDynamicPostponeReason(reason: string) {
return (
reason.includes(
'needs to bail out of prerendering at this point because it used'
) &&
reason.includes(
'Learn more: https://nextjs.org/docs/messages/ppr-caught-error'
)
)
}
if (isDynamicPostponeReason(createPostponeReason('%%%', '^^^')) === false) {
throw new Error(
'Invariant: isDynamicPostpone misidentified a postpone reason. This is a bug in Next.js'
)
}
const NEXT_PRERENDER_INTERRUPTED = 'NEXT_PRERENDER_INTERRUPTED'
function createPrerenderInterruptedError(message: string): Error {
......@@ -532,18 +449,6 @@ export function formatDynamicAPIAccesses(
})
}
function assertPostpone() {
if (!hasPostpone) {
throw new Error(
`Invariant: React.unstable_postpone is not defined. This suggests the wrong version of React was loaded. This is a bug in Next.js`
)
}
}
/**
* This is a bit of a hack to allow us to abort a render using a Postpone instance instead of an Error which changes React's
* abort semantics slightly.
*/
export function createRenderInBrowserAbortSignal(): AbortSignal {
const controller = new AbortController()
controller.abort(new BailoutToCSRError('Render in Browser'))
......@@ -601,7 +506,6 @@ export function createHangingInputAbortSignal(
return controller.signal
case 'prerender-client':
case 'validation-client':
case 'prerender-ppr':
case 'prerender-legacy':
case 'request':
case 'cache':
......@@ -656,17 +560,6 @@ export function useDynamicRouteParams(expression: string) {
throw new InvariantError(
`\`${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.`
)
case 'prerender-ppr': {
const fallbackParams = workUnitStore.fallbackRouteParams
if (fallbackParams && fallbackParams.size > 0) {
return postponeWithTracking(
workStore.route,
expression,
workUnitStore.dynamicTracking
)
}
break
}
case 'validation-client': {
// Don't check fallbackRouteParams here. We handle params that weren't
// provided in the samples using a proxy that throws when accessed.
......@@ -722,8 +615,7 @@ export function useDynamicSearchParams(expression: string) {
)
break
}
case 'prerender-legacy':
case 'prerender-ppr': {
case 'prerender-legacy': {
if (workStore.forceStatic) {
return
}
......
......@@ -293,7 +293,6 @@ export async function decryptActionBoundArgs(
break
case 'prerender-client':
case 'validation-client':
case 'prerender-ppr':
case 'prerender-legacy':
case 'request':
case 'cache':
......
......@@ -62,7 +62,6 @@ export { createMetadataComponents } from '../../lib/metadata/metadata'
export { RootLayoutBoundary } from '../../lib/framework/boundary-components'
export { preloadStyle, preloadFont, preconnect } from './rsc/preloads'
export { Postpone } from './rsc/postpone'
export { taintObjectReference } from './rsc/taint'
export {
collectSegmentData,
......
......@@ -24,7 +24,6 @@ function getValidationBoundaryTracking(): ValidationBoundaryTracking | null {
return store.boundaryState
case 'prerender':
case 'prerender-client':
case 'prerender-ppr':
case 'prerender-legacy':
case 'prerender-runtime':
case 'request':
......
......@@ -32,7 +32,6 @@ export function instrumentParamsForClientValidation<TPArams extends Params>(
case 'prerender-runtime':
case 'prerender-client':
case 'prerender-legacy':
case 'prerender-ppr':
case 'prerender':
case 'cache':
case 'request':
......@@ -72,7 +71,6 @@ export function expectCompleteParamsInClientValidation(
case 'prerender-runtime':
case 'prerender-client':
case 'prerender-legacy':
case 'prerender-ppr':
case 'prerender':
case 'cache':
case 'request':
......@@ -109,7 +107,6 @@ export function instrumentSearchParamsForClientValidation(
case 'prerender-runtime':
case 'prerender-client':
case 'prerender-legacy':
case 'prerender-ppr':
case 'prerender':
case 'cache':
case 'request':
......
......@@ -42,7 +42,6 @@ function getExpectedSampleTracking(): InstantValidationSampleTracking {
case 'private-cache':
case 'unstable-cache':
case 'prerender-legacy':
case 'prerender-ppr':
case 'prerender-client':
case 'prerender':
case 'prerender-runtime':
......
/*
Files in the rsc directory are meant to be packaged as part of the RSC graph using next-app-loader.
*/
// When postpone is available in canary React we can switch to importing it directly
export { Postpone } from '../dynamic-rendering'
......@@ -149,11 +149,6 @@ export interface RenderOptsPartial {
isPrefetch?: boolean
htmlLimitedBots: string | undefined
experimental: {
/**
* When true, it indicates that the current page supports partial
* prerendering.
*/
isRoutePPREnabled?: boolean
expireTime: number | undefined
staleTimes: ExperimentalConfig['staleTimes'] | undefined
clientTraceMetadata: string[] | undefined
......
......@@ -135,7 +135,6 @@ export function getFlightStream<T>(
return responseOnNextTick
case 'prerender':
case 'prerender-runtime':
case 'prerender-ppr':
case 'prerender-legacy':
case 'request':
case 'cache':
......
......@@ -134,7 +134,7 @@ export async function walkTreeWithFlightRouterState({
if (
isInsideSharedLayout &&
!experimental.isRoutePPREnabled &&
!cacheComponents &&
// If PPR is disabled, and this is a request for the route tree, then we
// never render any components. Only send the router state.
(parsedRequestHeaders.isRouteTreePrefetchRequest ||
......
......@@ -11,10 +11,7 @@ import type { OpaqueFallbackRouteParams } from '../request/fallback-params'
// Share the instance module in the next-shared layer
import { workUnitAsyncStorageInstance } from './work-unit-async-storage-instance' with { 'turbopack-transition': 'next-shared' }
import type { ServerComponentsHmrCache } from '../response-cache'
import type {
PrerenderResumeDataCache,
ResumeDataCache,
} from '../resume-data-cache/resume-data-cache'
import type { ResumeDataCache } from '../resume-data-cache/resume-data-cache'
import type { Params } from '../request/params'
import type { ImplicitTags } from '../lib/implicit-tags'
import type { WorkStore } from './work-async-storage.external'
......@@ -283,25 +280,6 @@ interface StaticPrerenderStoreCommon {
readonly fallbackRouteParams: OpaqueFallbackRouteParams | null
}
export interface PrerenderStorePPR
extends CommonWorkUnitStore,
RevalidateStore {
readonly type: 'prerender-ppr'
readonly rootParams: Params
readonly dynamicTracking: null | DynamicTrackingState
/**
* The set of unknown route parameters. Accessing these will be tracked as
* a dynamic access.
*/
readonly fallbackRouteParams: OpaqueFallbackRouteParams | null
/**
* The resume data cache for this prerender. Always mutable in PPR mode.
*/
resumeDataCache: PrerenderResumeDataCache
}
export interface PrerenderStoreLegacy
extends CommonWorkUnitStore,
RevalidateStore {
......@@ -309,10 +287,7 @@ export interface PrerenderStoreLegacy
readonly rootParams: Params
}
export type PrerenderStore =
| PrerenderStoreLegacy
| PrerenderStorePPR
| PrerenderStoreModern
export type PrerenderStore = PrerenderStoreLegacy | PrerenderStoreModern
// /** Like `PrerenderStoreModern`, but only including static prerenders (i.e. not runtime prerenders) */
export type StaticPrerenderStore = Exclude<
......@@ -448,7 +423,6 @@ export function getResumeDataCache(
case 'prerender-runtime':
case 'prerender-client':
case 'validation-client':
case 'prerender-ppr':
return workUnitStore.resumeDataCache
case 'cache':
case 'private-cache':
......@@ -475,7 +449,6 @@ export function getHmrRefreshHash(
return workUnitStore.cookies.get(NEXT_HMR_REFRESH_HASH_COOKIE)?.value
case 'prerender-client':
case 'validation-client':
case 'prerender-ppr':
case 'prerender-legacy':
case 'unstable-cache':
case 'generate-static-params':
......@@ -499,7 +472,6 @@ export function isHmrRefresh(workUnitStore: WorkUnitStore): boolean {
case 'prerender-client':
case 'validation-client':
case 'prerender-runtime':
case 'prerender-ppr':
case 'prerender-legacy':
case 'unstable-cache':
case 'generate-static-params':
......@@ -525,7 +497,6 @@ export function getServerComponentsHmrCache(
case 'prerender-client':
case 'validation-client':
case 'prerender-runtime':
case 'prerender-ppr':
case 'prerender-legacy':
case 'unstable-cache':
case 'generate-static-params':
......@@ -556,7 +527,6 @@ export function getDraftModeProviderForCacheScope(
case 'prerender':
case 'prerender-client':
case 'validation-client':
case 'prerender-ppr':
case 'prerender-legacy':
case 'generate-static-params':
break
......@@ -578,7 +548,6 @@ export function getStagedRenderingController(
return workUnitStore.stagedRendering ?? null
case 'prerender-client':
case 'validation-client':
case 'prerender-ppr':
case 'prerender-legacy':
case 'cache':
case 'private-cache':
......@@ -606,7 +575,6 @@ export function getCacheSignal(
}
// fallthrough
}
case 'prerender-ppr':
case 'prerender-legacy':
case 'cache':
case 'private-cache':
......@@ -627,7 +595,6 @@ export function getVaryParamsAccumulator(
case 'request': {
return workUnitStore.varyParamsAccumulator ?? null
}
case 'prerender-ppr':
case 'prerender-legacy':
case 'cache':
case 'private-cache':
......
......@@ -34,7 +34,7 @@ export type WorkStoreContext = {
pendingWaitUntil?: Promise<any>
experimental: Pick<
RenderOpts['experimental'],
'isRoutePPREnabled' | 'authInterrupts' | 'useCacheTimeout'
'authInterrupts' | 'useCacheTimeout'
>
/**
......
......@@ -133,7 +133,6 @@ import { toRoute } from './lib/to-route'
import type { DeepReadonly } from '../shared/lib/deep-readonly'
import { isNodeNextRequest, isNodeNextResponse } from './base-http/helpers'
import { patchSetHeaderWithCookieSupport } from './lib/patch-set-header'
import { checkIsAppPPREnabled } from './lib/experimental/ppr'
import {
getBuiltinRequestContext,
type WaitUntil,
......@@ -431,7 +430,7 @@ export default abstract class Server<
readonly data: NextDataPathnameNormalizer | undefined
}
private readonly isAppPPREnabled: boolean
private readonly isAppCacheComponentsEnabled: boolean
/**
* This is used to persist cache scopes across
......@@ -517,9 +516,8 @@ export default abstract class Server<
this.enabledDirectories = this.getEnabledDirectories(dev)
this.isAppPPREnabled =
this.enabledDirectories.app &&
checkIsAppPPREnabled(this.nextConfig.experimental.ppr)
this.isAppCacheComponentsEnabled =
this.enabledDirectories.app && Boolean(this.nextConfig.cacheComponents)
this.normalizers = {
// We should normalize the pathname from the RSC prefix only in minimal
......@@ -1096,7 +1094,7 @@ export default abstract class Server<
// It's important to execute the following block even it the request
// matches a pages data route from above.
if (
this.isAppPPREnabled &&
this.isAppCacheComponentsEnabled &&
this.minimalMode &&
req.headers[NEXT_RESUME_HEADER] === '1' &&
req.method === 'POST'
......@@ -2218,7 +2216,7 @@ export default abstract class Server<
* enabled, then the given route _could_ support PPR.
*/
const couldSupportPPR: boolean =
this.isAppPPREnabled &&
this.isAppCacheComponentsEnabled &&
typeof routeModule !== 'undefined' &&
isAppPageRouteModule(routeModule)
......
......@@ -41,7 +41,6 @@ const zExportMap: zod.ZodType<ExportPathMap> = z.record(
_fallbackRouteParams: z.array(z.any()).optional(),
_isAppDir: z.boolean().optional(),
_isDynamicError: z.boolean().optional(),
_isRoutePPREnabled: z.boolean().optional(),
_allowEmptyStaticShell: z.boolean().optional(),
})
)
......
......@@ -11,7 +11,6 @@ import type { WEB_VITALS } from '../shared/lib/utils'
import type { NextParsedUrlQuery } from './request-meta'
import type { SizeLimit } from '../types'
import type { SupportedTestRunners } from '../cli/next-test'
import type { ExperimentalPPRConfig } from './lib/experimental/ppr'
import { INFINITE_CACHE } from '../lib/constants'
import type { FallbackRouteParam } from '../build/static-paths/types'
import type { MemoryEvictionMode } from '../build/swc/types'
......@@ -965,12 +964,6 @@ export interface ExperimentalConfig {
*/
clientTraceMetadata?: string[]
/**
* @deprecated This configuration option has been merged into `cacheComponents`.
* The Partial Prerendering feature is still available via `cacheComponents`.
*/
ppr?: ExperimentalPPRConfig
/**
* Enables experimental taint APIs in React.
* Using this feature will enable the `react@experimental` for the `app` directory.
......@@ -1355,11 +1348,6 @@ export type ExportPathMap = {
*/
_isDynamicError?: boolean
/**
* @internal
*/
_isRoutePPREnabled?: boolean
/**
* When true, the page is prerendered as a fallback shell, while allowing
* any dynamic accesses to result in an empty shell. This is the case when
......@@ -2069,7 +2057,6 @@ export const defaultConfig = Object.freeze({
clientTraceMetadata: undefined,
parallelServerCompiles: false,
parallelServerBuildTraces: false,
ppr: false,
authInterrupts: false,
webpackBuildWorker: undefined,
webpackMemoryOptimizations: false,
......@@ -2134,7 +2121,6 @@ export async function normalizeConfig(phase: string, config: any) {
// cacheComponents?: boolean;
// clientParamParsingOrigins?: string[];
// clientSegmentCache?: boolean;
// ppr?: boolean | 'incremental';
// serverActions?: Record<string, never>;
// };
// };
......@@ -2177,7 +2163,6 @@ export interface NextConfigRuntime {
experimental: Pick<
NextConfigComplete['experimental'],
| 'ppr'
| 'taint'
| 'serverActions'
| 'staleTimes'
......@@ -2245,7 +2230,6 @@ export function getNextConfigRuntime(
}
const experimental = {
ppr: ex.ppr,
taint: ex.taint,
serverActions: ex.serverActions,
staleTimes: ex.staleTimes,
......
......@@ -575,7 +575,7 @@ function assignDefaultsAndValidate(
}
}
if (result.experimental.ppr) {
if ((result.experimental as any).ppr) {
throw new HardDeprecatedConfigError(
`\`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,11 +1570,6 @@ function assignDefaultsAndValidate(
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
// we transfer the value for cacheComponents to the explicit useCache flag to ensure
// backwards compatibility.
......
......@@ -72,7 +72,6 @@ import { DefaultFileReader } from '../route-matcher-providers/dev/helpers/file-r
import { LRUCache } from '../lib/lru-cache'
import { getMiddlewareRouteMatcher } from '../../shared/lib/router/utils/middleware-route-matcher'
import { DetachedPromise } from '../../lib/detached-promise'
import { isPostpone } from '../lib/router-utils/is-postpone'
import { generateInterceptionRoutesRewrites } from '../../lib/generate-interception-routes-rewrites'
import { buildCustomRoute } from '../../lib/build-custom-route'
import { decorateServerError } from '../../shared/lib/error-source'
......@@ -345,11 +344,6 @@ export default class DevServer extends Server {
}
process.on('unhandledRejection', (reason) => {
if (isPostpone(reason)) {
// React postpones that are unhandled might end up logged here but they're
// not really errors. They're just part of rendering.
return
}
this.logErrorWithOriginalStack(reason, 'unhandledRejection')
})
process.on('uncaughtException', (err) => {
......@@ -806,7 +800,6 @@ export default class DevServer extends Server {
distDir: this.distDir,
pathname,
config: {
pprConfig: this.nextConfig.experimental.ppr,
configFileName,
cacheComponents: Boolean(this.nextConfig.cacheComponents),
},
......
......@@ -17,10 +17,6 @@ import { loadComponents } from '../load-components'
import { setHttpClientAndAgentOptions } from '../setup-http-agent-env'
import type { IncrementalCache } from '../lib/incremental-cache'
import { isAppPageRouteModule } from '../route-modules/checks'
import {
checkIsRoutePPREnabled,
type ExperimentalPPRConfig,
} from '../lib/experimental/ppr'
import { InvariantError } from '../../shared/lib/invariant-error'
import { collectRootParamKeys } from '../../build/segment-config/app/collect-root-param-keys'
import { buildAppStaticPaths } from '../../build/static-paths/app'
......@@ -29,7 +25,6 @@ import { createIncrementalCache } from '../../export/helpers/create-incremental-
import { parseNormalizedAppRoute } from '../../shared/lib/router/routes/app'
type RuntimeConfig = {
pprConfig: ExperimentalPPRConfig | undefined
configFileName: string
cacheComponents: boolean
}
......@@ -132,8 +127,7 @@ export async function loadStaticPaths({
}
const isRoutePPREnabled =
isAppPageRouteModule(routeModule) &&
checkIsRoutePPREnabled(config.pprConfig)
isAppPageRouteModule(routeModule) && Boolean(config.cacheComponents)
const rootParamKeys = collectRootParamKeys(routeModule)
......
......@@ -273,7 +273,6 @@ export function applyOwnerStack(error: Error): Error {
case 'unstable-cache':
case 'request':
case 'prerender':
case 'prerender-ppr':
case 'prerender-legacy':
case 'prerender-runtime':
case 'prerender-client':
......
/**
* If set to `incremental`, only those leaf pages that export
* `experimental_ppr = true` will have partial prerendering enabled. If any
* page exports this value as `false` or does not export it at all will not
* have partial prerendering enabled. If set to a boolean, the options for
* `experimental_ppr` will be ignored.
*/
export type ExperimentalPPRConfig = boolean | 'incremental'
/**
* Returns true if partial prerendering is enabled for the application. It does
* not tell you if a given route has PPR enabled, as that requires analysis of
* the route's configuration.
*
* @see {@link checkIsRoutePPREnabled} - for checking if a specific route has PPR enabled.
*/
export function checkIsAppPPREnabled(
config: ExperimentalPPRConfig | undefined
): boolean {
// If the config is undefined, partial prerendering is disabled.
if (typeof config === 'undefined') return false
// If the config is a boolean, use it directly.
if (typeof config === 'boolean') return config
// If the config is a string, it must be 'incremental' to enable partial
// prerendering.
if (config === 'incremental') return true
return false
}
/**
* Returns true if partial prerendering is supported for the current page with
* the provided app configuration. If the application doesn't have partial
* prerendering enabled, this function will always return false. If you want to
* check if the application has partial prerendering enabled
*
* @see {@link checkIsAppPPREnabled} for checking if the application has PPR enabled.
*/
export function checkIsRoutePPREnabled(
config: ExperimentalPPRConfig | undefined
): boolean {
// If the config is undefined, partial prerendering is disabled.
if (typeof config === 'undefined') return false
// If the config is a boolean, use it directly.
if (typeof config === 'boolean') return config
return false
}
......@@ -369,7 +369,6 @@ export function createPatchedFetcher(
// TODO: Stop accumulating tags in client prerender. (fallthrough)
case 'prerender-client':
case 'validation-client':
case 'prerender-ppr':
case 'prerender-legacy':
case 'cache':
case 'private-cache':
......@@ -412,7 +411,6 @@ export function createPatchedFetcher(
case 'prerender-client':
case 'validation-client':
case 'prerender-runtime':
case 'prerender-ppr':
case 'prerender-legacy':
case 'request':
case 'cache':
......@@ -584,7 +582,6 @@ export function createPatchedFetcher(
)
}
break
case 'prerender-ppr':
case 'prerender-legacy':
case 'cache':
case 'private-cache':
......@@ -717,7 +714,6 @@ export function createPatchedFetcher(
)
}
break
case 'prerender-ppr':
case 'prerender-legacy':
case 'cache':
case 'private-cache':
......@@ -764,7 +760,6 @@ export function createPatchedFetcher(
case 'prerender-client':
case 'validation-client':
case 'prerender-runtime':
case 'prerender-ppr':
case 'prerender-legacy':
case 'unstable-cache':
case 'generate-static-params':
......@@ -917,7 +912,6 @@ export function createPatchedFetcher(
)
}
// fallthrough
case 'prerender-ppr':
case 'prerender-legacy':
case 'cache':
case 'private-cache':
......@@ -1001,7 +995,6 @@ export function createPatchedFetcher(
)
}
break
case 'prerender-ppr':
case 'prerender-legacy':
case 'cache':
case 'private-cache':
......@@ -1131,7 +1124,6 @@ export function createPatchedFetcher(
)
}
break
case 'prerender-ppr':
case 'prerender-legacy':
case 'cache':
case 'private-cache':
......@@ -1183,7 +1175,6 @@ export function createPatchedFetcher(
case 'private-cache':
case 'unstable-cache':
case 'prerender-legacy':
case 'prerender-ppr':
case 'generate-static-params':
break
default:
......
......@@ -24,7 +24,6 @@ import { pathHasPrefix } from '../../shared/lib/router/utils/path-has-prefix'
import { removePathPrefix } from '../../shared/lib/router/utils/remove-path-prefix'
import setupCompression from 'next/dist/compiled/compression'
import { signalFromNodeResponse } from '../web/spec-extension/adapters/next-request'
import { isPostpone } from './router-utils/is-postpone'
import { parseUrl as parseUrlUtil } from '../../shared/lib/router/utils/parse-url'
import {
......@@ -795,11 +794,6 @@ export async function initialize(opts: {
type: 'uncaughtException' | 'unhandledRejection',
err: Error | undefined
) => {
if (isPostpone(err)) {
// React postpones that are unhandled might end up logged here but they're
// not really errors. They're just part of rendering.
return
}
if (type === 'unhandledRejection') {
Log.error('unhandledRejection: ', err)
} else if (type === 'uncaughtException') {
......
const REACT_POSTPONE_TYPE: symbol = Symbol.for('react.postpone')
export function isPostpone(error: any): boolean {
return (
typeof error === 'object' &&
error !== null &&
error.$$typeof === REACT_POSTPONE_TYPE
)
}
......@@ -257,7 +257,6 @@ function patchConsoleMethod(methodName: InterceptableConsoleMethod): void {
}
// intentional fallthrough
case 'prerender-legacy':
case 'prerender-ppr':
case 'cache':
case 'unstable-cache':
case 'private-cache':
......
......@@ -90,7 +90,6 @@ export function io(expression: string, type: SyncIOApiType) {
break
}
case 'validation-client':
case 'prerender-ppr':
case 'prerender-legacy':
case 'cache':
case 'private-cache':
......
import { isPostpone } from '../lib/router-utils/is-postpone'
let _global = globalThis as typeof globalThis & {
nextInitializedProcessErrorHandlers?: boolean
}
......@@ -56,11 +54,6 @@ export function installProcessErrorHandlers(
// Install a new handler to prevent the process from crashing.
process.on('unhandledRejection', (reason: unknown) => {
if (isPostpone(reason)) {
// React postpones that are unhandled might end up logged here but they're
// not really errors. They're just part of rendering.
return
}
// Immediately log the error.
// TODO: Ideally, if we knew that this error was triggered by application
// code, we would suppress it entirely without logging. We can't reliably
......@@ -81,9 +74,6 @@ export function installProcessErrorHandlers(
// is unrelated to the late-awaiting pattern. However, for similar reasons,
// we still shouldn't crash the process. Just log it.
process.on('uncaughtException', (reason: unknown) => {
if (isPostpone(reason)) {
return
}
console.error(reason)
})
}
......@@ -615,7 +615,6 @@ function filteringUnhandledRejectionHandler(
}
break
}
case 'prerender-ppr':
case 'prerender-legacy':
case 'cache':
case 'private-cache':
......
......@@ -76,7 +76,6 @@ async function getCachedImageResponseArrayBuffer(
case 'prerender-runtime':
case 'prerender-client':
case 'validation-client':
case 'prerender-ppr':
case 'prerender-legacy':
case 'generate-static-params':
return renderImageResponseArrayBuffer(args)
......
......@@ -4,7 +4,6 @@ import {
workUnitAsyncStorage,
} from '../app-render/work-unit-async-storage.external'
import {
postponeWithTracking,
throwToInterruptStaticGeneration,
trackDynamicDataInDynamicRender,
} from '../app-render/dynamic-rendering'
......@@ -96,14 +95,6 @@ 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.`
)
}
case 'prerender-ppr':
// We use React's postpone API to interrupt rendering here to create a
// dynamic hole
return postponeWithTracking(
workStore.route,
'connection',
workUnitStore.dynamicTracking
)
case 'prerender-legacy':
// We throw an error here to interrupt prerendering to mark the route
// as dynamic
......
......@@ -16,7 +16,6 @@ import {
isInEarlyRenderStage,
} from '../app-render/work-unit-async-storage.external'
import {
postponeWithTracking,
throwToInterruptStaticGeneration,
trackDynamicDataInDynamicRender,
} from '../app-render/dynamic-rendering'
......@@ -83,14 +82,6 @@ export function cookies(): Promise<ReadonlyRequestCookies> {
throw new InvariantError(
`${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.
return postponeWithTracking(
workStore.route,
callingExpression,
workUnitStore.dynamicTracking
)
case 'prerender-legacy':
// We track dynamic access here so we don't need to wrap the cookies
// in individual property access tracking.
......
......@@ -12,7 +12,6 @@ import {
import { workUnitAsyncStorage } from '../app-render/work-unit-async-storage.external'
import {
abortAndThrowOnSynchronousRequestDataAccess,
postponeWithTracking,
trackDynamicDataInDynamicRender,
} from '../app-render/dynamic-rendering'
import { createDedupedByCallsiteServerErrorLoggerDev } from '../create-deduped-by-callsite-server-error-logger'
......@@ -69,7 +68,6 @@ export function draftMode(): Promise<DraftMode> {
// Otherwise, we fall through to providing an empty draft mode.
// eslint-disable-next-line no-fallthrough
case 'prerender':
case 'prerender-ppr':
case 'prerender-legacy':
// Return empty draft mode
return createOrGetCachedDraftMode(null, workStore)
......@@ -243,12 +241,6 @@ function trackDynamicDraftMode(expression: string, constructorOpt: Function) {
throw new InvariantError(
`${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':
return postponeWithTracking(
workStore.route,
expression,
workUnitStore.dynamicTracking
)
case 'prerender-legacy':
workUnitStore.revalidate = 0
......
......@@ -14,7 +14,6 @@ import {
isInEarlyRenderStage,
} from '../app-render/work-unit-async-storage.external'
import {
postponeWithTracking,
throwToInterruptStaticGeneration,
trackDynamicDataInDynamicRender,
} from '../app-render/dynamic-rendering'
......@@ -82,7 +81,6 @@ export function headers(): Promise<ReadonlyHeaders> {
case 'validation-client':
case 'private-cache':
case 'prerender-runtime':
case 'prerender-ppr':
case 'prerender-legacy':
case 'request':
break
......@@ -107,16 +105,6 @@ export function headers(): Promise<ReadonlyHeaders> {
throw new InvariantError(
`${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
return postponeWithTracking(
workStore.route,
callingExpression,
workUnitStore.dynamicTracking
)
case 'prerender-legacy':
// Legacy Prerender
// We are in a legacy static generation mode while prerendering
......
......@@ -5,7 +5,6 @@ import {
makeDevtoolsIOAwarePromise,
} from '../dynamic-rendering-utils'
import { RenderStage } from '../app-render/staged-rendering'
import { throwPrerenderPPRRemovedError } from '../../shared/lib/ppr-removed-error'
import { isRequestApiAllowedInCurrentPhase } from './utils'
// A fulfilled thenable that React can unwrap synchronously via `use()` without
......@@ -67,10 +66,6 @@ export function io(): Promise<void> {
workStore.route,
'`io()`'
)
case 'prerender-ppr':
// Dead code to be removed when we eliminate legacy ppr code
throwPrerenderPPRRemovedError()
break
case 'cache':
case 'private-cache':
case 'unstable-cache':
......
......@@ -10,15 +10,8 @@ import {
} from '../app-render/vary-params'
import { ReflectAdapter } from '../web/spec-extension/adapters/reflect'
import {
throwToInterruptStaticGeneration,
postponeWithTracking,
} from '../app-render/dynamic-rendering'
import {
workUnitAsyncStorage,
type PrerenderStorePPR,
type PrerenderStoreLegacy,
type StaticPrerenderStoreModern,
type StaticPrerenderStore,
throwInvariantForMissingStore,
......@@ -56,7 +49,6 @@ export function createParamsFromClient(
switch (workUnitStore.type) {
case 'prerender':
case 'prerender-client':
case 'prerender-ppr':
case 'prerender-legacy':
// Client params don't need additional vary tracking because by the
// time they reach the client, the access would have already been
......@@ -147,7 +139,6 @@ export function createServerParamsForRoute(
if (workUnitStore) {
switch (workUnitStore.type) {
case 'prerender':
case 'prerender-ppr':
case 'prerender-legacy':
return createStaticPrerenderParams(
underlyingParams,
......@@ -212,7 +203,6 @@ export function createServerParamsForServerSegment(
switch (workUnitStore.type) {
case 'prerender':
case 'prerender-client':
case 'prerender-ppr':
case 'prerender-legacy':
return createStaticPrerenderParams(
underlyingParams,
......@@ -308,7 +298,6 @@ export function createPrerenderParamsForClientSegment(
'createPrerenderParamsForClientSegment should not be called inside generateStaticParams.'
)
case 'prerender-runtime':
case 'prerender-ppr':
case 'prerender-legacy':
case 'request':
break
......@@ -392,22 +381,6 @@ function createStaticPrerenderParams(
}
break
}
case 'prerender-ppr': {
const fallbackParams = prerenderStore.fallbackRouteParams
if (fallbackParams) {
for (const key in underlyingParams) {
if (fallbackParams.has(key)) {
return makeErroringParams(
underlyingParams,
fallbackParams,
workStore,
prerenderStore
)
}
}
}
break
}
case 'prerender-legacy':
break
default:
......@@ -760,65 +733,6 @@ function makeHangingParams(
return promise
}
function makeErroringParams(
underlyingParams: Params,
fallbackParams: OpaqueFallbackRouteParams,
workStore: WorkStore,
prerenderStore: PrerenderStorePPR | PrerenderStoreLegacy
): Promise<Params> {
const cachedParams = CachedParams.get(underlyingParams)
if (cachedParams) {
return cachedParams
}
const augmentedUnderlying = { ...underlyingParams }
// We don't use makeResolvedReactPromise here because params
// supports copying with spread and we don't want to unnecessarily
// instrument the promise with spreadable properties of ReactPromise.
const promise = Promise.resolve(augmentedUnderlying)
CachedParams.set(underlyingParams, promise)
Object.keys(underlyingParams).forEach((prop) => {
if (wellKnownProperties.has(prop)) {
// These properties cannot be shadowed because they need to be the
// true underlying value for Promises to work correctly at runtime
} else {
if (fallbackParams.has(prop)) {
Object.defineProperty(augmentedUnderlying, prop, {
get() {
const expression = describeStringPropertyAccess('params', prop)
// In most dynamic APIs we also throw if `dynamic = "error"` however
// for params is only dynamic when we're generating a fallback shell
// and even when `dynamic = "error"` we still support generating dynamic
// fallback shells
// TODO remove this comment when cacheComponents is the default since there
// will be no `dynamic = "error"`
if (prerenderStore.type === 'prerender-ppr') {
// PPR Prerender (no cacheComponents)
postponeWithTracking(
workStore.route,
expression,
prerenderStore.dynamicTracking
)
} else {
// Legacy Prerender
throwToInterruptStaticGeneration(
expression,
workStore,
prerenderStore
)
}
},
enumerable: true,
})
}
}
})
return promise
}
function makeUntrackedParams(underlyingParams: Params): Promise<Params> {
const cachedParams = CachedParams.get(underlyingParams)
if (cachedParams) {
......
......@@ -3,17 +3,11 @@ import {
type WorkStore,
} from '../app-render/work-async-storage.external'
import {
postponeWithTracking,
type DynamicTrackingState,
} from '../app-render/dynamic-rendering'
import {
throwInvariantForMissingStore,
workUnitAsyncStorage,
type PrerenderStoreLegacy,
type PrerenderStoreModernServer,
type PrerenderStorePPR,
} from '../app-render/work-unit-async-storage.external'
import {
makeHangingPromise,
......@@ -33,7 +27,6 @@ export function createServerPathnameForMetadata(
if (workUnitStore) {
switch (workUnitStore.type) {
case 'prerender':
case 'prerender-ppr':
case 'prerender-legacy': {
return createPrerenderPathname(
underlyingPathname,
......@@ -91,10 +84,7 @@ export function createServerPathnameForMetadata(
function createPrerenderPathname(
underlyingPathname: string,
workStore: WorkStore,
prerenderStore:
| PrerenderStoreLegacy
| PrerenderStorePPR
| PrerenderStoreModernServer
prerenderStore: PrerenderStoreLegacy | PrerenderStoreModernServer
): Promise<string> {
switch (prerenderStore.type) {
case 'prerender': {
......@@ -108,13 +98,6 @@ function createPrerenderPathname(
}
break
}
case 'prerender-ppr': {
const fallbackParams = prerenderStore.fallbackRouteParams
if (fallbackParams && fallbackParams.size > 0) {
return makeErroringPathname(workStore, prerenderStore.dynamicTracking)
}
break
}
case 'prerender-legacy':
break
default:
......@@ -125,41 +108,6 @@ function createPrerenderPathname(
return Promise.resolve(underlyingPathname)
}
function makeErroringPathname<T>(
workStore: WorkStore,
dynamicTracking: null | DynamicTrackingState
): Promise<T> {
let reject: null | ((reason: unknown) => void) = null
const promise = new Promise<T>((_, re) => {
reject = re
})
const originalThen = promise.then.bind(promise)
// We instrument .then so that we can generate a tracking event only if you actually
// await this promise, not just that it is created.
promise.then = (onfulfilled, onrejected) => {
if (reject) {
try {
postponeWithTracking(
workStore.route,
'metadata relative url resolving',
dynamicTracking
)
} catch (error) {
reject(error)
reject = null
}
}
return originalThen(onfulfilled, onrejected)
}
// We wrap in a noop proxy to trick the runtime into thinking it
// isn't a native promise (it's not really). This is so that awaiting
// the promise will call the `then` property triggering the lazy postpone
return new Proxy(promise, {})
}
function createRenderPathname(underlyingPathname: string): Promise<string> {
return Promise.resolve(underlyingPathname)
}
import { InvariantError } from '../../shared/lib/invariant-error'
import {
postponeWithTracking,
throwToInterruptStaticGeneration,
} from '../app-render/dynamic-rendering'
import {
workAsyncStorage,
type WorkStore,
......@@ -11,11 +7,9 @@ import {
workUnitAsyncStorage,
type PrerenderStoreLegacy,
type PrerenderStoreModernServer,
type PrerenderStorePPR,
} from '../app-render/work-unit-async-storage.external'
import { makeHangingPromise } from '../dynamic-rendering-utils'
import type { ParamValue } from './params'
import { describeStringPropertyAccess } from '../../shared/lib/utils/reflect-utils'
import { actionAsyncStorage } from '../app-render/action-async-storage.external'
import { accumulateRootVaryParam } from '../app-render/vary-params'
......@@ -73,7 +67,6 @@ export function getRootParam(paramName: string): Promise<ParamValue> {
return Promise.resolve(workUnitStore.rootParams[paramName])
}
case 'prerender':
case 'prerender-ppr':
case 'prerender-legacy': {
return createPrerenderRootParamPromise(
paramName,
......@@ -139,16 +132,12 @@ export function getRootParam(paramName: string): Promise<ParamValue> {
function createPrerenderRootParamPromise(
paramName: string,
workStore: WorkStore,
prerenderStore:
| PrerenderStorePPR
| PrerenderStoreLegacy
| PrerenderStoreModernServer,
prerenderStore: PrerenderStoreLegacy | PrerenderStoreModernServer,
apiName: string
): Promise<ParamValue> {
switch (prerenderStore.type) {
case 'prerender':
case 'prerender-legacy':
case 'prerender-ppr':
default:
}
......@@ -170,22 +159,6 @@ function createPrerenderRootParamPromise(
}
break
}
case 'prerender-ppr': {
// We aren't in a cacheComponents prerender, but the param is a fallback,
// so we need to make an erroring params object which will postpone/error if you access it
if (
prerenderStore.fallbackRouteParams &&
prerenderStore.fallbackRouteParams.has(paramName)
) {
return makeErroringRootParamPromise(
paramName,
workStore,
prerenderStore,
apiName
)
}
break
}
case 'prerender-legacy': {
// legacy prerenders can't have fallback params
break
......@@ -199,36 +172,3 @@ function createPrerenderRootParamPromise(
accumulateRootVaryParam(paramName)
return Promise.resolve(underlyingParams[paramName])
}
/** Deliberately async -- we want to create a rejected promise, not error synchronously. */
async function makeErroringRootParamPromise(
paramName: string,
workStore: WorkStore,
prerenderStore: PrerenderStorePPR | PrerenderStoreLegacy,
apiName: string
): Promise<ParamValue> {
const expression = describeStringPropertyAccess(apiName, paramName)
// In most dynamic APIs, we also throw if `dynamic = "error"`.
// However, root params are only dynamic when we're generating a fallback shell,
// and even with `dynamic = "error"` we still support generating dynamic fallback shells.
// TODO: remove this comment when cacheComponents is the default since there will be no `dynamic = "error"`
switch (prerenderStore.type) {
case 'prerender-ppr': {
return postponeWithTracking(
workStore.route,
expression,
prerenderStore.dynamicTracking
)
}
case 'prerender-legacy': {
return throwToInterruptStaticGeneration(
expression,
workStore,
prerenderStore
)
}
default: {
prerenderStore satisfies never
}
}
}
......@@ -11,14 +11,12 @@ import {
import { ReflectAdapter } from '../web/spec-extension/adapters/reflect'
import {
throwToInterruptStaticGeneration,
postponeWithTracking,
annotateDynamicAccess,
} from '../app-render/dynamic-rendering'
import {
workUnitAsyncStorage,
type PrerenderStoreLegacy,
type PrerenderStorePPR,
type PrerenderStoreModern,
type PrerenderStoreModernRuntime,
type StaticPrerenderStore,
......@@ -59,7 +57,6 @@ export function createSearchParamsFromClient(
switch (workUnitStore.type) {
case 'prerender':
case 'prerender-client':
case 'prerender-ppr':
case 'prerender-legacy':
return createStaticPrerenderSearchParams(workStore, workUnitStore)
case 'validation-client': {
......@@ -126,7 +123,6 @@ export function createServerSearchParamsForServerPage(
switch (workUnitStore.type) {
case 'prerender':
case 'prerender-client':
case 'prerender-ppr':
case 'prerender-legacy':
return createStaticPrerenderSearchParams(workStore, workUnitStore)
case 'validation-client':
......@@ -205,7 +201,6 @@ export function createPrerenderSearchParamsForClientPage(): Promise<SearchParams
throw new InvariantError(
'createPrerenderSearchParamsForClientPage should not be called inside generateStaticParams.'
)
case 'prerender-ppr':
case 'prerender-legacy':
case 'request':
return Promise.resolve({})
......@@ -231,7 +226,6 @@ function createStaticPrerenderSearchParams(
case 'prerender-client':
// We are in a cacheComponents (PPR or otherwise) prerender
return makeHangingSearchParams(workStore, prerenderStore)
case 'prerender-ppr':
case 'prerender-legacy':
// We are in a legacy static generation and need to interrupt the
// prerender when search params are accessed.
......@@ -421,7 +415,7 @@ function makeHangingSearchParams(
function makeErroringSearchParams(
workStore: WorkStore,
prerenderStore: PrerenderStoreLegacy | PrerenderStorePPR
prerenderStore: PrerenderStoreLegacy
): Promise<SearchParams> {
const cachedSearchParams = CachedSearchParams.get(workStore)
if (cachedSearchParams) {
......@@ -451,13 +445,6 @@ function makeErroringSearchParams(
workStore.route,
expression
)
} else if (prerenderStore.type === 'prerender-ppr') {
// PPR Prerender (no cacheComponents)
postponeWithTracking(
workStore.route,
expression,
prerenderStore.dynamicTracking
)
} else {
// Legacy Prerender
throwToInterruptStaticGeneration(
......
......@@ -60,7 +60,6 @@ import { StaticGenBailoutError } from '../../../client/components/static-generat
import { isStaticGenEnabled } from './helpers/is-static-gen-enabled'
import {
abortAndThrowOnSynchronousRequestDataAccess,
postponeWithTracking,
createDynamicTrackingState,
getFirstDynamicReason,
} from '../../app-render/dynamic-rendering'
......@@ -1352,12 +1351,6 @@ function trackDynamic(
throw new InvariantError(
'A runtime prerender store should not be used for a route handler.'
)
case 'prerender-ppr':
return postponeWithTracking(
store.route,
expression,
workUnitStore.dynamicTracking
)
case 'prerender-legacy':
workUnitStore.revalidate = 0
......
......@@ -88,7 +88,6 @@ export function cacheLife(profile: CacheLifeProfiles | CacheLife): void {
case 'prerender-client':
case 'validation-client':
case 'prerender-runtime':
case 'prerender-ppr':
case 'prerender-legacy':
case 'request':
case 'unstable-cache':
......
......@@ -15,7 +15,6 @@ export function cacheTag(...tags: string[]): void {
case 'prerender-client':
case 'validation-client':
case 'prerender-runtime':
case 'prerender-ppr':
case 'prerender-legacy':
case 'request':
case 'unstable-cache':
......
......@@ -83,7 +83,6 @@ import {
} from './use-cache-errors'
import {
createHangingInputAbortSignal,
postponeWithTracking,
throwToInterruptStaticGeneration,
} from '../app-render/dynamic-rendering'
import {
......@@ -686,7 +685,6 @@ function createUseCacheStore(
break
case 'prerender-runtime':
case 'prerender':
case 'prerender-ppr':
case 'prerender-legacy':
case 'unstable-cache':
case 'generate-static-params':
......@@ -746,7 +744,6 @@ function captureOuterOwnerStack(
case 'unstable-cache':
case 'request':
case 'prerender':
case 'prerender-ppr':
case 'prerender-legacy':
case 'prerender-runtime':
case 'prerender-client':
......@@ -916,7 +913,6 @@ function propagateCacheEntryMetadata(
case 'private-cache':
case 'prerender':
case 'prerender-runtime':
case 'prerender-ppr':
case 'prerender-legacy':
propagateCacheLifeAndTagsToRevalidateStore(
cacheContext.outerWorkUnitStore,
......@@ -981,8 +977,7 @@ function maybePropagateCacheEntryMetadata(
case 'private-cache':
case 'cache':
case 'unstable-cache':
case 'prerender-legacy':
case 'prerender-ppr': {
case 'prerender-legacy': {
propagateCacheEntryMetadata(cacheContext, metadata)
break
}
......@@ -1223,7 +1218,6 @@ async function generateCacheEntryImpl(
}
})
break
case 'prerender-ppr':
case 'prerender-legacy':
case 'request':
case 'cache':
......@@ -1479,7 +1473,6 @@ async function generateCacheEntryImpl(
}
}
// fallthrough
case 'prerender-ppr':
case 'prerender-legacy':
case 'cache':
case 'private-cache':
......@@ -1725,12 +1718,6 @@ export async function cache(
workStore.route,
expression
)
case 'prerender-ppr':
return postponeWithTracking(
workStore.route,
expression,
workUnitStore.dynamicTracking
)
case 'prerender-legacy':
return throwToInterruptStaticGeneration(
expression,
......@@ -1818,7 +1805,6 @@ export async function cache(
}
case 'prerender':
case 'prerender-runtime':
case 'prerender-ppr':
case 'prerender-legacy':
case 'request':
case 'private-cache':
......@@ -2074,7 +2060,6 @@ export async function cache(
break
}
// fallthrough
case 'prerender-ppr':
case 'prerender-legacy':
case 'request':
// TODO(restart-on-cache-miss): We need to handle params/searchParams on page components.
......@@ -2213,7 +2198,6 @@ export async function cache(
workStore.route,
'dynamic "use cache"'
)
case 'prerender-ppr':
case 'prerender-legacy':
case 'request':
case 'cache':
......@@ -2368,7 +2352,6 @@ export async function cache(
}
break
}
case 'prerender-ppr':
case 'prerender-legacy':
case 'cache':
case 'private-cache':
......@@ -2422,7 +2405,6 @@ export async function cache(
}
break
}
case 'prerender-ppr':
case 'prerender-legacy':
case 'cache':
case 'private-cache':
......@@ -2530,7 +2512,6 @@ export async function cache(
)
}
break
case 'prerender-ppr':
case 'prerender-legacy':
case 'request':
case 'cache':
......@@ -2893,7 +2874,6 @@ export async function cache(
break
}
case 'prerender-runtime':
case 'prerender-ppr':
case 'prerender-legacy':
case 'cache':
case 'private-cache':
......@@ -2929,7 +2909,6 @@ export async function cache(
}
case 'prerender':
case 'prerender-runtime':
case 'prerender-ppr':
case 'prerender-legacy':
case 'cache':
case 'private-cache':
......@@ -3275,7 +3254,6 @@ function shouldForceRevalidate(
case 'prerender':
case 'prerender-client':
case 'validation-client':
case 'prerender-ppr':
case 'prerender-legacy':
case 'unstable-cache':
case 'generate-static-params':
......@@ -3319,7 +3297,6 @@ function shouldDiscardCacheEntry(
case 'prerender-runtime':
case 'prerender-client':
case 'validation-client':
case 'prerender-ppr':
case 'prerender-legacy':
case 'request':
case 'cache':
......
......@@ -315,7 +315,6 @@ export async function adapter(
// TODO: remove validationLevel and other global config from renderOpts
validationLevel: 'warning',
experimental: {
isRoutePPREnabled: false,
authInterrupts:
!!params.request.nextConfig?.experimental?.authInterrupts,
// Proxy doesn't fill Cache Components entries, so this value
......
import {
abortAndThrowOnSynchronousRequestDataAccess,
postponeWithTracking,
} from '../../app-render/dynamic-rendering'
import { abortAndThrowOnSynchronousRequestDataAccess } from '../../app-render/dynamic-rendering'
import { isDynamicRoute } from '../../../shared/lib/router/utils'
import {
NEXT_CACHE_IMPLICIT_TAG_ID,
......@@ -173,12 +170,6 @@ function revalidate(
throw new InvariantError(
`${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.`
)
case 'prerender-ppr':
return postponeWithTracking(
store.route,
expression,
workUnitStore.dynamicTracking
)
case 'prerender-legacy':
workUnitStore.revalidate = 0
......
......@@ -166,7 +166,6 @@ export function unstable_cache<T extends Callback>(
case 'private-cache':
case 'prerender':
case 'prerender-runtime':
case 'prerender-ppr':
case 'prerender-legacy':
// We update the store's revalidate property if the option.revalidate is a higher precedence
// options.revalidate === undefined doesn't affect timing.
......@@ -418,7 +417,6 @@ function getFetchUrlPrefix(
case 'prerender-client':
case 'validation-client':
case 'prerender-runtime':
case 'prerender-ppr':
case 'prerender-legacy':
case 'cache':
case 'private-cache':
......
......@@ -38,7 +38,6 @@ export function unstable_noStore() {
case 'prerender-runtime':
// unstable_noStore() is a noop in Dynamic I/O.
return
case 'prerender-ppr':
case 'prerender-legacy':
case 'request':
case 'cache':
......
import { InvariantError } from './invariant-error'
/**
* Throws an InvariantError indicating that a prerender-ppr code path was
* reached. The prerender-ppr work unit type has been removed and all code
* handling it is dead. Use this in exhaustive switch cases while the
* prerender-ppr type is being cleaned up.
*/
export function throwPrerenderPPRRemovedError(): never {
throw new InvariantError(
'The prerender-ppr work unit type has been removed. This code path should be unreachable.'
)
}
import React from 'react'
export default function Root({ children }) {
return (
<html>
<body>{children}</body>
</html>
)
}
import { Suspense } from 'react'
import { cookies } from 'next/headers'
export default async function Page() {
return (
<Suspense fallback={<div>Loading...</div>}>
<Foobar />
</Suspense>
)
}
async function Foobar() {
try {
await cookies()
} catch (err) {
console.log('User land logged error: ' + err.message)
}
await cookies() // still postpones so doesn't fail build
return null
}
import React from 'react'
import { cookies } from 'next/headers'
export default async function Page() {
try {
await cookies()
} catch (err) {
throw new Error(
"Throwing a new error from 'no-suspense-boundary-re-throwing-error'"
)
}
return <div>Hello World</div>
}
import React from 'react'
import { cookies } from 'next/headers'
export default async function Page() {
try {
await cookies()
} catch (err) {}
return <div>Hello World</div>
}
import React, { Suspense } from 'react'
import { cookies } from 'next/headers'
export default async function Page() {
return (
<Suspense fallback={<div>Loading...</div>}>
<Foobar />
</Suspense>
)
}
async function Foobar() {
try {
await cookies()
} catch (err) {}
return null
}
import React, { Suspense } from 'react'
import { cookies } from 'next/headers'
export default async function Page() {
return (
<Suspense fallback={<div>Loading...</div>}>
<Foobar />
</Suspense>
)
}
async function Foobar() {
try {
await cookies()
} catch (err) {
throw new Error('The original error was caught and rethrown.')
}
return null
}
import React, { Suspense } from 'react'
export default async function Page() {
return (
<Suspense fallback={<div>Loading...</div>}>
<Foobar />
</Suspense>
)
}
async function Foobar() {
throw new Error('Kaboom')
}
export default async function Page() {
throw new Error('Regular Prerender Error')
}
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {
cacheComponents: true,
experimental: { prerenderEarlyExit: false },
}
module.exports = nextConfig
import { isNextStart, nextTestSetup } from 'e2e-utils'
// TODO(NAR-423): Migrate to Cache Components.
describe.skip('ppr build errors', () => {
;(isNextStart ? describe : describe.skip)('production only', () => {
const { next } = nextTestSetup({
files: __dirname,
skipStart: true,
})
let cliOutput: string
beforeAll(async () => {
const output = await next.build()
cliOutput = output.cliOutput
})
describe('within a suspense boundary', () => {
it('should fail the build for uncaught prerender errors', async () => {
expect(cliOutput).toContain(
'Error occurred prerendering page "/regular-error-suspense-boundary".'
)
expect(cliOutput).toContain(
'Error occurred prerendering page "/re-throwing-error".'
)
})
})
describe('outside of a suspense boundary', () => {
it('should fail the build for uncaught errors', async () => {
expect(cliOutput).toContain(
'Error occurred prerendering page "/regular-error".'
)
expect(cliOutput).toContain(
'Error occurred prerendering page "/no-suspense-boundary-re-throwing-error".'
)
})
})
describe('when a postpone call is caught and logged it should', () => {
it('should include a message telling why', async () => {
expect(cliOutput).toContain(
'User land logged error: Route /logging-error needs to bail out of prerendering at this point because it used cookies.'
)
})
})
})
})
......@@ -2,10 +2,10 @@ import { nextTestSetup } from 'e2e-utils'
// TODO(NAR-423): Migrate to Cache Components.
describe.skip('static-shell-debugging', () => {
const ppr = Boolean(process.env.__NEXT_CACHE_COMPONENTS)
const cacheComponents = Boolean(process.env.__NEXT_CACHE_COMPONENTS)
const context = {
ppr,
debugging: ppr,
cacheComponents,
debugging: cacheComponents,
}
const { next, skipped, isNextDev } = nextTestSetup({
......@@ -19,13 +19,13 @@ describe.skip('static-shell-debugging', () => {
: undefined,
},
nextConfig: {
experimental: { ppr: context.ppr },
cacheComponents: context.cacheComponents,
},
})
if (skipped) return
if (context.debugging && context.ppr) {
if (context.debugging && context.cacheComponents) {
it('should only render the static shell', async () => {
const res = await next.fetch('/?__nextppronly=1')
expect(res.status).toBe(200)
......
......@@ -159,7 +159,7 @@ describe('Config Experimental Warning', () => {
nextConfig: {
experimental: {
ppr: 'incremental',
},
} as any,
},
})
......
......@@ -2,7 +2,7 @@ import React from 'react';
import { DynamicServerError } from '../../client/components/hooks-server-context';
import { StaticGenBailoutError } from '../../client/components/static-generation-bailout';
import { getPathname } from '../../lib/url';
const hasPostpone = typeof React.unstable_postpone === 'function';
const hasUnnamed = typeof React.unstable_unnamed === 'function';
export function createPrerenderState(isDebugSkeleton) {
return {
isDebugSkeleton,
......@@ -16,7 +16,7 @@ export function markCurrentScopeAsDynamic(store, expression) {
} else if (store.dynamicShouldError) {
throw new StaticGenBailoutError(`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`);
} else if (store.prerenderState) {
postponeWithTracking(store.prerenderState, expression, pathname);
markPrerenderState(store.prerenderState, expression, pathname);
} else {
store.revalidate = 0;
if (store.isStaticGeneration) {
......@@ -34,7 +34,7 @@ export function trackDynamicDataAccessed(store, expression) {
} else if (store.dynamicShouldError) {
throw new StaticGenBailoutError(`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`);
} else if (store.prerenderState) {
postponeWithTracking(store.prerenderState, expression, pathname);
markPrerenderState(store.prerenderState, expression, pathname);
} else {
store.revalidate = 0;
if (store.isStaticGeneration) {
......@@ -45,21 +45,21 @@ export function trackDynamicDataAccessed(store, expression) {
}
}
}
export function Postpone({ reason, prerenderState, pathname }) {
postponeWithTracking(prerenderState, reason, pathname);
export function ApiThatShallNotBeNamed({ reason, prerenderState, pathname }) {
markPrerenderState(prerenderState, reason, pathname);
}
export function trackDynamicFetch(store, expression) {
if (!store.prerenderState || store.isUnstableCacheCallback) return;
postponeWithTracking(store.prerenderState, expression, store.urlPathname);
markPrerenderState(store.prerenderState, expression, store.urlPathname);
}
function postponeWithTracking(prerenderState, expression, pathname) {
assertPostpone();
function markPrerenderState(prerenderState, expression, pathname) {
assertUnnamed();
const reason = `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`;
prerenderState.dynamicAccesses.push({
stack: prerenderState.isDebugSkeleton ? new Error().stack : undefined,
expression
});
React.unstable_postpone(reason);
React.unstable_unnamed(reason);
}
export function usedDynamicAPIs(prerenderState) {
return prerenderState.dynamicAccesses.length > 0;
......@@ -81,16 +81,16 @@ export function formatDynamicAPIAccesses(prerenderState) {
return `Dynamic API Usage Debug - ${expression}:\n${stack}`;
});
}
function assertPostpone() {
if (!hasPostpone) {
throw new Error(`Invariant: React.unstable_postpone is not defined. This suggests the wrong version of React was loaded. This is a bug in Next.js`);
function assertUnnamed() {
if (!hasUnnamed) {
throw new Error(`Invariant: React.unstable_unnamed is not defined. This suggests the wrong version of React was loaded. This is a bug in Next.js`);
}
}
export function createPostponedAbortSignal(reason) {
assertPostpone();
export function createUnnamedAbortSignal(reason) {
assertUnnamed();
const controller = new AbortController();
try {
React.unstable_postpone(reason);
React.unstable_unnamed(reason);
} catch (x) {
controller.abort(x);
}
......
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