GeezerVison is showing github.com — fix hydration warning suppression in text comparisons (#24784) · react/react@1678530
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js +48Lines changed: 48 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -4146,6 +4146,54 @@ describe('ReactDOMFizzServer', () => { | 4146 | 4146 | ); | 4147 | 4147 | }); | 4148 | 4148 |
| | 4149 | + it('hydration warnings for mismatched text with multiple text nodes caused by suspending should be suppressed', async () => { | | 4150 | + let resolve; | | 4151 | + const Lazy = React.lazy(() => { | | 4152 | + return new Promise(r => { | | 4153 | + resolve = r; | | 4154 | + }); | | 4155 | + }); | | 4156 | + | | 4157 | + function App({isClient}) { | | 4158 | + return ( | | 4159 | + <div> | | 4160 | + {isClient ? <Lazy /> : <p>lazy</p>} | | 4161 | + <p>some {'text'}</p> | | 4162 | + </div> | | 4163 | + ); | | 4164 | + } | | 4165 | + await act(async () => { | | 4166 | + const {pipe} = ReactDOMFizzServer.renderToPipeableStream(<App />); | | 4167 | + pipe(writable); | | 4168 | + }); | | 4169 | + | | 4170 | + const errors = []; | | 4171 | + ReactDOMClient.hydrateRoot(container, <App isClient={true} />, { | | 4172 | + onRecoverableError(error) { | | 4173 | + errors.push(error.message); | | 4174 | + }, | | 4175 | + }); | | 4176 | + | | 4177 | + expect(Scheduler).toFlushAndYield([]); | | 4178 | + expect(errors).toEqual([]); | | 4179 | + expect(getVisibleChildren(container)).toEqual( | | 4180 | + <div> | | 4181 | + <p>lazy</p> | | 4182 | + <p>some {'text'}</p> | | 4183 | + </div>, | | 4184 | + ); | | 4185 | + | | 4186 | + resolve({default: () => <p>lazy</p>}); | | 4187 | + expect(Scheduler).toFlushAndYield([]); | | 4188 | + expect(errors).toEqual([]); | | 4189 | + expect(getVisibleChildren(container)).toEqual( | | 4190 | + <div> | | 4191 | + <p>lazy</p> | | 4192 | + <p>some {'text'}</p> | | 4193 | + </div>, | | 4194 | + ); | | 4195 | + }); | | 4196 | + | 4149 | 4197 | describe('text separators', () => { | 4150 | 4198 | // To force performWork to start before resolving AsyncText but before piping we need to wait until | 4151 | 4199 | // after scheduleWork which currently uses setImmediate to delay performWork | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-dom/src/client/ReactDOMHostConfig.js +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -971,8 +971,8 @@ export function didNotMatchHydratedContainerTextInstance( | 971 | 971 | textInstance: TextInstance, | 972 | 972 | text: string, | 973 | 973 | isConcurrentMode: boolean, | | 974 | + shouldWarnDev: boolean, | 974 | 975 | ) { | 975 | | - const shouldWarnDev = true; | 976 | 976 | checkForUnmatchedText( | 977 | 977 | textInstance.nodeValue, | 978 | 978 | text, | @@ -988,9 +988,9 @@ export function didNotMatchHydratedTextInstance( | 988 | 988 | textInstance: TextInstance, | 989 | 989 | text: string, | 990 | 990 | isConcurrentMode: boolean, | | 991 | + shouldWarnDev: boolean, | 991 | 992 | ) { | 992 | 993 | if (parentProps[SUPPRESS_HYDRATION_WARNING] !== true) { | 993 | | - const shouldWarnDev = true; | 994 | 994 | checkForUnmatchedText( | 995 | 995 | textInstance.nodeValue, | 996 | 996 | text, | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberHydrationContext.new.js +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -508,6 +508,7 @@ function prepareToHydrateHostTextInstance(fiber: Fiber): boolean { | 508 | 508 | textContent, | 509 | 509 | // TODO: Delete this argument when we remove the legacy root API. | 510 | 510 | isConcurrentMode, | | 511 | + shouldWarnIfMismatchDev, | 511 | 512 | ); | 512 | 513 | break; | 513 | 514 | } | @@ -525,6 +526,7 @@ function prepareToHydrateHostTextInstance(fiber: Fiber): boolean { | 525 | 526 | textContent, | 526 | 527 | // TODO: Delete this argument when we remove the legacy root API. | 527 | 528 | isConcurrentMode, | | 529 | + shouldWarnIfMismatchDev, | 528 | 530 | ); | 529 | 531 | break; | 530 | 532 | } | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberHydrationContext.old.js +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -508,6 +508,7 @@ function prepareToHydrateHostTextInstance(fiber: Fiber): boolean { | 508 | 508 | textContent, | 509 | 509 | // TODO: Delete this argument when we remove the legacy root API. | 510 | 510 | isConcurrentMode, | | 511 | + shouldWarnIfMismatchDev, | 511 | 512 | ); | 512 | 513 | break; | 513 | 514 | } | @@ -525,6 +526,7 @@ function prepareToHydrateHostTextInstance(fiber: Fiber): boolean { | 525 | 526 | textContent, | 526 | 527 | // TODO: Delete this argument when we remove the legacy root API. | 527 | 528 | isConcurrentMode, | | 529 | + shouldWarnIfMismatchDev, | 528 | 530 | ); | 529 | 531 | break; | 530 | 532 | } | |
|