Commit df76b85a authored by Hendrik Liebau's avatar Hendrik Liebau Committed by Josh Story

Use runtime stage end time to ignore I/O debug info from dynamic stage

This ensures that any I/O awaited during the dynamic stage (i.e. after
other uncached I/O resolved) does not contaminate the owner stacks used
for error reporting.
parent 54188831
......@@ -214,7 +214,6 @@ if (clientResumeFetch) {
callServer,
findSourceMapURL,
debugChannel,
// @ts-expect-error This is not yet part of the React types
startTime: 0,
}
)
......
......@@ -15,6 +15,7 @@ export class StagedRenderingController {
naturalStage: RenderStage = RenderStage.Static
staticInterruptReason: Error | null = null
runtimeInterruptReason: Error | null = null
runtimeStageEndTime: number = Infinity
/** Whether sync IO should interrupt the render */
enableSyncInterrupt = true
......@@ -129,6 +130,10 @@ export class StagedRenderingController {
return this.runtimeInterruptReason
}
getRuntimeStageEndTime() {
return this.runtimeStageEndTime
}
abandonRender() {
if (!this.mayAbandon) {
throw new InvariantError(
......@@ -188,6 +193,7 @@ export class StagedRenderingController {
this.runtimeStagePromise.resolve()
}
if (currentStage < RenderStage.Dynamic && stage >= RenderStage.Dynamic) {
this.runtimeStageEndTime = performance.now() + performance.timeOrigin
const dynamicListeners = this.dynamicStageListeners
for (let i = 0; i < dynamicListeners.length; i++) {
dynamicListeners[i]()
......
......@@ -33,6 +33,7 @@ const findSourceMapURL =
export function getFlightStream<T>(
flightStream: Readable | BinaryStreamOf<T>,
debugStream: Readable | ReadableStream<Uint8Array> | undefined,
debugEndTime: number | undefined,
clientReferenceManifest: DeepReadonly<ClientReferenceManifest>,
nonce: string | undefined
): Promise<T> {
......@@ -65,6 +66,7 @@ export function getFlightStream<T>(
},
nonce,
debugChannel: debugStream ? { readable: debugStream } : undefined,
endTime: debugEndTime,
})
} else {
// The types of flightStream and debugStream should match.
......@@ -90,6 +92,7 @@ export function getFlightStream<T>(
findSourceMapURL,
nonce,
debugChannel: debugStream,
endTime: debugEndTime,
}
)
}
......
......@@ -115,6 +115,8 @@ declare module 'react-server-dom-webpack/client.browser' {
replayConsoleLogs?: boolean
temporaryReferences?: TemporaryReferenceSet
debugChannel?: { readable?: ReadableStream; writable?: WritableStream }
startTime?: number
endTime?: number
}
export function createFromFetch<T>(
......@@ -318,6 +320,8 @@ declare module 'react-server-dom-webpack/client.edge' {
replayConsoleLogs?: boolean
environmentName?: string
debugChannel?: { readable?: ReadableStream }
startTime?: number
endTime?: number
}
export type EncodeFormActionCallback = <A>(
......
import { Suspense } from 'react'
import { IndirectionOne, IndirectionTwo } from './indirection'
import { cookies } from 'next/headers'
export default async function Page() {
return (
......@@ -56,8 +57,15 @@ const fetchRandomCached = async (entropy: string) => {
}
const fetchRandom = async (entropy: string) => {
// Hide uncached I/O behind a runtime API call, to ensure we still get the
// correct owner stack for the error.
await cookies()
const response = await fetch(
'https://next-data-api-endpoint.vercel.app/api/random?b=' + entropy
)
// The error should point at the fetch above, and not at the following fetch.
await fetch(
'https://next-data-api-endpoint.vercel.app/api/random?b=' + entropy + 'x'
)
return response.text()
}
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