Skip to content

Commit e1314a2

Browse files
committed
Fix className hydration warning for custom elements
1 parent 3499590 commit e1314a2

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,10 @@ export function getValueForAttributeOnCustomComponent(
231231
if (!isAttributeNameSafe(name)) {
232232
return;
233233
}
234+
if (enableCustomElementPropertySupport && name === 'className') {
235+
// className is a special cased property on the server to render as an attribute.
236+
name = 'class';
237+
}
234238
if (!node.hasAttribute(name)) {
235239
// shouldRemoveAttribute
236240
switch (typeof expected) {
@@ -253,10 +257,6 @@ export function getValueForAttributeOnCustomComponent(
253257
}
254258
return expected === undefined ? undefined : null;
255259
}
256-
if (enableCustomElementPropertySupport && name === 'className') {
257-
// className is a special cased property on the server to render as an attribute.
258-
name = 'class';
259-
}
260260
const value = node.getAttribute(name);
261261

262262
if (enableCustomElementPropertySupport) {

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -662,16 +662,13 @@ describe('ReactDOMServerIntegration', () => {
662662
});
663663

664664
itRenders('className for custom elements', async render => {
665+
const e = await render(<custom-element className="test" />, 0);
665666
if (ReactFeatureFlags.enableCustomElementPropertySupport) {
666-
const e = await render(
667-
<custom-element className="test" />,
668-
render === clientRenderOnServerString ? 1 : 0,
669-
);
670667
expect(e.getAttribute('className')).toBe(null);
671668
expect(e.getAttribute('class')).toBe('test');
672669
} else {
673-
const e = await render(<custom-element className="test" />, 0);
674670
expect(e.getAttribute('className')).toBe('test');
671+
expect(e.getAttribute('class')).toBe(null);
675672
}
676673
});
677674

0 commit comments

Comments
 (0)