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

Use a Wrapper Error for onRecoverableError with a "cause" Field for the real Error #28736

Merged
merged 7 commits into from
Apr 4, 2024
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
170 changes: 97 additions & 73 deletions packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,9 @@ describe('ReactDOMFizzShellHydration', () => {
},
onRecoverableError(error) {
Scheduler.log('onRecoverableError: ' + error.message);
if (error.cause) {
Scheduler.log('Cause: ' + error.cause.message);
}
},
});
});
Expand Down Expand Up @@ -462,6 +465,9 @@ describe('ReactDOMFizzShellHydration', () => {
},
onRecoverableError(error) {
Scheduler.log('onRecoverableError: ' + error.message);
if (error.cause) {
Scheduler.log('Cause: ' + error.cause.message);
}
},
});
});
Expand Down Expand Up @@ -529,13 +535,16 @@ describe('ReactDOMFizzShellHydration', () => {
},
onRecoverableError(error) {
Scheduler.log('onRecoverableError: ' + error.message);
if (error.cause) {
Scheduler.log('Cause: ' + error.cause.message);
}
},
});
});

assertLog([
'onRecoverableError: plain error',
'onRecoverableError: There was an error while hydrating. Because the error happened outside of a Suspense boundary, the entire root will switch to client rendering.',
'onRecoverableError: There was an error while hydrating but React was able to recover by instead client rendering the entire root.',
'Cause: plain error',
]);
expect(container.textContent).toBe('Hello world');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,10 @@ describe('ReactDOMFizzServerHydrationWarning', () => {
ReactDOMClient.hydrateRoot(container, <App isClient={true} />, {
onRecoverableError(error) {
// Don't miss a hydration error. There should be none.
Scheduler.log(normalizeError(error.message));
Scheduler.log('onRecoverableError: ' + normalizeError(error.message));
if (error.cause) {
Scheduler.log('Cause: ' + normalizeError(error.cause.message));
}
},
});
await waitForAll([]);
Expand Down Expand Up @@ -205,7 +208,10 @@ describe('ReactDOMFizzServerHydrationWarning', () => {
);
ReactDOMClient.hydrateRoot(container, <App isClient={true} />, {
onRecoverableError(error) {
Scheduler.log(normalizeError(error.message));
Scheduler.log('onRecoverableError: ' + normalizeError(error.message));
if (error.cause) {
Scheduler.log('Cause: ' + normalizeError(error.cause.message));
}
},
});
await waitForAll([]);
Expand Down Expand Up @@ -246,12 +252,14 @@ describe('ReactDOMFizzServerHydrationWarning', () => {
);
ReactDOMClient.hydrateRoot(container, <App isClient={true} />, {
onRecoverableError(error) {
Scheduler.log(normalizeError(error.message));
Scheduler.log('onRecoverableError: ' + normalizeError(error.message));
if (error.cause) {
Scheduler.log('Cause: ' + normalizeError(error.cause.message));
}
},
});
await waitForAll([
"Hydration failed because the server rendered HTML didn't match the client.",
'There was an error while hydrating.',
"onRecoverableError: Hydration failed because the server rendered HTML didn't match the client.",
]);
expect(getVisibleChildren(container)).toEqual(
<div>
Expand Down Expand Up @@ -283,7 +291,10 @@ describe('ReactDOMFizzServerHydrationWarning', () => {
);
const root = ReactDOMClient.hydrateRoot(container, <App text="Client" />, {
onRecoverableError(error) {
Scheduler.log(normalizeError(error.message));
Scheduler.log('onRecoverableError: ' + normalizeError(error.message));
if (error.cause) {
Scheduler.log('Cause: ' + normalizeError(error.cause.message));
}
},
});
await waitForAll([]);
Expand Down Expand Up @@ -327,12 +338,14 @@ describe('ReactDOMFizzServerHydrationWarning', () => {
);
ReactDOMClient.hydrateRoot(container, <App isClient={true} />, {
onRecoverableError(error) {
Scheduler.log(normalizeError(error.message));
Scheduler.log('onRecoverableError: ' + normalizeError(error.message));
if (error.cause) {
Scheduler.log('Cause: ' + normalizeError(error.cause.message));
}
},
});
await waitForAll([
"Hydration failed because the server rendered HTML didn't match the client.",
'There was an error while hydrating.',
"onRecoverableError: Hydration failed because the server rendered HTML didn't match the client.",
]);
expect(getVisibleChildren(container)).toEqual(
<div>
Expand Down Expand Up @@ -367,12 +380,14 @@ describe('ReactDOMFizzServerHydrationWarning', () => {
);
ReactDOMClient.hydrateRoot(container, <App isClient={true} />, {
onRecoverableError(error) {
Scheduler.log(normalizeError(error.message));
Scheduler.log('onRecoverableError: ' + normalizeError(error.message));
if (error.cause) {
Scheduler.log('Cause: ' + normalizeError(error.cause.message));
}
},
});
await waitForAll([
"Hydration failed because the server rendered HTML didn't match the client.",
'There was an error while hydrating.',
"onRecoverableError: Hydration failed because the server rendered HTML didn't match the client.",
]);
expect(getVisibleChildren(container)).toEqual(
<div>
Expand Down Expand Up @@ -410,12 +425,14 @@ describe('ReactDOMFizzServerHydrationWarning', () => {
);
ReactDOMClient.hydrateRoot(container, <App isClient={true} />, {
onRecoverableError(error) {
Scheduler.log(normalizeError(error.message));
Scheduler.log('onRecoverableError: ' + normalizeError(error.message));
if (error.cause) {
Scheduler.log('Cause: ' + normalizeError(error.cause.message));
}
},
});
await waitForAll([
"Hydration failed because the server rendered HTML didn't match the client.",
'There was an error while hydrating.',
"onRecoverableError: Hydration failed because the server rendered HTML didn't match the client.",
]);
expect(getVisibleChildren(container)).toEqual(
<div>
Expand Down Expand Up @@ -451,12 +468,14 @@ describe('ReactDOMFizzServerHydrationWarning', () => {
);
ReactDOMClient.hydrateRoot(container, <App isClient={true} />, {
onRecoverableError(error) {
Scheduler.log(normalizeError(error.message));
Scheduler.log('onRecoverableError: ' + normalizeError(error.message));
if (error.cause) {
Scheduler.log('Cause: ' + normalizeError(error.cause.message));
}
},
});
await waitForAll([
"Hydration failed because the server rendered HTML didn't match the client.",
'There was an error while hydrating.',
"onRecoverableError: Hydration failed because the server rendered HTML didn't match the client.",
]);
expect(getVisibleChildren(container)).toEqual(
<div>
Expand Down Expand Up @@ -496,7 +515,10 @@ describe('ReactDOMFizzServerHydrationWarning', () => {
);
ReactDOMClient.hydrateRoot(container, <App isClient={true} />, {
onRecoverableError(error) {
Scheduler.log(normalizeError(error.message));
Scheduler.log('onRecoverableError: ' + normalizeError(error.message));
if (error.cause) {
Scheduler.log('Cause: ' + normalizeError(error.cause.message));
}
},
});
await waitForAll([]);
Expand Down Expand Up @@ -533,7 +555,10 @@ describe('ReactDOMFizzServerHydrationWarning', () => {
);
ReactDOMClient.hydrateRoot(container, <App isClient={true} />, {
onRecoverableError(error) {
Scheduler.log(normalizeError(error.message));
Scheduler.log('onRecoverableError: ' + normalizeError(error.message));
if (error.cause) {
Scheduler.log('Cause: ' + normalizeError(error.cause.message));
}
},
});
await waitForAll([]);
Expand Down Expand Up @@ -566,12 +591,14 @@ describe('ReactDOMFizzServerHydrationWarning', () => {
);
ReactDOMClient.hydrateRoot(container, <App isClient={true} />, {
onRecoverableError(error) {
Scheduler.log(normalizeError(error.message));
Scheduler.log('onRecoverableError: ' + normalizeError(error.message));
if (error.cause) {
Scheduler.log('Cause: ' + normalizeError(error.cause.message));
}
},
});
await waitForAll([
"Hydration failed because the server rendered HTML didn't match the client.",
'There was an error while hydrating.',
"onRecoverableError: Hydration failed because the server rendered HTML didn't match the client.",
]);
expect(getVisibleChildren(container)).toEqual(
<div>
Expand Down Expand Up @@ -604,12 +631,14 @@ describe('ReactDOMFizzServerHydrationWarning', () => {
);
ReactDOMClient.hydrateRoot(container, <App isClient={true} />, {
onRecoverableError(error) {
Scheduler.log(normalizeError(error.message));
Scheduler.log('onRecoverableError: ' + normalizeError(error.message));
if (error.cause) {
Scheduler.log('Cause: ' + normalizeError(error.cause.message));
}
},
});
await waitForAll([
"Hydration failed because the server rendered HTML didn't match the client.",
'There was an error while hydrating.',
"onRecoverableError: Hydration failed because the server rendered HTML didn't match the client.",
]);
expect(getVisibleChildren(container)).toEqual(
<div>
Expand Down
Loading