Unverified Commit ddc8807a authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

Fully enable custom error callbacks for app router (#71794)

parent af6f6aa9
...@@ -217,6 +217,12 @@ function Root({ children }: React.PropsWithChildren<{}>) { ...@@ -217,6 +217,12 @@ function Root({ children }: React.PropsWithChildren<{}>) {
return children return children
} }
const reactRootOptions = {
onRecoverableError,
onCaughtError,
onUncaughtError,
} satisfies ReactDOMClient.RootOptions
export function hydrate() { export function hydrate() {
const reactEl = ( const reactEl = (
<StrictModeIfEnabled> <StrictModeIfEnabled>
...@@ -231,19 +237,6 @@ export function hydrate() { ...@@ -231,19 +237,6 @@ export function hydrate() {
const rootLayoutMissingTags = window.__next_root_layout_missing_tags const rootLayoutMissingTags = window.__next_root_layout_missing_tags
const hasMissingTags = !!rootLayoutMissingTags?.length const hasMissingTags = !!rootLayoutMissingTags?.length
const errorCallbacks =
typeof (React as any).captureOwnerStack === 'function' &&
process.env.NODE_ENV !== 'production'
? {
onCaughtError,
onUncaughtError,
}
: undefined
const options = {
onRecoverableError,
...errorCallbacks,
} satisfies ReactDOMClient.RootOptions
const isError = const isError =
document.documentElement.id === '__next_error__' || hasMissingTags document.documentElement.id === '__next_error__' || hasMissingTags
...@@ -252,14 +245,18 @@ export function hydrate() { ...@@ -252,14 +245,18 @@ export function hydrate() {
const createDevOverlayElement = const createDevOverlayElement =
require('./components/react-dev-overlay/client-entry').createDevOverlayElement require('./components/react-dev-overlay/client-entry').createDevOverlayElement
const errorTree = createDevOverlayElement(reactEl) const errorTree = createDevOverlayElement(reactEl)
ReactDOMClient.createRoot(appElement as any, options).render(errorTree) ReactDOMClient.createRoot(appElement as any, reactRootOptions).render(
errorTree
)
} else { } else {
ReactDOMClient.createRoot(appElement as any, options).render(reactEl) ReactDOMClient.createRoot(appElement as any, reactRootOptions).render(
reactEl
)
} }
} else { } else {
React.startTransition(() => React.startTransition(() =>
(ReactDOMClient as any).hydrateRoot(appElement, reactEl, { (ReactDOMClient as any).hydrateRoot(appElement, reactEl, {
...options, ...reactRootOptions,
formState: initialFormStateData, formState: initialFormStateData,
}) })
) )
......
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