Skip to content

Commit d8bb04e

Browse files
author
Sebastian Silbermann
committed
New warnings are from enableClientRenderFallbackOnTextMismatch
1 parent ab6a13e commit d8bb04e

File tree

1 file changed

+34
-15
lines changed

1 file changed

+34
-15
lines changed

packages/react-dom/src/__tests__/ReactServerRenderingHydration-test.js

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ describe('ReactDOMServerHydration', () => {
123123
// Now simulate a situation where the app is not idempotent. React should
124124
// warn but do the right thing.
125125
element.innerHTML = lastMarkup;
126+
const enableClientRenderFallbackOnTextMismatch = gate(
127+
flags => flags.enableClientRenderFallbackOnTextMismatch,
128+
);
126129
await expect(async () => {
127130
root = await act(() => {
128131
return ReactDOMClient.hydrateRoot(
@@ -139,11 +142,13 @@ describe('ReactDOMServerHydration', () => {
139142
);
140143
});
141144
}).toErrorDev(
142-
[
143-
'Text content did not match. Server: "x" Client: "y"',
144-
'An error occurred during hydration. The server HTML was replaced with client content in <div>.',
145-
],
146-
{withoutStack: 1},
145+
enableClientRenderFallbackOnTextMismatch
146+
? [
147+
'An error occurred during hydration. The server HTML was replaced with client content in <div>.',
148+
'Text content did not match. Server: "x" Client: "y"',
149+
]
150+
: ['Text content did not match. Server: "x" Client: "y"'],
151+
{withoutStack: enableClientRenderFallbackOnTextMismatch ? 1 : 0},
147152
);
148153
expect(mountCount).toEqual(4);
149154
expect(element.innerHTML.length > 0).toBe(true);
@@ -213,6 +218,9 @@ describe('ReactDOMServerHydration', () => {
213218
const onFocusAfterHydration = jest.fn();
214219
element.firstChild.focus = onFocusBeforeHydration;
215220

221+
const enableClientRenderFallbackOnTextMismatch = gate(
222+
flags => flags.enableClientRenderFallbackOnTextMismatch,
223+
);
216224
await expect(async () => {
217225
await act(() => {
218226
ReactDOMClient.hydrateRoot(
@@ -224,11 +232,15 @@ describe('ReactDOMServerHydration', () => {
224232
);
225233
});
226234
}).toErrorDev(
227-
[
228-
'An error occurred during hydration. The server HTML was replaced with client content in <div>.',
229-
'Warning: Text content did not match. Server: "server" Client: "client"',
230-
],
231-
{withoutStack: 1},
235+
enableClientRenderFallbackOnTextMismatch
236+
? [
237+
'An error occurred during hydration. The server HTML was replaced with client content in <div>.',
238+
'Warning: Text content did not match. Server: "server" Client: "client"',
239+
]
240+
: [
241+
'Warning: Text content did not match. Server: "server" Client: "client"',
242+
],
243+
{withoutStack: enableClientRenderFallbackOnTextMismatch ? 1 : 0},
232244
);
233245

234246
expect(onFocusBeforeHydration).not.toHaveBeenCalled();
@@ -583,6 +595,9 @@ describe('ReactDOMServerHydration', () => {
583595
);
584596
domElement.innerHTML = markup;
585597

598+
const enableClientRenderFallbackOnTextMismatch = gate(
599+
flags => flags.enableClientRenderFallbackOnTextMismatch,
600+
);
586601
await expect(async () => {
587602
await act(() => {
588603
ReactDOMClient.hydrateRoot(
@@ -596,11 +611,15 @@ describe('ReactDOMServerHydration', () => {
596611

597612
expect(domElement.innerHTML).not.toEqual(markup);
598613
}).toErrorDev(
599-
[
600-
'An error occurred during hydration. The server HTML was replaced with client content in <div>.',
601-
'Warning: Text content did not match. Server: "server" Client: "client"',
602-
],
603-
{withoutStack: 1},
614+
enableClientRenderFallbackOnTextMismatch
615+
? [
616+
'An error occurred during hydration. The server HTML was replaced with client content in <div>.',
617+
'Warning: Text content did not match. Server: "server" Client: "client"',
618+
]
619+
: [
620+
'Warning: Text content did not match. Server: "server" Client: "client"',
621+
],
622+
{withoutStack: enableClientRenderFallbackOnTextMismatch ? 1 : 0},
604623
);
605624
});
606625

0 commit comments

Comments
 (0)