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 { ...@@ -68,6 +68,7 @@ import {
createNodeInlinedDataStream, createNodeInlinedDataStream,
} from './stream-ops' } from './stream-ops'
import type { AnyStream } from './stream-ops' import type { AnyStream } from './stream-ops'
import { createRenderInBrowserAbortSignal } from './render-in-browser'
import { getInstantTestBootstrapScriptContent } from './instant-test-bootstrap' import { getInstantTestBootstrapScriptContent } from './instant-test-bootstrap'
import { stripInternalQueries } from '../internal-utils' import { stripInternalQueries } from '../internal-utils'
import { import {
...@@ -180,7 +181,6 @@ import { ...@@ -180,7 +181,6 @@ import {
import { getStackWithoutErrorMessage } from '../../lib/format-server-error' import { getStackWithoutErrorMessage } from '../../lib/format-server-error'
import { import {
accessedDynamicData, accessedDynamicData,
createRenderInBrowserAbortSignal,
formatDynamicAPIAccesses, formatDynamicAPIAccesses,
isPrerenderInterruptedError, isPrerenderInterruptedError,
createDynamicTrackingState, createDynamicTrackingState,
...@@ -9581,7 +9581,9 @@ async function prerenderToStream( ...@@ -9581,7 +9581,9 @@ async function prerenderToStream(
/>, />,
JSON.parse(JSON.stringify(postponed)), JSON.parse(JSON.stringify(postponed)),
{ {
signal: createRenderInBrowserAbortSignal(), signal: createRenderInBrowserAbortSignal(
ctx.renderOpts.experimental.reactBrowserBailout
),
onError: htmlRendererErrorHandler, onError: htmlRendererErrorHandler,
nonce, nonce,
} }
...@@ -10120,7 +10122,9 @@ async function prerenderToStream( ...@@ -10120,7 +10122,9 @@ async function prerenderToStream(
/>, />,
JSON.parse(JSON.stringify(errorPostponed)), JSON.parse(JSON.stringify(errorPostponed)),
{ {
signal: createRenderInBrowserAbortSignal(), signal: createRenderInBrowserAbortSignal(
ctx.renderOpts.experimental.reactBrowserBailout
),
onError: htmlRendererErrorHandler, onError: htmlRendererErrorHandler,
nonce, nonce,
} }
......
...@@ -46,7 +46,6 @@ import { ...@@ -46,7 +46,6 @@ import {
ROOT_LAYOUT_BOUNDARY_NAME, ROOT_LAYOUT_BOUNDARY_NAME,
} from '../../lib/framework/boundary-constants' } from '../../lib/framework/boundary-constants'
import { scheduleOnNextTick } from '../../lib/scheduler' import { scheduleOnNextTick } from '../../lib/scheduler'
import { BailoutToCSRError } from '../../shared/lib/lazy-dynamic/bailout-to-csr'
import { import {
createRuntimeBodyError, createRuntimeBodyError,
createDynamicBodyError, createDynamicBodyError,
...@@ -460,12 +459,6 @@ export function formatDynamicAPIAccesses( ...@@ -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 * 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 * 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) { ...@@ -712,7 +712,6 @@ async function readNormalizedNFT(next, name) {
"/node_modules/next/dist/shared/lib/invariant-error.js", "/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-plain-object.js",
"/node_modules/next/dist/shared/lib/is-thenable.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/lazy-dynamic/react-browser-bailout.js",
"/node_modules/next/dist/shared/lib/no-fallback-error.external.js", "/node_modules/next/dist/shared/lib/no-fallback-error.external.js",
"/node_modules/next/dist/shared/lib/promise-with-resolvers.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