Skip to content
Merged
Show file tree
Hide file tree
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
27 changes: 27 additions & 0 deletions types/react-dom/canary.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,35 @@ declare module "./client" {
[REACT_FORM_STATE_SIGIL]: never;
}

interface RootOptions {
onUncaughtError?:
| ((error: unknown, errorInfo: { componentStack?: string | undefined }) => void)
| undefined;
onCaughtError?:
| ((
error: unknown,
errorInfo: {
componentStack?: string | undefined;
errorBoundary?: React.Component<unknown> | undefined;
},
) => void)
| undefined;
}

interface HydrationOptions {
formState?: ReactFormState | null;
onUncaughtError?:
| ((error: unknown, errorInfo: { componentStack?: string | undefined }) => void)
| undefined;
onCaughtError?:
| ((
error: unknown,
errorInfo: {
componentStack?: string | undefined;
errorBoundary?: React.Component<unknown> | undefined;
},
) => void)
| undefined;
}

interface DO_NOT_USE_OR_YOU_WILL_BE_FIRED_EXPERIMENTAL_CREATE_ROOT_CONTAINERS {
Expand Down
46 changes: 46 additions & 0 deletions types/react-dom/test/canary-tests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -265,4 +265,50 @@ function formTest() {
function createRoot(validContainer: Element | DocumentFragment | Document) {
ReactDOMClient.createRoot(document);
ReactDOMClient.createRoot(validContainer);

ReactDOMClient.createRoot(document, {
onUncaughtError: (error, errorInfo) => {
// $ExpectType unknown
error;
// $ExpectType string | undefined
errorInfo.componentStack;
// @ts-expect-error -- only on onRecoverableError
errorInfo.digest;
// @ts-expect-error -- only on onCaughtError
errorInfo.errorBoundary;
},
onCaughtError: (error, errorInfo) => {
// $ExpectType unknown
error;
// $ExpectType string | undefined
errorInfo.componentStack;
// @ts-expect-error -- only on onRecoverableError
errorInfo.digest;
// $ExpectType Component<unknown, {}, any> | undefined
errorInfo.errorBoundary;
},
});

ReactDOMClient.hydrateRoot(document.body, null, {
onUncaughtError: (error, errorInfo) => {
// $ExpectType unknown
error;
// $ExpectType string | undefined
errorInfo.componentStack;
// @ts-expect-error -- only on onRecoverableError
errorInfo.digest;
// @ts-expect-error -- only on onCaughtError
errorInfo.errorBoundary;
},
onCaughtError: (error, errorInfo) => {
// $ExpectType unknown
error;
// $ExpectType string | undefined
errorInfo.componentStack;
// @ts-expect-error -- only on onRecoverableError
errorInfo.digest;
// $ExpectType Component<unknown, {}, any> | undefined
errorInfo.errorBoundary;
},
});
}