Unverified Commit 70a2e8d9 authored by Jiwon Choi's avatar Jiwon Choi Committed by GitHub

Replace PPR config helpers with cacheComponents checks (#90704)

This PR replaces the legacy PPR configs in the codebase with the
`cacheComponents` config.

Confirmed deployment test passes
https://github.com/vercel/next.js/actions/runs/22533307017

---------
Co-authored-by: 's avatarHendrik Liebau <mail@hendrik-liebau.de>
parent 5719439f
......@@ -2104,7 +2104,7 @@ export async function handleBuildComplete({
onMatchHeaders: [],
rewrites,
restrictedRedirectPaths: [],
isAppPPREnabled: config.cacheComponents,
isAppCacheComponentsEnabled: 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,7 +166,7 @@ async function collectRoutesForAnalyze(
config.basePath ? `${config.basePath}${pathPrefix}` : pathPrefix
)
const isAppPPREnabled = checkIsAppPPREnabled(config.experimental.ppr)
const isAppCacheComponentsEnabled = !!config.cacheComponents
// Generate routes manifest
const { routesManifest } = generateRoutesManifest({
......@@ -179,7 +178,7 @@ async function collectRoutesForAnalyze(
onMatchHeaders,
rewrites,
restrictedRedirectPaths,
isAppPPREnabled,
isAppCacheComponentsEnabled,
})
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,
......@@ -120,7 +119,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
......@@ -170,7 +168,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_INSTANT_NAV_TOGGLE':
!!config.experimental.instantNavigationDevToolsToggle,
......
......@@ -34,7 +34,7 @@ export interface GenerateRoutesManifestOptions {
onMatchHeaders: CustomRoutes['headers']
rewrites: CustomRoutes['rewrites']
restrictedRedirectPaths: string[]
isAppPPREnabled: boolean
isAppCacheComponentsEnabled: boolean
appType: 'pages' | 'app' | 'hybrid'
deploymentId?: string
}
......@@ -61,7 +61,7 @@ export function generateRoutesManifest(
onMatchHeaders,
rewrites,
restrictedRedirectPaths,
isAppPPREnabled,
isAppCacheComponentsEnabled,
appType,
deploymentId,
} = options
......@@ -132,7 +132,8 @@ export function generateRoutesManifest(
prefetchSegmentDirSuffix: RSC_SEGMENTS_DIR_SUFFIX,
clientParamParsing: config.cacheComponents ?? false,
clientParamParsingOrigins: config.experimental.clientParamParsingOrigins,
dynamicRSCPrerender: isAppPPREnabled && config.cacheComponents === true,
dynamicRSCPrerender:
isAppCacheComponentsEnabled && config.cacheComponents === true,
},
rewriteHeaders: {
pathHeader: NEXT_REWRITTEN_PATH_HEADER,
......@@ -140,7 +141,7 @@ export function generateRoutesManifest(
},
skipProxyUrlNormalize: config.skipProxyUrlNormalize,
deploymentId: deploymentId || undefined,
ppr: isAppPPREnabled
ppr: isAppCacheComponentsEnabled
? {
chain: {
headers: {
......
......@@ -185,10 +185,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'
......@@ -1492,8 +1488,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)
// Generate the routes manifest using the extracted helper
......@@ -1509,7 +1503,7 @@ export default async function build(
onMatchHeaders,
rewrites,
restrictedRedirectPaths,
isAppPPREnabled,
isAppCacheComponentsEnabled,
deploymentId: config.deploymentId,
})
)
......@@ -2062,7 +2056,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,
clientAssetToken:
......@@ -2289,7 +2282,6 @@ export default async function build(
: config.experimental.isrFlushToDisk,
cacheMaxMemorySize: config.cacheMaxMemorySize,
nextConfigOutput: config.output,
pprConfig: config.experimental.ppr,
cacheLifeProfiles: config.cacheLife,
buildId,
clientAssetToken:
......@@ -2694,7 +2686,7 @@ export default async function build(
},
{
featureName: 'experimental/ppr',
invocationCount: config.experimental.ppr ? 1 : 0,
invocationCount: config.cacheComponents ? 1 : 0,
},
{
featureName: 'turbopackFileSystemCache',
......@@ -2880,9 +2872,8 @@ export default async function build(
const appConfig = appDefaultConfigs.get(originalAppPath)
const isDynamicError = appConfig?.dynamic === 'error'
const isRoutePPREnabled: boolean = appConfig
? checkIsRoutePPREnabled(config.experimental.ppr)
: false
const isRoutePPREnabled: boolean =
!!appConfig && isAppCacheComponentsEnabled
routes.forEach((route) => {
// If the route has any dynamic root segments, we need to skip
......@@ -3076,8 +3067,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 && isAppCacheComponentsEnabled
? true
: undefined
......@@ -3217,7 +3207,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
......@@ -3301,7 +3291,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
......@@ -3404,7 +3394,7 @@ export default async function build(
prerenderManifest.dynamicRoutes[route.pathname] = {
experimentalPPR: isRoutePPREnabled,
renderingMode: isAppPPREnabled
renderingMode: isAppCacheComponentsEnabled
? isRoutePPREnabled
? RenderingMode.PARTIALLY_STATIC
: RenderingMode.STATIC
......
......@@ -20,7 +20,6 @@ import { BaseServerSpan } from '../../server/lib/trace/constants'
import { interopDefault } from '../../server/app-render/interop-default'
import { stripFlightHeaders } from '../../server/app-render/strip-flight-headers'
import { NodeNextRequest, NodeNextResponse } from '../../server/base-http/node'
import { checkIsAppPPREnabled } from '../../server/lib/experimental/ppr'
import {
getFallbackRouteParams,
createOpaqueFallbackRouteParams,
......@@ -100,7 +99,6 @@ import * as entryBase from '../../server/app-render/entry-base' with { 'turbopac
import { RedirectStatusCode } from '../../client/components/redirect-status-code'
import { InvariantError } from '../../shared/lib/invariant-error'
import { scheduleOnNextTick } from '../../lib/scheduler'
import { isInterceptionRouteAppPath } from '../../shared/lib/router/utils/interception-routes'
export * from '../../server/app-render/entry-base' with { 'turbopack-transition': 'next-server-utility' }
......@@ -195,16 +193,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 prerenderInfo =
nextConfig.experimental.ppr &&
!nextConfig.cacheComponents &&
isInterceptionRouteAppPath(resolvedPathname)
? null
: routeModule.match(resolvedPathname, prerenderManifest)
// source.
const prerenderInfo = routeModule.match(resolvedPathname, prerenderManifest)
const isPrerendered = !!prerenderManifest.routes[resolvedPathname]
......@@ -228,12 +218,10 @@ export async function handler(
const isPossibleServerAction = getIsPossibleServerAction(req)
/**
* If the route being rendered is an app page, and the ppr feature has been
* enabled, then the given route _could_ support PPR.
* If the route being rendered is an app page, and the cacheComponents feature
* has been enabled, then the given route _could_ support PPR.
*/
const couldSupportPPR: boolean = checkIsAppPPREnabled(
nextConfig.experimental.ppr
)
const isAppCacheComponentsEnabled: 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.
......@@ -241,7 +229,7 @@ export async function handler(
if (
!getRequestMeta(req, 'postponed') &&
isMinimalMode &&
couldSupportPPR &&
isAppCacheComponentsEnabled &&
isPossibleServerAction &&
resumeStateLengthHeader &&
typeof resumeStateLengthHeader === 'string'
......@@ -305,7 +293,7 @@ export async function handler(
if (
!getRequestMeta(req, 'postponed') &&
couldSupportPPR &&
isAppCacheComponentsEnabled &&
req.headers[NEXT_RESUME_HEADER] === '1' &&
req.method === 'POST'
) {
......@@ -332,7 +320,7 @@ export async function handler(
const hasDebugStaticShellQuery =
process.env.__NEXT_EXPERIMENTAL_STATIC_SHELL_DEBUGGING === '1' &&
typeof query.__nextppronly !== 'undefined' &&
couldSupportPPR
isAppCacheComponentsEnabled
// When enabled, this will allow the use of the `?__nextppronly` query
// to enable debugging of the fallback shell.
......@@ -354,7 +342,7 @@ export async function handler(
// with blocking happening on the client side.
const isInstantNavigationTest =
exposeTestingApi &&
couldSupportPPR &&
isAppCacheComponentsEnabled &&
(req.headers[NEXT_INSTANT_PREFETCH_HEADER] === '1' ||
(req.headers[RSC_HEADER] === undefined &&
typeof req.headers.cookie === 'string' &&
......@@ -363,7 +351,7 @@ export async function handler(
// This page supports PPR if it is marked as being `PARTIALLY_STATIC` in the
// prerender manifest and this is an app page.
const isRoutePPREnabled: boolean =
couldSupportPPR &&
isAppCacheComponentsEnabled &&
((
prerenderManifest.routes[normalizedSrcPage] ??
prerenderManifest.dynamicRoutes[normalizedSrcPage]
......
......@@ -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'
......@@ -666,7 +664,6 @@ export async function isPageStatic({
cacheHandler,
cacheHandlers,
cacheLifeProfiles,
pprConfig,
buildId,
clientAssetToken,
sriEnabled,
......@@ -693,7 +690,6 @@ export async function isPageStatic({
[profile: string]: import('../server/use-cache/cache-life').CacheLife
}
nextConfigOutput: 'standalone' | 'export' | undefined
pprConfig: ExperimentalPPRConfig | undefined
buildId: string
clientAssetToken: string
sriEnabled: boolean
......@@ -820,12 +816,10 @@ 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.
// A page supports partial prerendering if it is an app page and
// cacheComponents is enabled.
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.
......
......@@ -167,15 +167,11 @@ 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 res = await createFetch<NavigationFlightResponse>(
url,
headers,
'auto',
shouldImmediatelyDecode
true
)
const responseUrl = urlToUrlWithoutFlightMarker(new URL(res.url))
......
......@@ -856,7 +856,7 @@ 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')
}
......
......@@ -132,7 +132,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,
......@@ -427,7 +426,7 @@ export default abstract class Server<
readonly data: NextDataPathnameNormalizer | undefined
}
private readonly isAppPPREnabled: boolean
private readonly isCacheComponentsEnabled: boolean
/**
* This is used to persist cache scopes across
......@@ -513,9 +512,8 @@ export default abstract class Server<
this.enabledDirectories = this.getEnabledDirectories(dev)
this.isAppPPREnabled =
this.enabledDirectories.app &&
checkIsAppPPREnabled(this.nextConfig.experimental.ppr)
this.isCacheComponentsEnabled =
this.enabledDirectories.app && !!this.nextConfig.cacheComponents
this.normalizers = {
// We should normalize the pathname from the RSC prefix only in minimal
......@@ -1083,7 +1081,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.isCacheComponentsEnabled &&
this.minimalMode &&
req.headers[NEXT_RESUME_HEADER] === '1' &&
req.method === 'POST'
......@@ -2194,7 +2192,7 @@ export default abstract class Server<
* enabled, then the given route _could_ support PPR.
*/
const couldSupportPPR: boolean =
this.isAppPPREnabled &&
this.isCacheComponentsEnabled &&
typeof routeModule !== 'undefined' &&
isAppPageRouteModule(routeModule)
......
......@@ -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 { isStableBuild } from '../shared/lib/errors/canary-only-config-error'
import type { FallbackRouteParam } from '../build/static-paths/types'
......@@ -692,7 +691,7 @@ export interface ExperimentalConfig {
* @deprecated This configuration option has been merged into `cacheComponents`.
* The Partial Prerendering feature is still available via `cacheComponents`.
*/
ppr?: ExperimentalPPRConfig
ppr?: boolean | 'incremental'
/**
* Enables experimental taint APIs in React.
......
......@@ -1396,9 +1396,6 @@ function assignDefaultsAndValidate(
}
if (result.cacheComponents) {
// TODO: remove once we've finished migrating internally to cacheComponents.
result.experimental.ppr = true
// Prerender sourcemaps are enabled by default when using cacheComponents, unless explicitly disabled.
if (result.enablePrerenderSourceMaps === undefined) {
result.enablePrerenderSourceMaps = true
......
......@@ -798,7 +798,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 { parseAppRoute } from '../../shared/lib/router/routes/app'
type RuntimeConfig = {
pprConfig: ExperimentalPPRConfig | undefined
configFileName: string
cacheComponents: boolean
}
......@@ -126,8 +121,7 @@ export async function loadStaticPaths({
}
const isRoutePPREnabled =
isAppPageRouteModule(routeModule) &&
checkIsRoutePPREnabled(config.pprConfig)
isAppPageRouteModule(routeModule) && config.cacheComponents
const rootParamKeys = collectRootParamKeys(routeModule)
......
/**
* 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
}
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