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

Replace resumed render bailout error with ReactDOM.browser behind a flag (#96844)

Stacked on #96843.

This PR replaces the bailout error used to abort resumed renders with
`ReactDOM.browser()` behind the experimental flag.

### How?

Pass the flag to the App Router runtime, use `ReactDOM.browser()` as the
abort reason when enabled, and preserve existing behavior otherwise.

<!-- NEXT_JS_LLM -->
parent c11c48e4
......@@ -68,6 +68,7 @@ import {
createNodeInlinedDataStream,
} from './stream-ops'
import type { AnyStream } from './stream-ops'
import { createRenderInBrowserAbortSignal } from './render-in-browser'
import { getInstantTestBootstrapScriptContent } from './instant-test-bootstrap'
import { stripInternalQueries } from '../internal-utils'
import {
......@@ -180,7 +181,6 @@ import {
import { getStackWithoutErrorMessage } from '../../lib/format-server-error'
import {
accessedDynamicData,
createRenderInBrowserAbortSignal,
formatDynamicAPIAccesses,
isPrerenderInterruptedError,
createDynamicTrackingState,
......@@ -9581,7 +9581,9 @@ async function prerenderToStream(
/>,
JSON.parse(JSON.stringify(postponed)),
{
signal: createRenderInBrowserAbortSignal(),
signal: createRenderInBrowserAbortSignal(
ctx.renderOpts.experimental.reactBrowserBailout
),
onError: htmlRendererErrorHandler,
nonce,
}
......@@ -10120,7 +10122,9 @@ async function prerenderToStream(
/>,
JSON.parse(JSON.stringify(errorPostponed)),
{
signal: createRenderInBrowserAbortSignal(),
signal: createRenderInBrowserAbortSignal(
ctx.renderOpts.experimental.reactBrowserBailout
),
onError: htmlRendererErrorHandler,
nonce,
}
......
......@@ -46,7 +46,6 @@ import {
ROOT_LAYOUT_BOUNDARY_NAME,
} from '../../lib/framework/boundary-constants'
import { scheduleOnNextTick } from '../../lib/scheduler'
import { BailoutToCSRError } from '../../shared/lib/lazy-dynamic/bailout-to-csr'
import {
createRuntimeBodyError,
createDynamicBodyError,
......@@ -460,12 +459,6 @@ export function formatDynamicAPIAccesses(
})
}
export function createRenderInBrowserAbortSignal(): AbortSignal {
const controller = new AbortController()
controller.abort(new BailoutToCSRError('Render in Browser'))
return controller.signal
}
/**
* In a prerender, we may end up with hanging Promises as inputs due them
* stalling on connection() or because they're loading dynamic data. In that
......
import { browser } from 'react-dom'
import { BailoutToCSRError } from '../../shared/lib/lazy-dynamic/bailout-to-csr'
import { createReactBrowserBailoutReason } from '../../shared/lib/lazy-dynamic/react-browser-bailout'
const RENDER_IN_BROWSER_BAILOUT_REASON = 'Render in Browser'
const getRenderInBrowserBailoutReason = createReactBrowserBailoutReason.bind(
null,
RENDER_IN_BROWSER_BAILOUT_REASON
)
/**
* Aborting a resumed render with a recoverable reason tells React to leave the
* postponed boundary for the browser instead of reporting a render error.
*/
export function createRenderInBrowserAbortSignal(
reactBrowserBailout: boolean
): AbortSignal {
const controller = new AbortController()
if (reactBrowserBailout) {
// @ts-expect-error TODO: Update @types/react-dom to include the reason argument.
controller.abort(browser(getRenderInBrowserBailoutReason))
} else {
controller.abort(new BailoutToCSRError(RENDER_IN_BROWSER_BAILOUT_REASON))
}
return controller.signal
}
......@@ -712,7 +712,6 @@ async function readNormalizedNFT(next, name) {
"/node_modules/next/dist/shared/lib/invariant-error.js",
"/node_modules/next/dist/shared/lib/is-plain-object.js",
"/node_modules/next/dist/shared/lib/is-thenable.js",
"/node_modules/next/dist/shared/lib/lazy-dynamic/bailout-to-csr.js",
"/node_modules/next/dist/shared/lib/lazy-dynamic/react-browser-bailout.js",
"/node_modules/next/dist/shared/lib/no-fallback-error.external.js",
"/node_modules/next/dist/shared/lib/promise-with-resolvers.js",
......
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