Skip to content

Commit e6eb98d

Browse files
committed
Remove legacy hydration mode
1 parent b8da12e commit e6eb98d

23 files changed

+37
-641
lines changed

packages/react-dom-bindings/src/client/ReactDOMComponent.js

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,6 @@ function normalizeMarkupForTextOrAttribute(markup: mixed): string {
328328
export function checkForUnmatchedText(
329329
serverText: string,
330330
clientText: string | number | bigint,
331-
isConcurrentMode: boolean,
332331
shouldWarnDev: boolean,
333332
) {
334333
const normalizedClientText = normalizeMarkupForTextOrAttribute(clientText);
@@ -350,7 +349,7 @@ export function checkForUnmatchedText(
350349
}
351350
}
352351

353-
if (isConcurrentMode && enableClientRenderFallbackOnTextMismatch) {
352+
if (enableClientRenderFallbackOnTextMismatch) {
354353
// In concurrent roots, we throw when there's a text mismatch and revert to
355354
// client rendering, up to the nearest Suspense boundary.
356355
throw new Error('Text content does not match server-rendered HTML.');
@@ -2716,7 +2715,6 @@ export function diffHydratedProperties(
27162715
domElement: Element,
27172716
tag: string,
27182717
props: Object,
2719-
isConcurrentMode: boolean,
27202718
shouldWarnDev: boolean,
27212719
hostContext: HostContext,
27222720
): void {
@@ -2835,14 +2833,9 @@ export function diffHydratedProperties(
28352833
// $FlowFixMe[unsafe-addition] Flow doesn't want us to use `+` operator with string and bigint
28362834
if (domElement.textContent !== '' + children) {
28372835
if (props.suppressHydrationWarning !== true) {
2838-
checkForUnmatchedText(
2839-
domElement.textContent,
2840-
children,
2841-
isConcurrentMode,
2842-
shouldWarnDev,
2843-
);
2836+
checkForUnmatchedText(domElement.textContent, children, shouldWarnDev);
28442837
}
2845-
if (!isConcurrentMode || !enableClientRenderFallbackOnTextMismatch) {
2838+
if (!enableClientRenderFallbackOnTextMismatch) {
28462839
// We really should be patching this in the commit phase but since
28472840
// this only affects legacy mode hydration which is deprecated anyway
28482841
// we can get away with it.
@@ -2911,11 +2904,7 @@ export function diffHydratedProperties(
29112904
}
29122905
}
29132906

2914-
export function diffHydratedText(
2915-
textNode: Text,
2916-
text: string,
2917-
isConcurrentMode: boolean,
2918-
): boolean {
2907+
export function diffHydratedText(textNode: Text, text: string): boolean {
29192908
const isDifferent = textNode.nodeValue !== text;
29202909
return isDifferent;
29212910
}

packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js

Lines changed: 12 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ import type {
3131
import {NotPending} from 'react-dom-bindings/src/shared/ReactDOMFormActions';
3232
import {getCurrentRootHostContainer} from 'react-reconciler/src/ReactFiberHostContext';
3333
import {DefaultEventPriority} from 'react-reconciler/src/ReactEventPriorities';
34-
// TODO: Remove this deep import when we delete the legacy root API
35-
import {ConcurrentMode, NoMode} from 'react-reconciler/src/ReactTypeOfMode';
3634

3735
import hasOwnProperty from 'shared/hasOwnProperty';
3836
import {checkAttributeStringCoercion} from 'shared/CheckStringCoercion';
@@ -1383,19 +1381,7 @@ export function hydrateInstance(
13831381
// get attached.
13841382
updateFiberProps(instance, props);
13851383

1386-
// TODO: Temporary hack to check if we're in a concurrent root. We can delete
1387-
// when the legacy root API is removed.
1388-
const isConcurrentMode =
1389-
((internalInstanceHandle: Fiber).mode & ConcurrentMode) !== NoMode;
1390-
1391-
diffHydratedProperties(
1392-
instance,
1393-
type,
1394-
props,
1395-
isConcurrentMode,
1396-
shouldWarnDev,
1397-
hostContext,
1398-
);
1384+
diffHydratedProperties(instance, type, props, shouldWarnDev, hostContext);
13991385
}
14001386

14011387
export function validateHydratableTextInstance(
@@ -1420,12 +1406,7 @@ export function hydrateTextInstance(
14201406
): boolean {
14211407
precacheFiberNode(internalInstanceHandle, textInstance);
14221408

1423-
// TODO: Temporary hack to check if we're in a concurrent root. We can delete
1424-
// when the legacy root API is removed.
1425-
const isConcurrentMode =
1426-
((internalInstanceHandle: Fiber).mode & ConcurrentMode) !== NoMode;
1427-
1428-
return diffHydratedText(textInstance, text, isConcurrentMode);
1409+
return diffHydratedText(textInstance, text);
14291410
}
14301411

14311412
export function hydrateSuspenseInstance(
@@ -1523,15 +1504,9 @@ export function didNotMatchHydratedContainerTextInstance(
15231504
parentContainer: Container,
15241505
textInstance: TextInstance,
15251506
text: string,
1526-
isConcurrentMode: boolean,
15271507
shouldWarnDev: boolean,
15281508
) {
1529-
checkForUnmatchedText(
1530-
textInstance.nodeValue,
1531-
text,
1532-
isConcurrentMode,
1533-
shouldWarnDev,
1534-
);
1509+
checkForUnmatchedText(textInstance.nodeValue, text, shouldWarnDev);
15351510
}
15361511

15371512
export function didNotMatchHydratedTextInstance(
@@ -1540,16 +1515,10 @@ export function didNotMatchHydratedTextInstance(
15401515
parentInstance: Instance,
15411516
textInstance: TextInstance,
15421517
text: string,
1543-
isConcurrentMode: boolean,
15441518
shouldWarnDev: boolean,
15451519
) {
15461520
if (parentProps[SUPPRESS_HYDRATION_WARNING] !== true) {
1547-
checkForUnmatchedText(
1548-
textInstance.nodeValue,
1549-
text,
1550-
isConcurrentMode,
1551-
shouldWarnDev,
1552-
);
1521+
checkForUnmatchedText(textInstance.nodeValue, text, shouldWarnDev);
15531522
}
15541523
}
15551524

@@ -1592,17 +1561,14 @@ export function didNotHydrateInstance(
15921561
parentProps: Props,
15931562
parentInstance: Instance,
15941563
instance: HydratableInstance,
1595-
isConcurrentMode: boolean,
15961564
) {
15971565
if (__DEV__) {
1598-
if (isConcurrentMode || parentProps[SUPPRESS_HYDRATION_WARNING] !== true) {
1599-
if (instance.nodeType === ELEMENT_NODE) {
1600-
warnForDeletedHydratableElement(parentInstance, (instance: any));
1601-
} else if (instance.nodeType === COMMENT_NODE) {
1602-
// TODO: warnForDeletedHydratableSuspenseBoundary
1603-
} else {
1604-
warnForDeletedHydratableText(parentInstance, (instance: any));
1605-
}
1566+
if (instance.nodeType === ELEMENT_NODE) {
1567+
warnForDeletedHydratableElement(parentInstance, (instance: any));
1568+
} else if (instance.nodeType === COMMENT_NODE) {
1569+
// TODO: warnForDeletedHydratableSuspenseBoundary
1570+
} else {
1571+
warnForDeletedHydratableText(parentInstance, (instance: any));
16061572
}
16071573
}
16081574
}
@@ -1673,12 +1639,9 @@ export function didNotFindHydratableInstance(
16731639
parentInstance: Instance,
16741640
type: string,
16751641
props: Props,
1676-
isConcurrentMode: boolean,
16771642
) {
16781643
if (__DEV__) {
1679-
if (isConcurrentMode || parentProps[SUPPRESS_HYDRATION_WARNING] !== true) {
1680-
warnForInsertedHydratedElement(parentInstance, type, props);
1681-
}
1644+
warnForInsertedHydratedElement(parentInstance, type, props);
16821645
}
16831646
}
16841647

@@ -1687,12 +1650,9 @@ export function didNotFindHydratableTextInstance(
16871650
parentProps: Props,
16881651
parentInstance: Instance,
16891652
text: string,
1690-
isConcurrentMode: boolean,
16911653
) {
16921654
if (__DEV__) {
1693-
if (isConcurrentMode || parentProps[SUPPRESS_HYDRATION_WARNING] !== true) {
1694-
warnForInsertedHydratedText(parentInstance, text);
1695-
}
1655+
warnForInsertedHydratedText(parentInstance, text);
16961656
}
16971657
}
16981658

packages/react-dom/index.classic.fb.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ export {
2424
hydrateRoot,
2525
findDOMNode,
2626
flushSync,
27-
hydrate,
2827
render,
2928
unmountComponentAtNode,
3029
unstable_batchedUpdates,

packages/react-dom/index.experimental.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ export {
1414
hydrateRoot,
1515
findDOMNode,
1616
flushSync,
17-
hydrate,
1817
render,
1918
unmountComponentAtNode,
2019
unstable_batchedUpdates,

packages/react-dom/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export {
1616
hydrateRoot,
1717
findDOMNode,
1818
flushSync,
19-
hydrate,
2019
render,
2120
unmountComponentAtNode,
2221
unstable_batchedUpdates,

packages/react-dom/index.stable.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ export {
1414
hydrateRoot,
1515
findDOMNode,
1616
flushSync,
17-
hydrate,
1817
render,
1918
unmountComponentAtNode,
2019
unstable_batchedUpdates,

packages/react-dom/src/__tests__/ReactDOMServerIntegrationReconnecting-test.js

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
const ReactDOMServerIntegrationUtils = require('./utils/ReactDOMServerIntegrationTestUtils');
1313

1414
let React;
15-
let ReactDOM;
1615
let ReactDOMClient;
1716
let ReactDOMServer;
1817

@@ -453,71 +452,3 @@ describe('ReactDOMServerIntegration', () => {
453452
));
454453
});
455454
});
456-
457-
describe('ReactDOMServerIntegration (legacy)', () => {
458-
function initModules() {
459-
// Reset warning cache.
460-
jest.resetModules();
461-
462-
React = require('react');
463-
ReactDOM = require('react-dom');
464-
ReactDOMServer = require('react-dom/server');
465-
466-
// Make them available to the helpers.
467-
return {
468-
ReactDOM,
469-
ReactDOMServer,
470-
};
471-
}
472-
473-
const {resetModules, expectMarkupMatch} =
474-
ReactDOMServerIntegrationUtils(initModules);
475-
476-
beforeEach(() => {
477-
resetModules();
478-
});
479-
480-
it('legacy mode can explicitly ignore errors reconnecting different element types of children', () =>
481-
expectMarkupMatch(
482-
<div>
483-
<div />
484-
</div>,
485-
<div suppressHydrationWarning={true}>
486-
<span />
487-
</div>,
488-
));
489-
490-
it('legacy mode can explicitly ignore reconnecting more children', () =>
491-
expectMarkupMatch(
492-
<div>
493-
<div />
494-
</div>,
495-
<div suppressHydrationWarning={true}>
496-
<div />
497-
<div />
498-
</div>,
499-
));
500-
501-
it('legacy mode can explicitly ignore reconnecting fewer children', () =>
502-
expectMarkupMatch(
503-
<div>
504-
<div />
505-
<div />
506-
</div>,
507-
<div suppressHydrationWarning={true}>
508-
<div />
509-
</div>,
510-
));
511-
512-
it('legacy mode can explicitly ignore reconnecting reordered children', () =>
513-
expectMarkupMatch(
514-
<div suppressHydrationWarning={true}>
515-
<div />
516-
<span />
517-
</div>,
518-
<div suppressHydrationWarning={true}>
519-
<span />
520-
<div />
521-
</div>,
522-
));
523-
});

packages/react-dom/src/__tests__/ReactDOMServerPartialHydration-test.internal.js

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -718,74 +718,6 @@ describe('ReactDOMServerPartialHydration', () => {
718718
expect(deleted.length).toBe(1);
719719
});
720720

721-
it('warns and replaces the boundary content in legacy mode', async () => {
722-
let suspend = false;
723-
let resolve;
724-
const promise = new Promise(resolvePromise => (resolve = resolvePromise));
725-
const ref = React.createRef();
726-
727-
function Child() {
728-
if (suspend) {
729-
throw promise;
730-
} else {
731-
return 'Hello';
732-
}
733-
}
734-
735-
function App() {
736-
return (
737-
<div>
738-
<Suspense fallback="Loading...">
739-
<span ref={ref}>
740-
<Child />
741-
</span>
742-
</Suspense>
743-
</div>
744-
);
745-
}
746-
747-
// Don't suspend on the server.
748-
suspend = false;
749-
const finalHTML = ReactDOMServer.renderToString(<App />);
750-
751-
const container = document.createElement('div');
752-
container.innerHTML = finalHTML;
753-
754-
const span = container.getElementsByTagName('span')[0];
755-
756-
// On the client we try to hydrate.
757-
suspend = true;
758-
await expect(async () => {
759-
await act(() => {
760-
ReactDOM.hydrate(<App />, container);
761-
});
762-
}).toErrorDev(
763-
'Warning: Cannot hydrate Suspense in legacy mode. Switch from ' +
764-
'ReactDOM.hydrate(element, container) to ' +
765-
'ReactDOMClient.hydrateRoot(container, <App />)' +
766-
'.render(element) or remove the Suspense components from the server ' +
767-
'rendered components.' +
768-
'\n in Suspense (at **)' +
769-
'\n in div (at **)' +
770-
'\n in App (at **)',
771-
);
772-
773-
// We're now in loading state.
774-
expect(container.textContent).toBe('Loading...');
775-
776-
const span2 = container.getElementsByTagName('span')[0];
777-
// This is a new node.
778-
expect(span).not.toBe(span2);
779-
expect(ref.current).toBe(null);
780-
781-
// Resolving the promise should render the final content.
782-
suspend = false;
783-
await act(() => resolve());
784-
785-
// We should now have hydrated with a ref on the existing span.
786-
expect(container.textContent).toBe('Hello');
787-
});
788-
789721
it('can insert siblings before the dehydrated boundary', async () => {
790722
let suspend = false;
791723
const promise = new Promise(() => {});

0 commit comments

Comments
 (0)