Skip to content

Commit 73e0aba

Browse files
committed
Add diff to hydrate warnings (facebook#10085)
Renders DOM attributes in the tags mentioned in the warnings. Borrows the idea and partially implementation of `getNodeSignature` from @giles-v facebook#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 2363589 commit 73e0aba

File tree

7 files changed

+593
-160
lines changed

7 files changed

+593
-160
lines changed

fixtures/ssr/src/components/SSRMismatchTest.js

+34-7
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,45 @@ const testCases = [
243243
),
244244
},
245245
{
246-
key: 'ssr-warnForInsertedHydratedText-didNotFindHydratableTextInstance',
246+
key:
247+
'ssr-warnForInsertedHydratedText-didNotFindHydratableTextInstance-replacement',
247248
renderServer: () => (
248249
<div>
249-
<span />
250-
<span />
250+
nested{' '}
251+
<p>
252+
children <b>text</b>
253+
</p>
251254
</div>
252255
),
253256
renderBrowser: () => (
254257
<div>
255-
<span />
256-
SSRMismatchTest client text
257-
<span />
258+
nested{' '}
259+
<div>
260+
children <b>text</b>
261+
</div>
262+
</div>
263+
),
264+
},
265+
{
266+
key:
267+
'ssr-warnForInsertedHydratedText-didNotFindHydratableTextInstance-insertion',
268+
renderServer: () => (
269+
<div>
270+
nested{' '}
271+
<p>
272+
children <b>text</b>
273+
</p>
274+
</div>
275+
),
276+
renderBrowser: () => (
277+
<div>
278+
nested{' '}
279+
<p>
280+
children <b>text</b>
281+
</p>
282+
<div>
283+
children <b>text</b>
284+
</div>
258285
</div>
259286
),
260287
},

0 commit comments

Comments
 (0)