Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions packages/next/src/server/app-render/app-render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,7 @@ async function generateDynamicFlightRenderResultWithStagesInDev(
dynamicChunks,
staticInterruptReason,
runtimeInterruptReason,
staticStageEndTime,
runtimeStageEndTime,
debugChannel: returnedDebugChannel,
requestStore: finalRequestStore,
Expand Down Expand Up @@ -855,6 +856,7 @@ async function generateDynamicFlightRenderResultWithStagesInDev(
dynamicChunks,
staticInterruptReason,
runtimeInterruptReason,
staticStageEndTime,
runtimeStageEndTime,
ctx,
clientReferenceManifest,
Expand Down Expand Up @@ -2582,6 +2584,7 @@ async function renderToStream(
dynamicChunks,
staticInterruptReason,
runtimeInterruptReason,
staticStageEndTime,
runtimeStageEndTime,
debugChannel: returnedDebugChannel,
requestStore: finalRequestStore,
Expand Down Expand Up @@ -2609,6 +2612,7 @@ async function renderToStream(
dynamicChunks,
staticInterruptReason,
runtimeInterruptReason,
staticStageEndTime,
runtimeStageEndTime,
ctx,
clientReferenceManifest,
Expand Down Expand Up @@ -3202,6 +3206,7 @@ async function renderWithRestartOnCacheMissInDev(
staticInterruptReason: initialStageController.getStaticInterruptReason(),
runtimeInterruptReason:
initialStageController.getRuntimeInterruptReason(),
staticStageEndTime: initialStageController.getStaticStageEndTime(),
runtimeStageEndTime: initialStageController.getRuntimeStageEndTime(),
debugChannel,
requestStore,
Expand Down Expand Up @@ -3319,7 +3324,8 @@ async function renderWithRestartOnCacheMissInDev(
dynamicChunks,
staticInterruptReason: finalStageController.getStaticInterruptReason(),
runtimeInterruptReason: finalStageController.getRuntimeInterruptReason(),
runtimeStageEndTime: initialStageController.getRuntimeStageEndTime(),
staticStageEndTime: finalStageController.getStaticStageEndTime(),
runtimeStageEndTime: finalStageController.getRuntimeStageEndTime(),
debugChannel,
requestStore,
}
Expand Down Expand Up @@ -3478,6 +3484,7 @@ async function spawnStaticShellValidationInDev(
dynamicServerChunks: Array<Uint8Array>,
staticInterruptReason: Error | null,
runtimeInterruptReason: Error | null,
staticStageEndTime: number,
runtimeStageEndTime: number,
ctx: AppRenderContext,
clientReferenceManifest: NonNullable<RenderOpts['clientReferenceManifest']>,
Expand Down Expand Up @@ -3557,17 +3564,11 @@ async function spawnStaticShellValidationInDev(
debugChannelClient.on('data', (c) => debugChunks.push(c))
}

// For both runtime and static validation we use the same end time which is
// when the runtime stage ended. This ensures that any I/O that is awaited
// (start of the await) in the dynamic stage won't be considered by React when
// constructing the owner stacks that we use for the validation errors.
const debugEndTime = runtimeStageEndTime

const runtimeResult = await validateStagedShell(
runtimeServerChunks,
dynamicServerChunks,
debugChunks,
debugEndTime,
runtimeStageEndTime,
rootParams,
fallbackRouteParams,
allowEmptyStaticShell,
Expand All @@ -3590,7 +3591,7 @@ async function spawnStaticShellValidationInDev(
staticServerChunks,
dynamicServerChunks,
debugChunks,
debugEndTime,
staticStageEndTime,
rootParams,
fallbackRouteParams,
allowEmptyStaticShell,
Expand Down
6 changes: 6 additions & 0 deletions packages/next/src/server/app-render/staged-rendering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class StagedRenderingController {
naturalStage: RenderStage = RenderStage.Static
staticInterruptReason: Error | null = null
runtimeInterruptReason: Error | null = null
staticStageEndTime: number = Infinity
runtimeStageEndTime: number = Infinity
/** Whether sync IO should interrupt the render */
enableSyncInterrupt = true
Expand Down Expand Up @@ -130,6 +131,10 @@ export class StagedRenderingController {
return this.runtimeInterruptReason
}

getStaticStageEndTime() {
return this.staticStageEndTime
}

getRuntimeStageEndTime() {
return this.runtimeStageEndTime
}
Expand Down Expand Up @@ -185,6 +190,7 @@ export class StagedRenderingController {
this.currentStage = stage

if (currentStage < RenderStage.Runtime && stage >= RenderStage.Runtime) {
this.staticStageEndTime = performance.now() + performance.timeOrigin
const runtimeListeners = this.runtimeStageListeners
for (let i = 0; i < runtimeListeners.length; i++) {
runtimeListeners[i]()
Expand Down