@@ -171,7 +171,9 @@ describe('ReactDOMServerHydration', () => {
171
171
+ client
172
172
- server
173
173
174
- Owner Stack: <empty>",
174
+ Owner Stack:
175
+ in main (at **)
176
+ in Mismatch (at **)",
175
177
]
176
178
` ) ;
177
179
}
@@ -236,7 +238,9 @@ describe('ReactDOMServerHydration', () => {
236
238
+ This markup contains an nbsp entity: client text
237
239
- This markup contains an nbsp entity: server text
238
240
239
- Owner Stack: <empty>",
241
+ Owner Stack:
242
+ in div (at **)
243
+ in Mismatch (at **)",
240
244
]
241
245
` ) ;
242
246
}
@@ -283,7 +287,9 @@ describe('ReactDOMServerHydration', () => {
283
287
}}
284
288
>
285
289
286
- Owner Stack: <empty>",
290
+ Owner Stack:
291
+ in main (at **)
292
+ in Mismatch (at **)",
287
293
]
288
294
` ) ;
289
295
} ) ;
@@ -325,7 +331,9 @@ describe('ReactDOMServerHydration', () => {
325
331
- dir="rtl"
326
332
>
327
333
328
- Owner Stack: <empty>",
334
+ Owner Stack:
335
+ in main (at **)
336
+ in Mismatch (at **)",
329
337
]
330
338
` ) ;
331
339
} ) ;
@@ -367,7 +375,9 @@ describe('ReactDOMServerHydration', () => {
367
375
- dir={null}
368
376
>
369
377
370
- Owner Stack: <empty>",
378
+ Owner Stack:
379
+ in main (at **)
380
+ in Mismatch (at **)",
371
381
]
372
382
` ) ;
373
383
} ) ;
@@ -409,7 +419,9 @@ describe('ReactDOMServerHydration', () => {
409
419
- dir="rtl"
410
420
>
411
421
412
- Owner Stack: <empty>",
422
+ Owner Stack:
423
+ in main (at **)
424
+ in Mismatch (at **)",
413
425
]
414
426
` ) ;
415
427
} ) ;
@@ -451,7 +463,9 @@ describe('ReactDOMServerHydration', () => {
451
463
- dir="rtl"
452
464
>
453
465
454
- Owner Stack: <empty>",
466
+ Owner Stack:
467
+ in main (at **)
468
+ in Mismatch (at **)",
455
469
]
456
470
` ) ;
457
471
} ) ;
@@ -492,7 +506,77 @@ describe('ReactDOMServerHydration', () => {
492
506
- style={{opacity:"0"}}
493
507
>
494
508
495
- Owner Stack: <empty>",
509
+ Owner Stack:
510
+ in main (at **)
511
+ in Mismatch (at **)",
512
+ ]
513
+ ` ) ;
514
+ } ) ;
515
+
516
+ // @gate __DEV__
517
+ it ( 'picks the DFS-first Fiber as the error Owner' , ( ) => {
518
+ function LeftMismatch ( { isClient} ) {
519
+ return < div className = { isClient ? 'client' : 'server' } > </ div > ;
520
+ }
521
+
522
+ function LeftIndirection ( { isClient} ) {
523
+ return < LeftMismatch isClient = { isClient } /> ;
524
+ }
525
+
526
+ function MiddleMismatch ( { isClient} ) {
527
+ return < span className = { isClient ? 'client' : 'server' } > </ span > ;
528
+ }
529
+
530
+ function RightMisMatch ( { isClient} ) {
531
+ return < p className = { isClient ? 'client' : 'server' } > </ p > ;
532
+ }
533
+
534
+ function App ( { isClient} ) {
535
+ return (
536
+ < >
537
+ < LeftIndirection isClient = { isClient } />
538
+ < MiddleMismatch isClient = { isClient } />
539
+ < RightMisMatch isClient = { isClient } />
540
+ </ >
541
+ ) ;
542
+ }
543
+ expect ( testMismatch ( App ) ) . toMatchInlineSnapshot ( `
544
+ [
545
+ "A tree hydrated but some attributes of the server rendered HTML didn't match the client properties. This won't be patched up. This can happen if a SSR-ed Client Component used:
546
+
547
+ - A server/client branch \`if (typeof window !== 'undefined')\`.
548
+ - Variable input such as \`Date.now()\` or \`Math.random()\` which changes each time it's called.
549
+ - Date formatting in a user's locale which doesn't match the server.
550
+ - External changing data without sending a snapshot of it along with the HTML.
551
+ - Invalid HTML tag nesting.
552
+
553
+ It can also happen if the client has a browser extension installed which messes with the HTML before React loaded.
554
+
555
+ https://react.dev/link/hydration-mismatch
556
+
557
+ <App isClient={true}>
558
+ <LeftIndirection isClient={true}>
559
+ <LeftMismatch isClient={true}>
560
+ <div
561
+ + className="client"
562
+ - className="server"
563
+ >
564
+ <MiddleMismatch isClient={true}>
565
+ <span
566
+ + className="client"
567
+ - className="server"
568
+ >
569
+ <RightMisMatch isClient={true}>
570
+ <p
571
+ + className="client"
572
+ - className="server"
573
+ >
574
+
575
+ Owner Stack:
576
+ in div (at **)
577
+ in LeftMismatch (at **)
578
+ in LeftIndirection (at **)
579
+ in App (at **)",
496
580
]
497
581
` ) ;
498
582
} ) ;
@@ -701,7 +785,9 @@ describe('ReactDOMServerHydration', () => {
701
785
+ only
702
786
-
703
787
704
- Owner Stack: <empty>",
788
+ Owner Stack:
789
+ in div (at **)
790
+ in Mismatch (at **)",
705
791
]
706
792
` ) ;
707
793
}
0 commit comments