Unverified Commit 4103f837 authored by Janka Uryga's avatar Janka Uryga Committed by GitHub

rename `RenderStage.Runtime` to `PrefetchRuntime` (#99679)

Aligns runtime stage naming with the static stages. We used to call this
the `Runtime` stage, but now we have the concept of navigation stages
("shell"/"prefetch"/"navigation") and we want to align the render stage
names with the navigation stage they correspond to (i.e. which content
they unblock), so it should be called `PrefetchRuntime` now.

(longer-term, i also want to fold `Static*` and `Runtime*` together, and
only use the navigation stage names, but this will take more work, so
we're not doing this now)
parent 1fffea65
......@@ -1259,7 +1259,7 @@ function getEnvironmentNameForStageWithoutCaches(stage: RenderStage) {
case RenderStage.Static:
return 'Prerender'
case RenderStage.ShellRuntime:
case RenderStage.Runtime:
case RenderStage.PrefetchRuntime:
case RenderStage.NavigationRuntime:
case RenderStage.Dynamic:
case RenderStage.Abandoned:
......@@ -1798,7 +1798,7 @@ async function finalRuntimeServerPrerender(
const stageController = new StagedRenderingController({
abortSignal: finalServerController.signal,
abandonController: null,
// In dynamic renders, we allow Sync IO in the Runtime stage
// In dynamic renders, we allow Sync IO in runtime stages
// if partialPrefetching is not enabled. However, a runtime prerender
// (or App Shell) is stricter and never allows sync IO in any stage
// that we go through here (i.e. < Dynamic)
......@@ -1936,9 +1936,9 @@ async function finalRuntimeServerPrerender(
if (checkUnexpectedAbort()) return
// We may not reach this stage depending on the mode.
if (finalStage < RenderStage.Runtime) return
if (finalStage < RenderStage.PrefetchRuntime) return
stageController.advanceStage(RenderStage.Runtime)
stageController.advanceStage(RenderStage.PrefetchRuntime)
},
() => {
if (checkUnexpectedAbort()) return
......@@ -1950,11 +1950,11 @@ async function finalRuntimeServerPrerender(
mode.shellUsedSessionDataDeferred.resolve(didSessionDataUnblockNewContent)
if ('shellByteLengthDeferred' in mode) {
// If advancing to the runtime stage didn't unblock new content,
// If advancing to the PrefetchRuntime stage didn't unblock new content,
// then the result does not depend on link data and can be used as a shell (indicated via `null`).
// Otherwise, send a byte length to indicate where the shell content ends.
const didLinkDataUnblockNewContent =
stageByteLengths[RenderStage.Runtime] >
stageByteLengths[RenderStage.PrefetchRuntime] >
stageByteLengths[RenderStage.ShellRuntime]
mode.shellByteLengthDeferred.resolve(
didLinkDataUnblockNewContent
......@@ -2026,7 +2026,7 @@ function getFinalStageForRuntimePrerenderMode(
case 'session-shell-only':
return RenderStage.ShellRuntime
case 'rewindable-session-shell':
return RenderStage.Runtime
return RenderStage.PrefetchRuntime
case 'navigation':
return RenderStage.NavigationRuntime
}
......@@ -5237,7 +5237,7 @@ async function prepareValidationInputsInPartialPrefetching(
// but `canRecoverStaticAndRuntimeShell === false` and we're doing a full rerender)
instantInputs && !needsRuntimeAppShell
? instantInputs
: // Otherwise perform a partial rerender (only up to the Runtime stage,
: // Otherwise perform a partial rerender (only up to the PrefetchRuntime stage,
// which we need for discriminated errors)
LAZY_RUNTIME_PRERENDER_WITH_STATIC_SHELL
......@@ -5479,7 +5479,7 @@ function getEnvironmentNameForStage(stage: RenderStage) {
case RenderStage.Static:
return 'Prerender'
case RenderStage.ShellRuntime:
case RenderStage.Runtime:
case RenderStage.PrefetchRuntime:
case RenderStage.NavigationRuntime:
return 'Prefetch'
case RenderStage.Dynamic:
......@@ -5514,7 +5514,7 @@ type StreamRevealStage =
| RenderStage.ShellStatic
| RenderStage.Static
| RenderStage.ShellRuntime
| RenderStage.Runtime
| RenderStage.PrefetchRuntime
function navigationHasRuntimeShell(navigationKind: DevNavigationKind): boolean {
switch (navigationKind.type) {
......@@ -5528,7 +5528,7 @@ function navigationHasRuntimeShell(navigationKind: DevNavigationKind): boolean {
return false
}
case RenderStage.ShellRuntime:
case RenderStage.Runtime: {
case RenderStage.PrefetchRuntime: {
return true
}
}
......@@ -5753,8 +5753,8 @@ async function streamStagedRenderInDev({
() => checkCacheMissAndAdvance(RenderStage.ShellRuntime),
() => checkReveal(RenderStage.ShellRuntime),
() => checkCacheMissAndAdvance(RenderStage.Runtime),
() => checkReveal(RenderStage.Runtime),
() => checkCacheMissAndAdvance(RenderStage.PrefetchRuntime),
() => checkReveal(RenderStage.PrefetchRuntime),
() => checkCacheMissAndAdvance(RenderStage.NavigationRuntime),
......@@ -5910,7 +5910,7 @@ async function renderWithWarmCachesForValidationInDev(
() => stageController.advanceStage(RenderStage.NavigationStatic),
() => stageController.advanceStage(RenderStage.Static),
() => stageController.advanceStage(RenderStage.ShellRuntime),
() => stageController.advanceStage(RenderStage.Runtime),
() => stageController.advanceStage(RenderStage.PrefetchRuntime),
() => stageController.advanceStage(RenderStage.NavigationRuntime),
() => stageController.advanceStage(RenderStage.Dynamic)
)
......@@ -5956,7 +5956,7 @@ async function prerenderWithWarmCachesForStaticValidationInDev(
const { clientModules } = getClientReferenceManifest()
// This render is for validation only, and won't be shown to the user,
// so we're only rendering until the runtime stage
// so we're only rendering until the PrefetchRuntime stage
// (we need static chunks and runtime chunks for discriminated errors)
const finalReactController = new AbortController()
const finalDataController = new AbortController()
......@@ -5967,7 +5967,7 @@ async function prerenderWithWarmCachesForStaticValidationInDev(
abortSignal: finalDataController.signal,
abandonController: null,
syncIO: getSyncIOMode(prefetchMode),
finalStage: RenderStage.Runtime,
finalStage: RenderStage.PrefetchRuntime,
})
const requestStore = createRequestStore()
......@@ -5985,7 +5985,7 @@ async function prerenderWithWarmCachesForStaticValidationInDev(
requestStore.headers
)
// We abort upon reaching the runtime stage or on Sync IO.
// We abort upon reaching the PrefetchRuntime stage or on Sync IO.
// If sync IO occurs in a place where it's not allowed, then we have to fail validation,
// and we can abort the render immediately, without waiting for anything else..
requestStore.controller = finalReactController
......@@ -6044,7 +6044,7 @@ async function prerenderWithWarmCachesForStaticValidationInDev(
() => stageController.advanceStage(RenderStage.NavigationStatic),
() => stageController.advanceStage(RenderStage.Static),
() => stageController.advanceStage(RenderStage.ShellRuntime),
() => stageController.advanceStage(RenderStage.Runtime),
() => stageController.advanceStage(RenderStage.PrefetchRuntime),
// NOTE: We don't need `NavigationRuntime`, because we set `needsRuntimeShell: false`
// so `navigation()` resolves in the static stages.
() => {
......@@ -6908,12 +6908,12 @@ async function runValidationInDev(
// interrupt the prerender and can properly observe the entire content
await warmupClientModulesForStagedValidation(
// if we're going to be validating prefetches, we'll be rendering some segments in the dynamic stage.
// otherwise, for static shell validation, we only need to warm up to the runtime stage.
// otherwise, for static shell validation, we only need to warm up to the PrefetchRuntime stage.
// we also need to use a different store type, because instant validation allows more APIs to resolve.
needsInstantValidation ? 'validation-client' : 'prerender-client',
needsInstantValidation
? accumulatedChunks[RenderStage.Dynamic]
: accumulatedChunks[RenderStage.Runtime],
: accumulatedChunks[RenderStage.PrefetchRuntime],
accumulatedChunks[RenderStage.Dynamic],
rootParams,
fallbackRouteParams,
......@@ -7068,7 +7068,7 @@ async function validateStaticShell(
)
const runtimeResult = await validateStaticShellAtStage(
RenderStage.Runtime,
RenderStage.PrefetchRuntime,
accumulatedChunks,
debugChunks,
stageEndTimes,
......@@ -7082,7 +7082,9 @@ async function validateStaticShell(
)
if (runtimeResult.length > 0) {
debug?.(`❌ Failed - ${runtimeResult.length} errors from runtime stage`)
debug?.(
`❌ Failed - ${runtimeResult.length} errors from PrefetchRuntime stage`
)
// We have something to report from the runtime validation
// We can skip the rest
return runtimeResult
......@@ -7295,7 +7297,7 @@ async function warmupClientModulesForStagedValidation(
}
async function validateStaticShellAtStage(
stage: RenderStage.Static | RenderStage.Runtime,
stage: RenderStage.Static | RenderStage.PrefetchRuntime,
accumulatedChunks: AccumulatedStreamChunks,
debugChunks: null | Array<Uint8Array>,
stageEndTimes: StageEndTimes,
......@@ -7518,8 +7520,8 @@ async function validateStaticShellAtStage(
/**
* Validates instant configs by iterating URL depths from deepest to
* shallowest. At each depth, builds a combined payload where segments
* above the boundary use Dynamic stage (already mounted) and segments
* below use Static/Runtime stage (being prefetched). If the new subtree
* above the boundary use the Dynamic stage (already mounted) and segments
* below use the stage that corresponds to what was prefetched. If the new subtree
* contains any `instant` configs, the payload is rendered to
* detect dynamic holes without Suspense.
*/
......@@ -7597,7 +7599,7 @@ async function validateInstantConfigs(
const { implicitTags, nonce, workStore, isDebugChannelEnabled } = ctx
type RetryStage = RenderStage.Runtime | RenderStage.NavigationRuntime
type RetryStage = RenderStage.PrefetchRuntime | RenderStage.NavigationRuntime
type ValidationSequence = {
stageOrder: [...PrefetchedSegmentStage[], RenderStage.Dynamic]
......@@ -7633,27 +7635,27 @@ async function validateInstantConfigs(
RenderStage.ShellStatic,
RenderStage.PrefetchStatic,
RenderStage.NavigationStatic,
RenderStage.Runtime,
RenderStage.PrefetchRuntime,
RenderStage.Dynamic,
],
holeResolution: {
[RenderStage.ShellStatic]: null, // initial stage
[RenderStage.PrefetchStatic]: DynamicHoleKind.Link, // TODO(ensure-static): distinguish static link data
[RenderStage.NavigationStatic]: DynamicHoleKind.Navigation,
[RenderStage.Runtime]: DynamicHoleKind.Runtime, // TODO(ensure-static): distinguish session data
[RenderStage.PrefetchRuntime]: DynamicHoleKind.Runtime, // TODO(ensure-static): distinguish session data
[RenderStage.Dynamic]: DynamicHoleKind.Dynamic,
},
}),
[ValidationPrefetchKind.RuntimeAppShell]: defineValidationSequence({
stageOrder: [
RenderStage.ShellRuntime,
RenderStage.Runtime,
RenderStage.PrefetchRuntime,
RenderStage.NavigationRuntime,
RenderStage.Dynamic,
],
holeResolution: {
[RenderStage.ShellRuntime]: null, // initial stage
[RenderStage.Runtime]: DynamicHoleKind.Link,
[RenderStage.PrefetchRuntime]: DynamicHoleKind.Link,
[RenderStage.NavigationRuntime]: DynamicHoleKind.Navigation,
[RenderStage.Dynamic]: DynamicHoleKind.Dynamic,
},
......@@ -7661,12 +7663,12 @@ async function validateInstantConfigs(
[ValidationPrefetchKind.LegacySpeculative]: defineValidationSequence({
stageOrder: [
RenderStage.Static,
RenderStage.Runtime,
RenderStage.PrefetchRuntime,
RenderStage.Dynamic,
],
holeResolution: {
[RenderStage.Static]: null, // initial stage
[RenderStage.Runtime]: DynamicHoleKind.Runtime,
[RenderStage.PrefetchRuntime]: DynamicHoleKind.Runtime,
[RenderStage.Dynamic]: DynamicHoleKind.Dynamic,
},
}),
......@@ -8206,7 +8208,7 @@ async function renderWithRestartOnCacheMissInValidation(
() => advanceStageIfNoCacheMiss(RenderStage.NavigationStatic),
() => advanceStageIfNoCacheMiss(RenderStage.Static),
() => advanceStageIfNoCacheMiss(RenderStage.ShellRuntime),
() => advanceStageIfNoCacheMiss(RenderStage.Runtime),
() => advanceStageIfNoCacheMiss(RenderStage.PrefetchRuntime),
() => advanceStageIfNoCacheMiss(RenderStage.NavigationRuntime),
() => advanceStageIfNoCacheMiss(RenderStage.Dynamic)
)
......@@ -8309,7 +8311,7 @@ async function renderWithRestartOnCacheMissInValidation(
() => finalStageController.advanceStage(RenderStage.NavigationStatic),
() => finalStageController.advanceStage(RenderStage.Static),
() => finalStageController.advanceStage(RenderStage.ShellRuntime),
() => finalStageController.advanceStage(RenderStage.Runtime),
() => finalStageController.advanceStage(RenderStage.PrefetchRuntime),
() => finalStageController.advanceStage(RenderStage.NavigationRuntime),
() => finalStageController.advanceStage(RenderStage.Dynamic)
)
......
......@@ -206,20 +206,20 @@ export async function collectStagedSegmentData(
RenderStage.ShellStatic,
RenderStage.PrefetchStatic,
RenderStage.NavigationStatic, // TODO(cache-stages): only if needed
RenderStage.Runtime,
RenderStage.PrefetchRuntime,
]
break
}
case ValidationPrefetchKind.RuntimeAppShell: {
partialStages = [
RenderStage.ShellRuntime,
RenderStage.Runtime,
RenderStage.PrefetchRuntime,
RenderStage.NavigationRuntime, // TODO(cache-stages): only if needed
]
break
}
case ValidationPrefetchKind.LegacySpeculative: {
partialStages = [RenderStage.Static, RenderStage.Runtime]
partialStages = [RenderStage.Static, RenderStage.PrefetchRuntime]
break
}
}
......@@ -293,7 +293,7 @@ async function collectSegmentDataForStage(
case RenderStage.NavigationStatic:
return 'Prerender'
case RenderStage.ShellRuntime: // TODO(app-shells) - proper environmentName
case RenderStage.Runtime:
case RenderStage.PrefetchRuntime:
case RenderStage.NavigationRuntime:
return 'Prefetch'
case RenderStage.Dynamic:
......@@ -479,7 +479,7 @@ function onFlightRenderError(error: unknown): string | undefined {
function createStagedStreamFromChunks(stageChunks: StageChunks) {
// The successive stages are supersets of one another,
// so we can index into the dynamic chunks everywhere
// and just look at the lengths of the Static/Runtime arrays
// and just look at the lengths of the partial stage arrays
const allChunks = stageChunks[RenderStage.Dynamic]
let chunkIx = 0
......@@ -986,7 +986,7 @@ export function discoverValidationDepths(loaderTree: LoaderTree): number[] {
* Walks the LoaderTree directly, loading modules and counting
* URL-contributing layouts. When `depth` URL segments have been
* consumed, the boundary flips from shared (dynamic stage) to new
* (static/runtime stage). As the new subtree is built, we check for
* (the prefetched stage). As the new subtree is built, we check for
* instant configs. If none are found, returns null — no validation
* needed at this depth or deeper.
*
......@@ -1024,7 +1024,7 @@ export async function createCombinedPayloadAtDepth(
clientReferenceManifest: ClientReferenceManifest,
overrideStageForPartialSegments:
| null
| RenderStage.Runtime
| RenderStage.PrefetchRuntime
| RenderStage.NavigationRuntime
): Promise<ValidationPayloadResult | null> {
const workStore = workAsyncStorage.getStore()
......
......@@ -10,7 +10,7 @@ export enum RenderStage {
Static = 13,
//
ShellRuntime = 20,
Runtime = 21,
PrefetchRuntime = 21,
NavigationRuntime = 22,
//
Dynamic = 30,
......@@ -29,7 +29,7 @@ export const RENDER_STAGE_ADVANCE_ORDER: AdvanceableRenderStage[] = [
RenderStage.Static,
//
RenderStage.ShellRuntime,
RenderStage.Runtime,
RenderStage.PrefetchRuntime,
RenderStage.NavigationRuntime,
//
RenderStage.Dynamic,
......
......@@ -747,7 +747,7 @@ class TrackedPromise<T> extends Promise<T> {
export const RENDER_STAGES_BY_DATA_KIND = {
sessionData: RenderStage.ShellRuntime as const,
staticLinkData: RenderStage.PrefetchStatic as const,
runtimeLinkData: RenderStage.Runtime as const,
runtimeLinkData: RenderStage.PrefetchRuntime as const,
}
export function applyOwnerStack(error: Error): Error {
......
......@@ -68,10 +68,10 @@ export function io(expression: string, type: SyncIOApiType) {
break
}
case RenderStage.ShellRuntime:
case RenderStage.Runtime:
case RenderStage.PrefetchRuntime:
case RenderStage.NavigationRuntime: {
// We're in the Runtime stage.
// We only error for Sync IO in the Runtime stage if the route has partialPrefetching enabled.
// We're in a runtime stage.
// We only error for Sync IO in runtime stages if the route has partialPrefetching enabled.
syncIOError = createSyncIORuntimeError(
workStore.route,
expression,
......
......@@ -433,7 +433,7 @@ function createRuntimePrerenderParams(
}
// Non-root params are URL data, and we need to recover a param-less session shell,
// so we delay all params until the runtime stage (even if they're static)
// so we delay all params until the PrefetchRuntime stage (even if they're static)
const paramsStage = RENDER_STAGES_BY_DATA_KIND.runtimeLinkData
const { stagedRendering } = workUnitStore
......
......@@ -54,7 +54,7 @@ export function createServerPathnameForMetadata(
// should depend on whether this route has params.
// if there's no params, it can be included.
// for now, we defensively exclude it to match the earlier pessimistic
// behavior of always resolving in the runtime stage
// behavior of always resolving in the PrefetchRuntime stage
// (i.e. assuming that we have non-static params in the pathname)
const { stagedRendering } = workUnitStore
const pathnameStage = RENDER_STAGES_BY_DATA_KIND.runtimeLinkData
......
......@@ -604,7 +604,7 @@ function makeUntrackedSearchParamsWithDevWarningsImpl(
promiseInitialized.current = true
},
// If we're in staged rendering, this promise will reject if the render
// is aborted before it can reach the runtime stage.
// is aborted before it can reach the PrefetchRuntime stage.
// In that case, we have to prevent an unhandled rejection from the promise
// created by this `.then()` call.
// This does not affect the `promiseInitialized` logic above,
......
......@@ -2134,7 +2134,7 @@ export async function cache(
switch (outerWorkUnitStore.type) {
case 'prerender-runtime': {
// In a runtime prerender, we have to make sure that APIs that would hang during a static prerender
// are resolved with a delay, in the appropriate runtime stage. Private caches resolve in EarlyRuntime,
// are resolved with a delay, in the appropriate runtime stage.
const stagedRendering = outerWorkUnitStore.stagedRendering
if (stagedRendering) {
await stagedRendering.waitForStage(
......
......@@ -201,7 +201,7 @@ export function runDevWarmupTests({
// Static
const STATIC_LINK_DATA = isInitialLoad
? 'Prerender'
: // If we're rendering an App Shell, static params are deferred until the runtime stage.
: // If we're rendering an App Shell, static params are deferred until the PrefetchRuntime stage.
partialPrefetching || hasRuntimePrefetch
? 'Prefetch'
: 'Prerender'
......
......@@ -51,7 +51,7 @@ describe('cache-indicator-partial-prefetching', () => {
const browser = await next.browser('/')
// Cold navigation: the cache read sits after `await params`, so it resolves
// in the runtime stage, part of the runtime shell for this navigation, so a
// in the PrefetchRuntime stage, part of the runtime shell for this navigation, so a
// cold cache there shows the badge.
await browser.elementByCss('a[href="/params/prefetch-auto"]').click()
await browser.elementById('params')
......@@ -69,7 +69,7 @@ describe('cache-indicator-partial-prefetching', () => {
const browser = await next.browser('/')
// Cold navigation: the cache read sits after `await params`, so it resolves
// in the runtime stage as part of the speculative prefetch shell for this navigation.
// in the PrefetchRuntime stage as part of the speculative prefetch shell for this navigation.
// a cold cache there shows the badge.
await browser.elementByCss('a[href="/params/prefetch-true"]').click()
await browser.elementById('params')
......
// A blocking route (`instant = false`) with a dynamic param and no
// `generateStaticParams`. The `'use cache'` read sits after `await params`, so
// it can only run once the param resolves, in the runtime stage.
// it can only run once the param resolves, in the PrefetchRuntime stage.
export const instant = false
async function getCachedValue() {
......
......@@ -369,7 +369,7 @@ describe('cached navigations', () => {
await page.clock.fastForward(60_000)
// Second navigation — fallback params are deferred to the runtime stage,
// Second navigation — fallback params are deferred to the PrefetchRuntime stage,
// so they should NOT be visible while the dynamic request is blocked
await act(async () => {
await act(
......
......@@ -36,7 +36,7 @@ async function ParamsContent({
params: Promise<{ slug: string }>
}) {
// When the param is a fallback param (not in generateStaticParams), the
// await is deferred to the runtime stage, so this content won't appear
// await is deferred to the PrefetchRuntime stage, so this content won't appear
// in the static stage.
const { slug } = await params
return <p>Param: {slug}</p>
......
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