Unverified Commit b4013ed3 authored by Jiwon Choi's avatar Jiwon Choi Committed by GitHub

Remove legacy PPR postpone cluster (#90726)

Stacked on https://github.com/vercel/next.js/pull/90721

Verified deployment tests pass on CI:
https://github.com/vercel/next.js/actions/runs/22541051404
parent 5dd02c46
...@@ -2,10 +2,7 @@ import { isHangingPromiseRejectionError } from '../../server/dynamic-rendering-u ...@@ -2,10 +2,7 @@ import { isHangingPromiseRejectionError } from '../../server/dynamic-rendering-u
import { isPostpone } from '../../server/lib/router-utils/is-postpone' import { isPostpone } from '../../server/lib/router-utils/is-postpone'
import { isBailoutToCSRError } from '../../shared/lib/lazy-dynamic/bailout-to-csr' import { isBailoutToCSRError } from '../../shared/lib/lazy-dynamic/bailout-to-csr'
import { isNextRouterError } from './is-next-router-error' import { isNextRouterError } from './is-next-router-error'
import { import { isPrerenderInterruptedError } from '../../server/app-render/dynamic-rendering'
isDynamicPostpone,
isPrerenderInterruptedError,
} from '../../server/app-render/dynamic-rendering'
import { isDynamicServerError } from './hooks-server-context' import { isDynamicServerError } from './hooks-server-context'
export function unstable_rethrow(error: unknown): void { export function unstable_rethrow(error: unknown): void {
...@@ -13,7 +10,6 @@ export function unstable_rethrow(error: unknown): void { ...@@ -13,7 +10,6 @@ export function unstable_rethrow(error: unknown): void {
isNextRouterError(error) || isNextRouterError(error) ||
isBailoutToCSRError(error) || isBailoutToCSRError(error) ||
isDynamicServerError(error) || isDynamicServerError(error) ||
isDynamicPostpone(error) ||
isPostpone(error) || isPostpone(error) ||
isHangingPromiseRejectionError(error) || isHangingPromiseRejectionError(error) ||
isPrerenderInterruptedError(error) isPrerenderInterruptedError(error)
......
import { isDynamicServerError } from '../../client/components/hooks-server-context' import { isDynamicServerError } from '../../client/components/hooks-server-context'
import { isBailoutToCSRError } from '../../shared/lib/lazy-dynamic/bailout-to-csr' import { isBailoutToCSRError } from '../../shared/lib/lazy-dynamic/bailout-to-csr'
import { isNextRouterError } from '../../client/components/is-next-router-error' import { isNextRouterError } from '../../client/components/is-next-router-error'
import { isDynamicPostpone } from '../../server/app-render/dynamic-rendering'
export const isDynamicUsageError = (err: unknown) => export const isDynamicUsageError = (err: unknown) =>
isDynamicServerError(err) || isDynamicServerError(err) ||
isBailoutToCSRError(err) || isBailoutToCSRError(err) ||
isNextRouterError(err) || isNextRouterError(err)
isDynamicPostpone(err)
...@@ -133,7 +133,6 @@ async function createComponentTreeInternal( ...@@ -133,7 +133,6 @@ async function createComponentTreeInternal(
createServerParamsForServerSegment, createServerParamsForServerSegment,
createPrerenderParamsForClientSegment, createPrerenderParamsForClientSegment,
serverHooks: { DynamicServerError }, serverHooks: { DynamicServerError },
Postpone,
}, },
pagePath, pagePath,
getDynamicParamFromSegment, getDynamicParamFromSegment,
...@@ -725,46 +724,6 @@ async function createComponentTreeInternal( ...@@ -725,46 +724,6 @@ async function createComponentTreeInternal(
} }
const Component = MaybeComponent 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 &&
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
)
}
const isClientComponent = isClientReference(layoutOrPageMod) const isClientComponent = isClientReference(layoutOrPageMod)
const varyParamsAccumulator = const varyParamsAccumulator =
......
...@@ -28,7 +28,6 @@ import type { ...@@ -28,7 +28,6 @@ import type {
ValidationStoreClient, ValidationStoreClient,
} from '../app-render/work-unit-async-storage.external' } 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 React from 'react'
import { DynamicServerError } from '../../client/components/hooks-server-context' import { DynamicServerError } from '../../client/components/hooks-server-context'
...@@ -51,8 +50,6 @@ import { InvariantError } from '../../shared/lib/invariant-error' ...@@ -51,8 +50,6 @@ import { InvariantError } from '../../shared/lib/invariant-error'
import { INSTANT_VALIDATION_BOUNDARY_NAME } from './instant-validation/boundary-constants' import { INSTANT_VALIDATION_BOUNDARY_NAME } from './instant-validation/boundary-constants'
import type { ValidationBoundaryTracking } from './instant-validation/boundary-tracking' import type { ValidationBoundaryTracking } from './instant-validation/boundary-tracking'
const hasPostpone = typeof React.unstable_postpone === 'function'
export type DynamicAccess = { export type DynamicAccess = {
/** /**
* If debugging, this will contain the stack trace of where the dynamic access * If debugging, this will contain the stack trace of where the dynamic access
...@@ -329,73 +326,6 @@ export function abortAndThrowOnSynchronousRequestDataAccess( ...@@ -329,73 +326,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 {
postponeWithTracking(route, reason, null)
}
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' const NEXT_PRERENDER_INTERRUPTED = 'NEXT_PRERENDER_INTERRUPTED'
function createPrerenderInterruptedError(message: string): Error { function createPrerenderInterruptedError(message: string): Error {
...@@ -476,17 +406,9 @@ export function formatDynamicAPIAccesses( ...@@ -476,17 +406,9 @@ 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 with a dedicated CSR bailout reason so resumption can reliably switch
* abort semantics slightly. * postponed boundaries to client rendering.
*/ */
export function createRenderInBrowserAbortSignal(): AbortSignal { export function createRenderInBrowserAbortSignal(): AbortSignal {
const controller = new AbortController() const controller = new AbortController()
......
...@@ -38,7 +38,6 @@ export { createMetadataComponents } from '../../lib/metadata/metadata' ...@@ -38,7 +38,6 @@ export { createMetadataComponents } from '../../lib/metadata/metadata'
export { RootLayoutBoundary } from '../../lib/framework/boundary-components' export { RootLayoutBoundary } from '../../lib/framework/boundary-components'
export { preloadStyle, preloadFont, preconnect } from './rsc/preloads' export { preloadStyle, preloadFont, preconnect } from './rsc/preloads'
export { Postpone } from './rsc/postpone'
export { taintObjectReference } from './rsc/taint' export { taintObjectReference } from './rsc/taint'
export { collectSegmentData } from './collect-segment-data' export { collectSegmentData } from './collect-segment-data'
......
/*
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'
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