Skip to content

Commit 5901d65

Browse files
committed
Remove legacy hydration mode
1 parent f24cf4a commit 5901d65

20 files changed

+37
-660
lines changed

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

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,6 @@ function normalizeMarkupForTextOrAttribute(markup: mixed): string {
330330
export function checkForUnmatchedText(
331331
serverText: string,
332332
clientText: string | number | bigint,
333-
isConcurrentMode: boolean,
334333
shouldWarnDev: boolean,
335334
) {
336335
const normalizedClientText = normalizeMarkupForTextOrAttribute(clientText);
@@ -352,7 +351,7 @@ export function checkForUnmatchedText(
352351
}
353352
}
354353

355-
if (isConcurrentMode && enableClientRenderFallbackOnTextMismatch) {
354+
if (enableClientRenderFallbackOnTextMismatch) {
356355
// In concurrent roots, we throw when there's a text mismatch and revert to
357356
// client rendering, up to the nearest Suspense boundary.
358357
throw new Error('Text content does not match server-rendered HTML.');
@@ -2746,7 +2745,6 @@ export function diffHydratedProperties(
27462745
domElement: Element,
27472746
tag: string,
27482747
props: Object,
2749-
isConcurrentMode: boolean,
27502748
shouldWarnDev: boolean,
27512749
hostContext: HostContext,
27522750
): void {
@@ -2865,14 +2863,9 @@ export function diffHydratedProperties(
28652863
// $FlowFixMe[unsafe-addition] Flow doesn't want us to use `+` operator with string and bigint
28662864
if (domElement.textContent !== '' + children) {
28672865
if (props.suppressHydrationWarning !== true) {
2868-
checkForUnmatchedText(
2869-
domElement.textContent,
2870-
children,
2871-
isConcurrentMode,
2872-
shouldWarnDev,
2873-
);
2866+
checkForUnmatchedText(domElement.textContent, children, shouldWarnDev);
28742867
}
2875-
if (!isConcurrentMode || !enableClientRenderFallbackOnTextMismatch) {
2868+
if (!enableClientRenderFallbackOnTextMismatch) {
28762869
// We really should be patching this in the commit phase but since
28772870
// this only affects legacy mode hydration which is deprecated anyway
28782871
// we can get away with it.
@@ -2941,11 +2934,7 @@ export function diffHydratedProperties(
29412934
}
29422935
}
29432936

2944-
export function diffHydratedText(
2945-
textNode: Text,
2946-
text: string,
2947-
isConcurrentMode: boolean,
2948-
): boolean {
2937+
export function diffHydratedText(textNode: Text, text: string): boolean {
29492938
const isDifferent = textNode.nodeValue !== text;
29502939
return isDifferent;
29512940
}

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

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

3634
import hasOwnProperty from 'shared/hasOwnProperty';
3735
import {checkAttributeStringCoercion} from 'shared/CheckStringCoercion';
@@ -1370,19 +1368,7 @@ export function hydrateInstance(
13701368
// get attached.
13711369
updateFiberProps(instance, props);
13721370

1373-
// TODO: Temporary hack to check if we're in a concurrent root. We can delete
1374-
// when the legacy root API is removed.
1375-
const isConcurrentMode =
1376-
((internalInstanceHandle: Fiber).mode & ConcurrentMode) !== NoMode;
1377-
1378-
diffHydratedProperties(
1379-
instance,
1380-
type,
1381-
props,
1382-
isConcurrentMode,
1383-
shouldWarnDev,
1384-
hostContext,
1385-
);
1371+
diffHydratedProperties(instance, type, props, shouldWarnDev, hostContext);
13861372
}
13871373

13881374
export function validateHydratableTextInstance(
@@ -1407,12 +1393,7 @@ export function hydrateTextInstance(
14071393
): boolean {
14081394
precacheFiberNode(internalInstanceHandle, textInstance);
14091395

1410-
// TODO: Temporary hack to check if we're in a concurrent root. We can delete
1411-
// when the legacy root API is removed.
1412-
const isConcurrentMode =
1413-
((internalInstanceHandle: Fiber).mode & ConcurrentMode) !== NoMode;
1414-
1415-
return diffHydratedText(textInstance, text, isConcurrentMode);
1396+
return diffHydratedText(textInstance, text);
14161397
}
14171398

14181399
export function hydrateSuspenseInstance(
@@ -1508,15 +1489,9 @@ export function didNotMatchHydratedContainerTextInstance(
15081489
parentContainer: Container,
15091490
textInstance: TextInstance,
15101491
text: string,
1511-
isConcurrentMode: boolean,
15121492
shouldWarnDev: boolean,
15131493
) {
1514-
checkForUnmatchedText(
1515-
textInstance.nodeValue,
1516-
text,
1517-
isConcurrentMode,
1518-
shouldWarnDev,
1519-
);
1494+
checkForUnmatchedText(textInstance.nodeValue, text, shouldWarnDev);
15201495
}
15211496

15221497
export function didNotMatchHydratedTextInstance(
@@ -1525,16 +1500,10 @@ export function didNotMatchHydratedTextInstance(
15251500
parentInstance: Instance,
15261501
textInstance: TextInstance,
15271502
text: string,
1528-
isConcurrentMode: boolean,
15291503
shouldWarnDev: boolean,
15301504
) {
15311505
if (parentProps[SUPPRESS_HYDRATION_WARNING] !== true) {
1532-
checkForUnmatchedText(
1533-
textInstance.nodeValue,
1534-
text,
1535-
isConcurrentMode,
1536-
shouldWarnDev,
1537-
);
1506+
checkForUnmatchedText(textInstance.nodeValue, text, shouldWarnDev);
15381507
}
15391508
}
15401509

@@ -1577,17 +1546,14 @@ export function didNotHydrateInstance(
15771546
parentProps: Props,
15781547
parentInstance: Instance,
15791548
instance: HydratableInstance,
1580-
isConcurrentMode: boolean,
15811549
) {
15821550
if (__DEV__) {
1583-
if (isConcurrentMode || parentProps[SUPPRESS_HYDRATION_WARNING] !== true) {
1584-
if (instance.nodeType === ELEMENT_NODE) {
1585-
warnForDeletedHydratableElement(parentInstance, (instance: any));
1586-
} else if (instance.nodeType === COMMENT_NODE) {
1587-
// TODO: warnForDeletedHydratableSuspenseBoundary
1588-
} else {
1589-
warnForDeletedHydratableText(parentInstance, (instance: any));
1590-
}
1551+
if (instance.nodeType === ELEMENT_NODE) {
1552+
warnForDeletedHydratableElement(parentInstance, (instance: any));
1553+
} else if (instance.nodeType === COMMENT_NODE) {
1554+
// TODO: warnForDeletedHydratableSuspenseBoundary
1555+
} else {
1556+
warnForDeletedHydratableText(parentInstance, (instance: any));
15911557
}
15921558
}
15931559
}
@@ -1658,12 +1624,9 @@ export function didNotFindHydratableInstance(
16581624
parentInstance: Instance,
16591625
type: string,
16601626
props: Props,
1661-
isConcurrentMode: boolean,
16621627
) {
16631628
if (__DEV__) {
1664-
if (isConcurrentMode || parentProps[SUPPRESS_HYDRATION_WARNING] !== true) {
1665-
warnForInsertedHydratedElement(parentInstance, type, props);
1666-
}
1629+
warnForInsertedHydratedElement(parentInstance, type, props);
16671630
}
16681631
}
16691632

@@ -1672,12 +1635,9 @@ export function didNotFindHydratableTextInstance(
16721635
parentProps: Props,
16731636
parentInstance: Instance,
16741637
text: string,
1675-
isConcurrentMode: boolean,
16761638
) {
16771639
if (__DEV__) {
1678-
if (isConcurrentMode || parentProps[SUPPRESS_HYDRATION_WARNING] !== true) {
1679-
warnForInsertedHydratedText(parentInstance, text);
1680-
}
1640+
warnForInsertedHydratedText(parentInstance, text);
16811641
}
16821642
}
16831643

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.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 & 73 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,75 +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-
// @gate !disableLegacyMode
481-
it('legacy mode can explicitly ignore errors reconnecting different element types of children', () =>
482-
expectMarkupMatch(
483-
<div>
484-
<div />
485-
</div>,
486-
<div suppressHydrationWarning={true}>
487-
<span />
488-
</div>,
489-
));
490-
491-
// @gate !disableLegacyMode
492-
it('legacy mode can explicitly ignore reconnecting more children', () =>
493-
expectMarkupMatch(
494-
<div>
495-
<div />
496-
</div>,
497-
<div suppressHydrationWarning={true}>
498-
<div />
499-
<div />
500-
</div>,
501-
));
502-
503-
// @gate !disableLegacyMode
504-
it('legacy mode can explicitly ignore reconnecting fewer children', () =>
505-
expectMarkupMatch(
506-
<div>
507-
<div />
508-
<div />
509-
</div>,
510-
<div suppressHydrationWarning={true}>
511-
<div />
512-
</div>,
513-
));
514-
515-
// @gate !disableLegacyMode
516-
it('legacy mode can explicitly ignore reconnecting reordered children', () =>
517-
expectMarkupMatch(
518-
<div suppressHydrationWarning={true}>
519-
<div />
520-
<span />
521-
</div>,
522-
<div suppressHydrationWarning={true}>
523-
<span />
524-
<div />
525-
</div>,
526-
));
527-
});

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

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,75 +1487,6 @@ describe('ReactDOMServerPartialHydration', () => {
14871487
expect(deleted.length).toBe(1);
14881488
});
14891489

1490-
// @gate !disableLegacyMode
1491-
it('warns and replaces the boundary content in legacy mode', async () => {
1492-
let suspend = false;
1493-
let resolve;
1494-
const promise = new Promise(resolvePromise => (resolve = resolvePromise));
1495-
const ref = React.createRef();
1496-
1497-
function Child() {
1498-
if (suspend) {
1499-
throw promise;
1500-
} else {
1501-
return 'Hello';
1502-
}
1503-
}
1504-
1505-
function App() {
1506-
return (
1507-
<div>
1508-
<Suspense fallback="Loading...">
1509-
<span ref={ref}>
1510-
<Child />
1511-
</span>
1512-
</Suspense>
1513-
</div>
1514-
);
1515-
}
1516-
1517-
// Don't suspend on the server.
1518-
suspend = false;
1519-
const finalHTML = ReactDOMServer.renderToString(<App />);
1520-
1521-
const container = document.createElement('div');
1522-
container.innerHTML = finalHTML;
1523-
1524-
const span = container.getElementsByTagName('span')[0];
1525-
1526-
// On the client we try to hydrate.
1527-
suspend = true;
1528-
await expect(async () => {
1529-
await act(() => {
1530-
ReactDOM.hydrate(<App />, container);
1531-
});
1532-
}).toErrorDev(
1533-
'Warning: Cannot hydrate Suspense in legacy mode. Switch from ' +
1534-
'ReactDOM.hydrate(element, container) to ' +
1535-
'ReactDOMClient.hydrateRoot(container, <App />)' +
1536-
'.render(element) or remove the Suspense components from the server ' +
1537-
'rendered components.' +
1538-
'\n in Suspense (at **)' +
1539-
'\n in div (at **)' +
1540-
'\n in App (at **)',
1541-
);
1542-
1543-
// We're now in loading state.
1544-
expect(container.textContent).toBe('Loading...');
1545-
1546-
const span2 = container.getElementsByTagName('span')[0];
1547-
// This is a new node.
1548-
expect(span).not.toBe(span2);
1549-
expect(ref.current).toBe(null);
1550-
1551-
// Resolving the promise should render the final content.
1552-
suspend = false;
1553-
await act(() => resolve());
1554-
1555-
// We should now have hydrated with a ref on the existing span.
1556-
expect(container.textContent).toBe('Hello');
1557-
});
1558-
15591490
it('can insert siblings before the dehydrated boundary', async () => {
15601491
let suspend = false;
15611492
const promise = new Promise(() => {});

0 commit comments

Comments
 (0)