Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 3 additions & 3 deletions packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4664,7 +4664,7 @@ describe('ReactDOMFizzServer', () => {
// client-side rendering.
await clientResolve();
await waitForAll([
"onRecoverableError: Hydration failed because the server rendered HTML didn't match the client.",
"onRecoverableError: Hydration failed because the server rendered text didn't match the client.",
]);
expect(getVisibleChildren(container)).toEqual(
<div>
Expand Down Expand Up @@ -4712,7 +4712,7 @@ describe('ReactDOMFizzServer', () => {
},
});
await waitForAll([
"onRecoverableError: Hydration failed because the server rendered HTML didn't match the client.",
"onRecoverableError: Hydration failed because the server rendered text didn't match the client.",
]);

expect(getVisibleChildren(container)).toEqual(
Expand Down Expand Up @@ -10179,7 +10179,7 @@ describe('ReactDOMFizzServer', () => {
);
expect(recoverableErrors).toEqual([
expect.stringContaining(
"Hydration failed because the server rendered HTML didn't match the client.",
"Hydration failed because the server rendered text didn't match the client.",
),
]);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ describe('ReactDOMServerHydration', () => {
if (gate(flags => flags.favorSafetyOverHydrationPerf)) {
expect(testMismatch(Mismatch)).toMatchInlineSnapshot(`
[
"Caught [Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:
"Caught [Hydration failed because the server rendered text didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:

- A server/client branch \`if (typeof window !== 'undefined')\`.
- Variable input such as \`Date.now()\` or \`Math.random()\` which changes each time it's called.
Expand Down Expand Up @@ -196,7 +196,7 @@ describe('ReactDOMServerHydration', () => {
if (gate(flags => flags.favorSafetyOverHydrationPerf)) {
expect(testMismatch(Mismatch)).toMatchInlineSnapshot(`
[
"Caught [Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:
"Caught [Hydration failed because the server rendered text didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:

- A server/client branch \`if (typeof window !== 'undefined')\`.
- Variable input such as \`Date.now()\` or \`Math.random()\` which changes each time it's called.
Expand Down Expand Up @@ -743,7 +743,7 @@ describe('ReactDOMServerHydration', () => {
if (gate(flags => flags.favorSafetyOverHydrationPerf)) {
expect(testMismatch(Mismatch)).toMatchInlineSnapshot(`
[
"Caught [Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:
"Caught [Hydration failed because the server rendered text didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:

- A server/client branch \`if (typeof window !== 'undefined')\`.
- Variable input such as \`Date.now()\` or \`Math.random()\` which changes each time it's called.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3897,7 +3897,7 @@ describe('ReactDOMServerPartialHydration', () => {
});
});
assertLog([
"onRecoverableError: Hydration failed because the server rendered HTML didn't match the client.",
"onRecoverableError: Hydration failed because the server rendered text didn't match the client.",
]);
});

Expand Down Expand Up @@ -3936,7 +3936,7 @@ describe('ReactDOMServerPartialHydration', () => {
);
});
assertLog([
"onRecoverableError: Hydration failed because the server rendered HTML didn't match the client.",
"onRecoverableError: Hydration failed because the server rendered text didn't match the client.",
]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ describe('rendering React components at document', () => {
assertLog(
favorSafetyOverHydrationPerf
? [
"onRecoverableError: Hydration failed because the server rendered HTML didn't match the client.",
"onRecoverableError: Hydration failed because the server rendered text didn't match the client.",
]
: [],
);
Expand Down
9 changes: 5 additions & 4 deletions packages/react-reconciler/src/ReactFiberHydrationContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ export const HydrationMismatchException: mixed = new Error(
"userspace. If you're seeing this, it's likely a bug in React.",
);

function throwOnHydrationMismatch(fiber: Fiber) {
function throwOnHydrationMismatch(fiber: Fiber, fromText = false) {
let diff = '';
if (__DEV__) {
// Consume the diff root for this mismatch.
Expand All @@ -320,7 +320,8 @@ function throwOnHydrationMismatch(fiber: Fiber) {
}
}
const error = new Error(
"Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:\n" +
`Hydration failed because the server rendered ${fromText ? 'text' : 'HTML'} didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:
` +
'\n' +
"- A server/client branch `if (typeof window !== 'undefined')`.\n" +
"- Variable input such as `Date.now()` or `Math.random()` which changes each time it's called.\n" +
Expand Down Expand Up @@ -481,7 +482,7 @@ function prepareToHydrateHostInstance(
fiber,
);
if (!didHydrate && favorSafetyOverHydrationPerf) {
throwOnHydrationMismatch(fiber);
throwOnHydrationMismatch(fiber, true);
}
}

Expand Down Expand Up @@ -547,7 +548,7 @@ function prepareToHydrateHostTextInstance(fiber: Fiber): void {
parentProps,
);
if (!didHydrate && favorSafetyOverHydrationPerf) {
throwOnHydrationMismatch(fiber);
throwOnHydrationMismatch(fiber, true);
}
}

Expand Down
Loading