Skip to content

Commit

Permalink
fix hydration warning suppression in text comparisons (#24784)
Browse files Browse the repository at this point in the history
* fix hydration warning suppression in text comparisons

* lint

* lowercase test
  • Loading branch information
gnoff committed Jun 26, 2022
1 parent 652e6c5 commit 1678530
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 2 deletions.
48 changes: 48 additions & 0 deletions packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4146,6 +4146,54 @@ describe('ReactDOMFizzServer', () => {
);
});

it('hydration warnings for mismatched text with multiple text nodes caused by suspending should be suppressed', async () => {
let resolve;
const Lazy = React.lazy(() => {
return new Promise(r => {
resolve = r;
});
});

function App({isClient}) {
return (
<div>
{isClient ? <Lazy /> : <p>lazy</p>}
<p>some {'text'}</p>
</div>
);
}
await act(async () => {
const {pipe} = ReactDOMFizzServer.renderToPipeableStream(<App />);
pipe(writable);
});

const errors = [];
ReactDOMClient.hydrateRoot(container, <App isClient={true} />, {
onRecoverableError(error) {
errors.push(error.message);
},
});

expect(Scheduler).toFlushAndYield([]);
expect(errors).toEqual([]);
expect(getVisibleChildren(container)).toEqual(
<div>
<p>lazy</p>
<p>some {'text'}</p>
</div>,
);

resolve({default: () => <p>lazy</p>});
expect(Scheduler).toFlushAndYield([]);
expect(errors).toEqual([]);
expect(getVisibleChildren(container)).toEqual(
<div>
<p>lazy</p>
<p>some {'text'}</p>
</div>,
);
});

describe('text separators', () => {
// To force performWork to start before resolving AsyncText but before piping we need to wait until
// after scheduleWork which currently uses setImmediate to delay performWork
Expand Down
4 changes: 2 additions & 2 deletions packages/react-dom/src/client/ReactDOMHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -971,8 +971,8 @@ export function didNotMatchHydratedContainerTextInstance(
textInstance: TextInstance,
text: string,
isConcurrentMode: boolean,
shouldWarnDev: boolean,
) {
const shouldWarnDev = true;
checkForUnmatchedText(
textInstance.nodeValue,
text,
Expand All @@ -988,9 +988,9 @@ export function didNotMatchHydratedTextInstance(
textInstance: TextInstance,
text: string,
isConcurrentMode: boolean,
shouldWarnDev: boolean,
) {
if (parentProps[SUPPRESS_HYDRATION_WARNING] !== true) {
const shouldWarnDev = true;
checkForUnmatchedText(
textInstance.nodeValue,
text,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ function prepareToHydrateHostTextInstance(fiber: Fiber): boolean {
textContent,
// TODO: Delete this argument when we remove the legacy root API.
isConcurrentMode,
shouldWarnIfMismatchDev,
);
break;
}
Expand All @@ -525,6 +526,7 @@ function prepareToHydrateHostTextInstance(fiber: Fiber): boolean {
textContent,
// TODO: Delete this argument when we remove the legacy root API.
isConcurrentMode,
shouldWarnIfMismatchDev,
);
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ function prepareToHydrateHostTextInstance(fiber: Fiber): boolean {
textContent,
// TODO: Delete this argument when we remove the legacy root API.
isConcurrentMode,
shouldWarnIfMismatchDev,
);
break;
}
Expand All @@ -525,6 +526,7 @@ function prepareToHydrateHostTextInstance(fiber: Fiber): boolean {
textContent,
// TODO: Delete this argument when we remove the legacy root API.
isConcurrentMode,
shouldWarnIfMismatchDev,
);
break;
}
Expand Down

0 comments on commit 1678530

Please sign in to comment.