Skip to content

Commit 0f3b777

Browse files
committed
Back out #28476 and #28458
Back out "Move Hydration Warnings from the DOM Config into the Fiber reconciliation (#28476)" Original commit changeset: 4b8dfd6 Back out "Remove enableClientRenderFallbackOnTextMismatch flag (#28458)" Original commit changeset: 84c84d7
1 parent 4b8dfd6 commit 0f3b777

27 files changed

+859
-660
lines changed

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

Lines changed: 159 additions & 222 deletions
Large diffs are not rendered by default.

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

Lines changed: 187 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,14 @@ import {hasRole} from './DOMAccessibilityRoles';
5252
import {
5353
setInitialProperties,
5454
updateProperties,
55-
hydrateProperties,
56-
hydrateText,
5755
diffHydratedProperties,
58-
getPropsFromElement,
5956
diffHydratedText,
6057
trapClickOnNonInteractiveElement,
58+
checkForUnmatchedText,
59+
warnForDeletedHydratableElement,
60+
warnForDeletedHydratableText,
61+
warnForInsertedHydratedElement,
62+
warnForInsertedHydratedText,
6163
} from './ReactDOMComponent';
6264
import {getSelectionInformation, restoreSelection} from './ReactInputSelection';
6365
import setTextContent from './setTextContent';
@@ -1340,26 +1342,6 @@ export function getFirstHydratableChildWithinSuspenseInstance(
13401342
return getNextHydratable(parentInstance.nextSibling);
13411343
}
13421344

1343-
export function describeHydratableInstanceForDevWarnings(
1344-
instance: HydratableInstance,
1345-
): string | {type: string, props: $ReadOnly<Props>} {
1346-
// Reverse engineer a pseudo react-element from hydratable instnace
1347-
if (instance.nodeType === ELEMENT_NODE) {
1348-
// Reverse engineer a set of props that can print for dev warnings
1349-
return {
1350-
type: instance.nodeName.toLowerCase(),
1351-
props: getPropsFromElement((instance: any)),
1352-
};
1353-
} else if (instance.nodeType === COMMENT_NODE) {
1354-
return {
1355-
type: 'Suspense',
1356-
props: {},
1357-
};
1358-
} else {
1359-
return instance.nodeValue;
1360-
}
1361-
}
1362-
13631345
export function validateHydratableInstance(
13641346
type: string,
13651347
props: Props,
@@ -1379,23 +1361,14 @@ export function hydrateInstance(
13791361
props: Props,
13801362
hostContext: HostContext,
13811363
internalInstanceHandle: Object,
1382-
): boolean {
1364+
shouldWarnDev: boolean,
1365+
): void {
13831366
precacheFiberNode(internalInstanceHandle, instance);
13841367
// TODO: Possibly defer this until the commit phase where all the events
13851368
// get attached.
13861369
updateFiberProps(instance, props);
13871370

1388-
return hydrateProperties(instance, type, props, hostContext);
1389-
}
1390-
1391-
// Returns a Map of properties that were different on the server.
1392-
export function diffHydratedPropsForDevWarnings(
1393-
instance: Instance,
1394-
type: string,
1395-
props: Props,
1396-
hostContext: HostContext,
1397-
): null | $ReadOnly<Props> {
1398-
return diffHydratedProperties(instance, type, props, hostContext);
1371+
diffHydratedProperties(instance, type, props, shouldWarnDev, hostContext);
13991372
}
14001373

14011374
export function validateHydratableTextInstance(
@@ -1416,26 +1389,11 @@ export function hydrateTextInstance(
14161389
textInstance: TextInstance,
14171390
text: string,
14181391
internalInstanceHandle: Object,
1419-
parentInstanceProps: null | Props,
1392+
shouldWarnDev: boolean,
14201393
): boolean {
14211394
precacheFiberNode(internalInstanceHandle, textInstance);
14221395

1423-
return hydrateText(textInstance, text, parentInstanceProps);
1424-
}
1425-
1426-
// Returns the server text if it differs from the client.
1427-
export function diffHydratedTextForDevWarnings(
1428-
textInstance: TextInstance,
1429-
text: string,
1430-
parentProps: null | Props,
1431-
): null | string {
1432-
if (
1433-
parentProps === null ||
1434-
parentProps[SUPPRESS_HYDRATION_WARNING] !== true
1435-
) {
1436-
return diffHydratedText(textInstance, text);
1437-
}
1438-
return null;
1396+
return diffHydratedText(textInstance, text);
14391397
}
14401398

14411399
export function hydrateSuspenseInstance(
@@ -1527,6 +1485,183 @@ export function shouldDeleteUnhydratedTailInstances(
15271485
return parentType !== 'form' && parentType !== 'button';
15281486
}
15291487

1488+
export function didNotMatchHydratedContainerTextInstance(
1489+
parentContainer: Container,
1490+
textInstance: TextInstance,
1491+
text: string,
1492+
shouldWarnDev: boolean,
1493+
) {
1494+
checkForUnmatchedText(textInstance.nodeValue, text, shouldWarnDev);
1495+
}
1496+
1497+
export function didNotMatchHydratedTextInstance(
1498+
parentType: string,
1499+
parentProps: Props,
1500+
parentInstance: Instance,
1501+
textInstance: TextInstance,
1502+
text: string,
1503+
shouldWarnDev: boolean,
1504+
) {
1505+
if (parentProps[SUPPRESS_HYDRATION_WARNING] !== true) {
1506+
checkForUnmatchedText(textInstance.nodeValue, text, shouldWarnDev);
1507+
}
1508+
}
1509+
1510+
export function didNotHydrateInstanceWithinContainer(
1511+
parentContainer: Container,
1512+
instance: HydratableInstance,
1513+
) {
1514+
if (__DEV__) {
1515+
if (instance.nodeType === ELEMENT_NODE) {
1516+
warnForDeletedHydratableElement(parentContainer, (instance: any));
1517+
} else if (instance.nodeType === COMMENT_NODE) {
1518+
// TODO: warnForDeletedHydratableSuspenseBoundary
1519+
} else {
1520+
warnForDeletedHydratableText(parentContainer, (instance: any));
1521+
}
1522+
}
1523+
}
1524+
1525+
export function didNotHydrateInstanceWithinSuspenseInstance(
1526+
parentInstance: SuspenseInstance,
1527+
instance: HydratableInstance,
1528+
) {
1529+
if (__DEV__) {
1530+
// $FlowFixMe[incompatible-type]: Only Element or Document can be parent nodes.
1531+
const parentNode: Element | Document | null = parentInstance.parentNode;
1532+
if (parentNode !== null) {
1533+
if (instance.nodeType === ELEMENT_NODE) {
1534+
warnForDeletedHydratableElement(parentNode, (instance: any));
1535+
} else if (instance.nodeType === COMMENT_NODE) {
1536+
// TODO: warnForDeletedHydratableSuspenseBoundary
1537+
} else {
1538+
warnForDeletedHydratableText(parentNode, (instance: any));
1539+
}
1540+
}
1541+
}
1542+
}
1543+
1544+
export function didNotHydrateInstance(
1545+
parentType: string,
1546+
parentProps: Props,
1547+
parentInstance: Instance,
1548+
instance: HydratableInstance,
1549+
) {
1550+
if (__DEV__) {
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));
1557+
}
1558+
}
1559+
}
1560+
1561+
export function didNotFindHydratableInstanceWithinContainer(
1562+
parentContainer: Container,
1563+
type: string,
1564+
props: Props,
1565+
) {
1566+
if (__DEV__) {
1567+
warnForInsertedHydratedElement(parentContainer, type, props);
1568+
}
1569+
}
1570+
1571+
export function didNotFindHydratableTextInstanceWithinContainer(
1572+
parentContainer: Container,
1573+
text: string,
1574+
) {
1575+
if (__DEV__) {
1576+
warnForInsertedHydratedText(parentContainer, text);
1577+
}
1578+
}
1579+
1580+
export function didNotFindHydratableSuspenseInstanceWithinContainer(
1581+
parentContainer: Container,
1582+
) {
1583+
if (__DEV__) {
1584+
// TODO: warnForInsertedHydratedSuspense(parentContainer);
1585+
}
1586+
}
1587+
1588+
export function didNotFindHydratableInstanceWithinSuspenseInstance(
1589+
parentInstance: SuspenseInstance,
1590+
type: string,
1591+
props: Props,
1592+
) {
1593+
if (__DEV__) {
1594+
// $FlowFixMe[incompatible-type]: Only Element or Document can be parent nodes.
1595+
const parentNode: Element | Document | null = parentInstance.parentNode;
1596+
if (parentNode !== null)
1597+
warnForInsertedHydratedElement(parentNode, type, props);
1598+
}
1599+
}
1600+
1601+
export function didNotFindHydratableTextInstanceWithinSuspenseInstance(
1602+
parentInstance: SuspenseInstance,
1603+
text: string,
1604+
) {
1605+
if (__DEV__) {
1606+
// $FlowFixMe[incompatible-type]: Only Element or Document can be parent nodes.
1607+
const parentNode: Element | Document | null = parentInstance.parentNode;
1608+
if (parentNode !== null) warnForInsertedHydratedText(parentNode, text);
1609+
}
1610+
}
1611+
1612+
export function didNotFindHydratableSuspenseInstanceWithinSuspenseInstance(
1613+
parentInstance: SuspenseInstance,
1614+
) {
1615+
if (__DEV__) {
1616+
// const parentNode: Element | Document | null = parentInstance.parentNode;
1617+
// TODO: warnForInsertedHydratedSuspense(parentNode);
1618+
}
1619+
}
1620+
1621+
export function didNotFindHydratableInstance(
1622+
parentType: string,
1623+
parentProps: Props,
1624+
parentInstance: Instance,
1625+
type: string,
1626+
props: Props,
1627+
) {
1628+
if (__DEV__) {
1629+
warnForInsertedHydratedElement(parentInstance, type, props);
1630+
}
1631+
}
1632+
1633+
export function didNotFindHydratableTextInstance(
1634+
parentType: string,
1635+
parentProps: Props,
1636+
parentInstance: Instance,
1637+
text: string,
1638+
) {
1639+
if (__DEV__) {
1640+
warnForInsertedHydratedText(parentInstance, text);
1641+
}
1642+
}
1643+
1644+
export function didNotFindHydratableSuspenseInstance(
1645+
parentType: string,
1646+
parentProps: Props,
1647+
parentInstance: Instance,
1648+
) {
1649+
if (__DEV__) {
1650+
// TODO: warnForInsertedHydratedSuspense(parentInstance);
1651+
}
1652+
}
1653+
1654+
export function errorHydratingContainer(parentContainer: Container): void {
1655+
if (__DEV__) {
1656+
// TODO: This gets logged by onRecoverableError, too, so we should be
1657+
// able to remove it.
1658+
console.error(
1659+
'An error occurred during hydration. The server HTML was replaced with client content in <%s>.',
1660+
parentContainer.nodeName.toLowerCase(),
1661+
);
1662+
}
1663+
}
1664+
15301665
// -------------------
15311666
// Test Selectors
15321667
// -------------------

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2407,8 +2407,8 @@ describe('ReactDOMFizzServer', () => {
24072407
]);
24082408
}).toErrorDev(
24092409
[
2410-
'Warning: An error occurred during hydration. The server HTML was replaced with client content.',
2411-
'Warning: Expected server HTML to contain a matching <div> in the root.\n' +
2410+
'Warning: An error occurred during hydration. The server HTML was replaced with client content in <div>.',
2411+
'Warning: Expected server HTML to contain a matching <div> in <div>.\n' +
24122412
' in div (at **)\n' +
24132413
' in App (at **)',
24142414
],
@@ -2492,7 +2492,7 @@ describe('ReactDOMFizzServer', () => {
24922492
}).toErrorDev(
24932493
[
24942494
'Warning: An error occurred during hydration. The server HTML was replaced with client content',
2495-
'Warning: Expected server HTML to contain a matching <div> in the root.\n' +
2495+
'Warning: Expected server HTML to contain a matching <div> in <div>.\n' +
24962496
' in div (at **)\n' +
24972497
' in App (at **)',
24982498
],
@@ -4419,6 +4419,7 @@ describe('ReactDOMFizzServer', () => {
44194419
);
44204420
});
44214421

4422+
// @gate enableClientRenderFallbackOnTextMismatch
44224423
it('#24384: Suspending should halt hydration warnings but still emit hydration warnings after unsuspending if mismatches are genuine', async () => {
44234424
const makeApp = () => {
44244425
let resolve, resolved;
@@ -4504,6 +4505,7 @@ describe('ReactDOMFizzServer', () => {
45044505
await waitForAll([]);
45054506
});
45064507

4508+
// @gate enableClientRenderFallbackOnTextMismatch
45074509
it('only warns once on hydration mismatch while within a suspense boundary', async () => {
45084510
const originalConsoleError = console.error;
45094511
const mockError = jest.fn();
@@ -6343,7 +6345,7 @@ describe('ReactDOMFizzServer', () => {
63436345
await waitForAll([]);
63446346
}).toErrorDev(
63456347
[
6346-
'Expected server HTML to contain a matching <span> in the root',
6348+
'Expected server HTML to contain a matching <span> in <div>',
63476349
'An error occurred during hydration',
63486350
],
63496351
{withoutStack: 1},

0 commit comments

Comments
 (0)