Skip to content

Commit fb4bbde

Browse files
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.gif
1 parent 6c425e7 commit fb4bbde

File tree

8 files changed

+598
-125
lines changed

8 files changed

+598
-125
lines changed

fixtures/ssr/src/components/SSRMismatchTest.js

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ const testCases = [
145145
key: 'ssr-warnForDeletedHydratableElement-didNotHydrateInstance',
146146
renderServer: () => (
147147
<div>
148-
<div />
148+
<div>SSRMismatchTest default text</div>
149149
<span />
150150
</div>
151151
),
@@ -243,18 +243,43 @@ const testCases = [
243243
),
244244
},
245245
{
246-
key: 'ssr-warnForInsertedHydratedText-didNotFindHydratableTextInstance',
246+
key: 'ssr-warnForInsertedHydratedText-didNotFindHydratableTextInstance-replacement',
247247
renderServer: () => (
248248
<div>
249-
<span />
250-
<span />
249+
nested{' '}
250+
<p>
251+
children <b>text</b>
252+
</p>
251253
</div>
252254
),
253255
renderBrowser: () => (
254256
<div>
255-
<span />
256-
SSRMismatchTest client text
257-
<span />
257+
nested{' '}
258+
<div>
259+
children <b>text</b>
260+
</div>
261+
</div>
262+
),
263+
},
264+
{
265+
key: 'ssr-warnForInsertedHydratedText-didNotFindHydratableTextInstance-insertion',
266+
renderServer: () => (
267+
<div>
268+
nested{' '}
269+
<p>
270+
children <b>text</b>
271+
</p>
272+
</div>
273+
),
274+
renderBrowser: () => (
275+
<div>
276+
nested{' '}
277+
<p>
278+
children <b>text</b>
279+
</p>
280+
<div>
281+
children <b>text</b>
282+
</div>
258283
</div>
259284
),
260285
},

0 commit comments

Comments
 (0)