diff --git a/packages/react-dom-bindings/src/client/ReactDOMComponent.js b/packages/react-dom-bindings/src/client/ReactDOMComponent.js index 622b8e044951d..80ce758959927 100644 --- a/packages/react-dom-bindings/src/client/ReactDOMComponent.js +++ b/packages/react-dom-bindings/src/client/ReactDOMComponent.js @@ -251,7 +251,7 @@ function warnForExtraAttributes( ) { if (__DEV__) { attributeNames.forEach(function (attributeName) { - serverDifferences[attributeName] = + serverDifferences[getPropNameFromAttributeName(attributeName)] = attributeName === 'style' ? getStylesObjectFromElement(domElement) : domElement.getAttribute(attributeName); @@ -1829,12 +1829,24 @@ function getPossibleStandardName(propName: string): string | null { return null; } +function getPropNameFromAttributeName(attrName: string): string { + switch (attrName) { + case 'class': + return 'className'; + case 'for': + return 'htmlFor'; + // TODO: The rest of the aliases. + default: + return attrName; + } +} + export function getPropsFromElement(domElement: Element): Object { const serverDifferences: {[propName: string]: mixed} = {}; const attributes = domElement.attributes; for (let i = 0; i < attributes.length; i++) { const attr = attributes[i]; - serverDifferences[attr.name] = + serverDifferences[getPropNameFromAttributeName(attr.name)] = attr.name.toLowerCase() === 'style' ? getStylesObjectFromElement(domElement) : attr.value; diff --git a/packages/react-dom/src/__tests__/ReactDOMHydrationDiff-test.js b/packages/react-dom/src/__tests__/ReactDOMHydrationDiff-test.js index c134ab973d58c..a52bb65181c90 100644 --- a/packages/react-dom/src/__tests__/ReactDOMHydrationDiff-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMHydrationDiff-test.js @@ -94,6 +94,12 @@ describe('ReactDOMServerHydration', () => { It can also happen if the client has a browser extension installed which messes with the HTML before React loaded. https://react.dev/link/hydration-mismatch + + +
+
+ + client + - server ]", "Caught [There was an error while hydrating. Because the error happened outside of a Suspense boundary, the entire root will switch to client rendering.]", ] @@ -128,6 +134,11 @@ describe('ReactDOMServerHydration', () => { It can also happen if the client has a browser extension installed which messes with the HTML before React loaded. https://react.dev/link/hydration-mismatch + + +
+ + This markup contains an nbsp entity:   client text + - This markup contains an nbsp entity:   server text ]", "Caught [There was an error while hydrating. Because the error happened outside of a Suspense boundary, the entire root will switch to client rendering.]", ] @@ -164,6 +175,16 @@ describe('ReactDOMServerHydration', () => { It can also happen if the client has a browser extension installed which messes with the HTML before React loaded. https://react.dev/link/hydration-mismatch + + +
+
client" + - __html: "server" + }} + > ", ] `); @@ -196,6 +217,15 @@ describe('ReactDOMServerHydration', () => { It can also happen if the client has a browser extension installed which messes with the HTML before React loaded. https://react.dev/link/hydration-mismatch + + +
+
", ] `); @@ -227,6 +257,16 @@ describe('ReactDOMServerHydration', () => { It can also happen if the client has a browser extension installed which messes with the HTML before React loaded. https://react.dev/link/hydration-mismatch + + +
+
", ] `); @@ -258,6 +298,16 @@ describe('ReactDOMServerHydration', () => { It can also happen if the client has a browser extension installed which messes with the HTML before React loaded. https://react.dev/link/hydration-mismatch + + +
+
", ] `); @@ -289,6 +339,16 @@ describe('ReactDOMServerHydration', () => { It can also happen if the client has a browser extension installed which messes with the HTML before React loaded. https://react.dev/link/hydration-mismatch + + +
+
", ] `); @@ -321,6 +381,14 @@ describe('ReactDOMServerHydration', () => { It can also happen if the client has a browser extension installed which messes with the HTML before React loaded. https://react.dev/link/hydration-mismatch + + +
+
", ] `); @@ -352,6 +420,10 @@ describe('ReactDOMServerHydration', () => { It can also happen if the client has a browser extension installed which messes with the HTML before React loaded. https://react.dev/link/hydration-mismatch + + +
+ +
]", "Caught [There was an error while hydrating. Because the error happened outside of a Suspense boundary, the entire root will switch to client rendering.]", ] @@ -383,6 +455,12 @@ describe('ReactDOMServerHydration', () => { It can also happen if the client has a browser extension installed which messes with the HTML before React loaded. https://react.dev/link/hydration-mismatch + + +
+ +
+ -
+ ... ]", "Caught [There was an error while hydrating. Because the error happened outside of a Suspense boundary, the entire root will switch to client rendering.]", ] @@ -414,6 +492,13 @@ describe('ReactDOMServerHydration', () => { It can also happen if the client has a browser extension installed which messes with the HTML before React loaded. https://react.dev/link/hydration-mismatch + + +
+
+ +
+ -