Commit 0364831
Validate DOM nesting for hydration before the hydration warns / errors (facebook#28434)
If there's invalid dom nesting, there will be mismatches following but
the nesting is the most important cause of the problem.
Previously we would include the DOM nesting when rerendering thanks to
the new model of throw and recovery. However, the log would come during
the recovery phase which is after we've already logged that there was a
hydration mismatch.
People would consistently miss this log. Which is fair because you
should always look at the first log first as the most probable cause.
This ensures that we log in the hydration phase if there's a dom nesting
issue. This assumes that the consequence of nesting will appear such
that the won't have a mismatch before this. That's typically the case
because the node will move up and to be a later sibling. So as long as
that happens and we keep hydrating depth first, it should hold true.
There might be an issue if there's a suspense boundary between the nodes
we'll find discover the new child in the outer path since suspense
boundaries as breadth first.
Before:
<img width="996" alt="Screenshot 2024-02-23 at 7 34 01 PM"
src="https://github.com/facebook/react/assets/63648/af70cf7f-898b-477f-be39-13b01cfe585f">
After:
<img width="853" alt="Screenshot 2024-02-23 at 7 22 24 PM"
src="https://github.com/facebook/react/assets/63648/896c6348-1620-4f99-881d-b6069263925e">
Cameo: RSC stacks.1 parent 3dabef6 commit 0364831
File tree
11 files changed
+181
-59
lines changed- packages
- react-dom-bindings/src/client
- react-dom/src/__tests__
- react-reconciler/src
- forks
11 files changed
+181
-59
lines changedLines changed: 27 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1355 | 1355 | | |
1356 | 1356 | | |
1357 | 1357 | | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
| 1363 | + | |
| 1364 | + | |
| 1365 | + | |
| 1366 | + | |
| 1367 | + | |
| 1368 | + | |
| 1369 | + | |
| 1370 | + | |
1358 | 1371 | | |
1359 | 1372 | | |
1360 | 1373 | | |
| |||
1383 | 1396 | | |
1384 | 1397 | | |
1385 | 1398 | | |
| 1399 | + | |
| 1400 | + | |
| 1401 | + | |
| 1402 | + | |
| 1403 | + | |
| 1404 | + | |
| 1405 | + | |
| 1406 | + | |
| 1407 | + | |
| 1408 | + | |
| 1409 | + | |
| 1410 | + | |
| 1411 | + | |
| 1412 | + | |
1386 | 1413 | | |
1387 | 1414 | | |
1388 | 1415 | | |
| |||
Lines changed: 22 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
441 | 441 | | |
442 | 442 | | |
443 | 443 | | |
444 | | - | |
| 444 | + | |
445 | 445 | | |
446 | 446 | | |
447 | 447 | | |
| |||
455 | 455 | | |
456 | 456 | | |
457 | 457 | | |
458 | | - | |
| 458 | + | |
459 | 459 | | |
460 | 460 | | |
461 | 461 | | |
| |||
464 | 464 | | |
465 | 465 | | |
466 | 466 | | |
467 | | - | |
| 467 | + | |
468 | 468 | | |
469 | 469 | | |
470 | 470 | | |
| |||
477 | 477 | | |
478 | 478 | | |
479 | 479 | | |
480 | | - | |
| 480 | + | |
| 481 | + | |
481 | 482 | | |
482 | 483 | | |
483 | 484 | | |
484 | 485 | | |
485 | 486 | | |
486 | 487 | | |
487 | | - | |
| 488 | + | |
| 489 | + | |
488 | 490 | | |
489 | 491 | | |
490 | 492 | | |
491 | 493 | | |
| 494 | + | |
492 | 495 | | |
| 496 | + | |
493 | 497 | | |
494 | 498 | | |
495 | | - | |
| 499 | + | |
496 | 500 | | |
497 | 501 | | |
498 | | - | |
| 502 | + | |
499 | 503 | | |
500 | 504 | | |
501 | 505 | | |
502 | 506 | | |
503 | 507 | | |
504 | | - | |
| 508 | + | |
505 | 509 | | |
506 | 510 | | |
507 | 511 | | |
508 | 512 | | |
509 | | - | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
510 | 518 | | |
511 | 519 | | |
512 | | - | |
| 520 | + | |
513 | 521 | | |
514 | | - | |
| 522 | + | |
| 523 | + | |
515 | 524 | | |
516 | 525 | | |
517 | 526 | | |
| 527 | + | |
518 | 528 | | |
| 529 | + | |
519 | 530 | | |
520 | 531 | | |
521 | 532 | | |
Lines changed: 23 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2188 | 2188 | | |
2189 | 2189 | | |
2190 | 2190 | | |
2191 | | - | |
2192 | | - | |
| 2191 | + | |
| 2192 | + | |
| 2193 | + | |
2193 | 2194 | | |
2194 | 2195 | | |
2195 | 2196 | | |
| |||
2208 | 2209 | | |
2209 | 2210 | | |
2210 | 2211 | | |
2211 | | - | |
2212 | | - | |
| 2212 | + | |
| 2213 | + | |
| 2214 | + | |
2213 | 2215 | | |
2214 | 2216 | | |
2215 | 2217 | | |
| |||
2241 | 2243 | | |
2242 | 2244 | | |
2243 | 2245 | | |
2244 | | - | |
| 2246 | + | |
2245 | 2247 | | |
2246 | | - | |
| 2248 | + | |
| 2249 | + | |
2247 | 2250 | | |
2248 | 2251 | | |
2249 | 2252 | | |
2250 | 2253 | | |
2251 | | - | |
2252 | | - | |
| 2254 | + | |
| 2255 | + | |
| 2256 | + | |
2253 | 2257 | | |
2254 | 2258 | | |
2255 | 2259 | | |
2256 | 2260 | | |
2257 | | - | |
2258 | | - | |
2259 | | - | |
| 2261 | + | |
| 2262 | + | |
| 2263 | + | |
| 2264 | + | |
2260 | 2265 | | |
2261 | 2266 | | |
2262 | 2267 | | |
| |||
2283 | 2288 | | |
2284 | 2289 | | |
2285 | 2290 | | |
2286 | | - | |
2287 | | - | |
2288 | | - | |
| 2291 | + | |
| 2292 | + | |
| 2293 | + | |
| 2294 | + | |
2289 | 2295 | | |
2290 | 2296 | | |
2291 | 2297 | | |
| |||
2311 | 2317 | | |
2312 | 2318 | | |
2313 | 2319 | | |
2314 | | - | |
2315 | | - | |
| 2320 | + | |
| 2321 | + | |
| 2322 | + | |
2316 | 2323 | | |
2317 | 2324 | | |
2318 | 2325 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
523 | 523 | | |
524 | 524 | | |
525 | 525 | | |
526 | | - | |
| 526 | + | |
527 | 527 | | |
528 | 528 | | |
529 | 529 | | |
| |||
538 | 538 | | |
539 | 539 | | |
540 | 540 | | |
541 | | - | |
| 541 | + | |
542 | 542 | | |
543 | 543 | | |
544 | 544 | | |
| |||
551 | 551 | | |
552 | 552 | | |
553 | 553 | | |
554 | | - | |
| 554 | + | |
555 | 555 | | |
556 | 556 | | |
557 | 557 | | |
| |||
574 | 574 | | |
575 | 575 | | |
576 | 576 | | |
577 | | - | |
| 577 | + | |
578 | 578 | | |
579 | 579 | | |
580 | 580 | | |
| |||
591 | 591 | | |
592 | 592 | | |
593 | 593 | | |
594 | | - | |
| 594 | + | |
595 | 595 | | |
596 | 596 | | |
597 | 597 | | |
| |||
2552 | 2552 | | |
2553 | 2553 | | |
2554 | 2554 | | |
2555 | | - | |
2556 | | - | |
2557 | | - | |
2558 | | - | |
2559 | | - | |
| 2555 | + | |
| 2556 | + | |
| 2557 | + | |
| 2558 | + | |
| 2559 | + | |
2560 | 2560 | | |
2561 | 2561 | | |
2562 | 2562 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
381 | 381 | | |
382 | 382 | | |
383 | 383 | | |
384 | | - | |
| 384 | + | |
| 385 | + | |
385 | 386 | | |
386 | 387 | | |
387 | 388 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
| 49 | + | |
| 50 | + | |
50 | 51 | | |
51 | 52 | | |
52 | 53 | | |
| |||
263 | 264 | | |
264 | 265 | | |
265 | 266 | | |
266 | | - | |
| 267 | + | |
267 | 268 | | |
268 | 269 | | |
269 | 270 | | |
| |||
Lines changed: 29 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | | - | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
64 | 68 | | |
65 | 69 | | |
66 | 70 | | |
67 | 71 | | |
68 | | - | |
| 72 | + | |
| 73 | + | |
69 | 74 | | |
70 | 75 | | |
71 | 76 | | |
72 | 77 | | |
73 | 78 | | |
74 | | - | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
75 | 84 | | |
76 | 85 | | |
77 | 86 | | |
78 | 87 | | |
79 | | - | |
| 88 | + | |
80 | 89 | | |
| 90 | + | |
81 | 91 | | |
82 | 92 | | |
83 | 93 | | |
84 | 94 | | |
85 | 95 | | |
86 | 96 | | |
87 | | - | |
| 97 | + | |
| 98 | + | |
88 | 99 | | |
89 | 100 | | |
90 | 101 | | |
| |||
93 | 104 | | |
94 | 105 | | |
95 | 106 | | |
96 | | - | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
97 | 112 | | |
98 | 113 | | |
99 | 114 | | |
100 | | - | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
101 | 120 | | |
102 | 121 | | |
103 | 122 | | |
104 | 123 | | |
105 | | - | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
106 | 127 | | |
107 | 128 | | |
108 | 129 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1513 | 1513 | | |
1514 | 1514 | | |
1515 | 1515 | | |
1516 | | - | |
1517 | | - | |
1518 | 1516 | | |
1519 | 1517 | | |
1520 | 1518 | | |
1521 | 1519 | | |
| 1520 | + | |
| 1521 | + | |
1522 | 1522 | | |
1523 | 1523 | | |
1524 | 1524 | | |
| |||
0 commit comments