Commit 9afbc48
committed
Add diff to hydrate warnings (#10085)
Renders DOM attributes in the tags mentioned in the warnings. Borrows the idea and partially implementation of `getNodeSignature` from @giles-v #12115
Renders DOM diff showing visually the location where the hydration failed. Example warning with a diff:
```
Warning: Expected server HTML to contain a matching <div>{['children ', …]}</div> in <div>nested<!-- --> <p>children <b>text</b></p></div>.
<div>
{'nested'}
{' '}
<p>children <b>text</b></p>
+ <div>{['children ', …]}</div>
</div>
in div (at SSRMismatchTest.js:280)
in div (at SSRMismatchTest.js:275)
in div (at SSRMismatchTest.js:308)
in SSRMismatchTest (at App.js:14)
in div (at App.js:11)
in body (at Chrome.js:17)
in html (at Chrome.js:9)
in Chrome (at App.js:10)
in App (at index.js:8)
```
Requires changes to ReactFiberReconciler interface functions that handle hydration errors to distinguish insertion from replacement and show insertion as one added line in the diff; show replacement as one removed, one added line, at correct position among the parentInstance's DOM children:
- add `index` (use `fiber.index`) to point at which child node the insertion or replacement occurs;
- add `isReplaced` to distinguish insertion from replacement.
Extends the proof-of-concept at commit 6c425e7
https://user-images.githubusercontent.com/498274/36652198-11bb46fe-1a62-11e8-9fa2-a612827d1463.gif1 parent 5e61781 commit 9afbc48
File tree
7 files changed
+593
-160
lines changed- fixtures/ssr/src/components
- packages
- react-dom/src
- __tests__
- client
- react-reconciler/src
- scripts/rollup
7 files changed
+593
-160
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
145 | 145 | | |
146 | 146 | | |
147 | 147 | | |
148 | | - | |
| 148 | + | |
149 | 149 | | |
150 | 150 | | |
151 | 151 | | |
| |||
243 | 243 | | |
244 | 244 | | |
245 | 245 | | |
246 | | - | |
| 246 | + | |
| 247 | + | |
247 | 248 | | |
248 | 249 | | |
249 | | - | |
250 | | - | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
251 | 254 | | |
252 | 255 | | |
253 | 256 | | |
254 | 257 | | |
255 | | - | |
256 | | - | |
257 | | - | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
258 | 285 | | |
259 | 286 | | |
260 | 287 | | |
| |||
0 commit comments