Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fully enable custom error callbacks for app router #71794

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 13 additions & 16 deletions packages/next/src/client/app-index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@ function Root({ children }: React.PropsWithChildren<{}>) {
return children
}

const reactRootOptions = {
onRecoverableError,
onCaughtError,
onUncaughtError,
} satisfies ReactDOMClient.RootOptions

export function hydrate() {
const reactEl = (
<StrictModeIfEnabled>
Expand All @@ -231,19 +237,6 @@ export function hydrate() {
const rootLayoutMissingTags = window.__next_root_layout_missing_tags
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 =
document.documentElement.id === '__next_error__' || hasMissingTags

Expand All @@ -252,14 +245,18 @@ export function hydrate() {
const createDevOverlayElement =
require('./components/react-dev-overlay/client-entry').createDevOverlayElement
const errorTree = createDevOverlayElement(reactEl)
ReactDOMClient.createRoot(appElement as any, options).render(errorTree)
ReactDOMClient.createRoot(appElement as any, reactRootOptions).render(
errorTree
)
} else {
ReactDOMClient.createRoot(appElement as any, options).render(reactEl)
ReactDOMClient.createRoot(appElement as any, reactRootOptions).render(
reactEl
)
}
} else {
React.startTransition(() =>
(ReactDOMClient as any).hydrateRoot(appElement, reactEl, {
...options,
...reactRootOptions,
formState: initialFormStateData,
})
)
Expand Down
Loading