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