@@ -130,6 +130,7 @@ describe('ReactDOMFizzServerHydrationWarning', () => {
130
130
: children;
131
131
}
132
132
133
+ // @gate enableClientRenderFallbackOnTextMismatch
133
134
it('suppresses but does not fix text mismatches with suppressHydrationWarning', async () => {
134
135
function App({isClient}) {
135
136
return (
@@ -169,6 +170,47 @@ describe('ReactDOMFizzServerHydrationWarning', () => {
169
170
);
170
171
});
171
172
173
+ // @gate !enableClientRenderFallbackOnTextMismatch
174
+ it('suppresses and fixes text mismatches with suppressHydrationWarning', async () => {
175
+ function App({isClient}) {
176
+ return (
177
+ <div>
178
+ <span suppressHydrationWarning={true}>
179
+ {isClient ? 'Client Text' : 'Server Text'}
180
+ </span>
181
+ <span suppressHydrationWarning={true}>{isClient ? 2 : 1}</span>
182
+ </div>
183
+ );
184
+ }
185
+ await act(() => {
186
+ const {pipe} = ReactDOMFizzServer.renderToPipeableStream(
187
+ <App isClient={false} />,
188
+ );
189
+ pipe(writable);
190
+ });
191
+ expect(getVisibleChildren(container)).toEqual(
192
+ <div>
193
+ <span>Server Text</span>
194
+ <span>1</span>
195
+ </div>,
196
+ );
197
+ ReactDOMClient.hydrateRoot(container, <App isClient={true} />, {
198
+ onRecoverableError(error) {
199
+ // Don't miss a hydration error. There should be none.
200
+ Scheduler.log(error.message);
201
+ },
202
+ });
203
+ await waitForAll([]);
204
+ // The text mismatch should be *silently* fixed. Even in production.
205
+ expect(getVisibleChildren(container)).toEqual(
206
+ <div>
207
+ <span>Client Text</span>
208
+ <span>2</span>
209
+ </div>,
210
+ );
211
+ });
212
+
213
+ // @gate enableClientRenderFallbackOnTextMismatch
172
214
it('suppresses but does not fix multiple text node mismatches with suppressHydrationWarning', async () => {
173
215
function App({isClient}) {
174
216
return (
@@ -210,6 +252,48 @@ describe('ReactDOMFizzServerHydrationWarning', () => {
210
252
);
211
253
});
212
254
255
+ // @gate !enableClientRenderFallbackOnTextMismatch
256
+ it('suppresses and fixes multiple text node mismatches with suppressHydrationWarning', async () => {
257
+ function App({isClient}) {
258
+ return (
259
+ <div>
260
+ <span suppressHydrationWarning={true}>
261
+ {isClient ? 'Client1' : 'Server1'}
262
+ {isClient ? 'Client2' : 'Server2'}
263
+ </span>
264
+ </div>
265
+ );
266
+ }
267
+ await act(() => {
268
+ const {pipe} = ReactDOMFizzServer.renderToPipeableStream(
269
+ <App isClient={false} />,
270
+ );
271
+ pipe(writable);
272
+ });
273
+ expect(getVisibleChildren(container)).toEqual(
274
+ <div>
275
+ <span>
276
+ {'Server1'}
277
+ {'Server2'}
278
+ </span>
279
+ </div>,
280
+ );
281
+ ReactDOMClient.hydrateRoot(container, <App isClient={true} />, {
282
+ onRecoverableError(error) {
283
+ Scheduler.log(error.message);
284
+ },
285
+ });
286
+ await waitForAll([]);
287
+ expect(getVisibleChildren(container)).toEqual(
288
+ <div>
289
+ <span>
290
+ {'Client1'}
291
+ {'Client2'}
292
+ </span>
293
+ </div>,
294
+ );
295
+ });
296
+
213
297
it('errors on text-to-element mismatches with suppressHydrationWarning', async () => {
214
298
function App({isClient}) {
215
299
return (
@@ -261,6 +345,7 @@ describe('ReactDOMFizzServerHydrationWarning', () => {
261
345
);
262
346
});
263
347
348
+ // @gate enableClientRenderFallbackOnTextMismatch
264
349
it('suppresses but does not fix client-only single text node mismatches with suppressHydrationWarning', async () => {
265
350
function App({text}) {
266
351
return (
@@ -301,6 +386,41 @@ describe('ReactDOMFizzServerHydrationWarning', () => {
301
386
);
302
387
});
303
388
389
+ // @gate !enableClientRenderFallbackOnTextMismatch
390
+ it('suppresses and fixes client-only single text node mismatches with suppressHydrationWarning', async () => {
391
+ function App({isClient}) {
392
+ return (
393
+ <div>
394
+ <span suppressHydrationWarning={true}>
395
+ {isClient ? 'Client' : null}
396
+ </span>
397
+ </div>
398
+ );
399
+ }
400
+ await act(() => {
401
+ const {pipe} = ReactDOMFizzServer.renderToPipeableStream(
402
+ <App isClient={false} />,
403
+ );
404
+ pipe(writable);
405
+ });
406
+ expect(getVisibleChildren(container)).toEqual(
407
+ <div>
408
+ <span />
409
+ </div>,
410
+ );
411
+ ReactDOMClient.hydrateRoot(container, <App isClient={true} />, {
412
+ onRecoverableError(error) {
413
+ Scheduler.log(error.message);
414
+ },
415
+ });
416
+ await waitForAll([]);
417
+ expect(getVisibleChildren(container)).toEqual(
418
+ <div>
419
+ <span>{'Client'}</span>
420
+ </div>,
421
+ );
422
+ });
423
+
304
424
// TODO: This behavior is not consistent with client-only single text node.
305
425
306
426
it('errors on server-only single text node mismatches with suppressHydrationWarning', async () => {
0 commit comments