+
`;
exports[`enzyme shallow with array of styles in a composite inner child 1`] = `
-.emotion-0 {
- background-color: black;
- color: white;
-}
-
Test content
@@ -592,13 +666,9 @@ exports[`enzyme shallow with array of styles in a composite inner child 1`] = `
`;
exports[`enzyme shallow with prop containing css element 1`] = `
-.emotion-0 {
- background-color: blue;
-}
-
Hello
@@ -625,10 +695,6 @@ exports[`enzyme shallow with prop containing css element not at the top level 1`
`;
exports[`enzyme shallow with prop containing css element with other label 1`] = `
-.emotion-0 {
- background-color: blue;
-}
-
Hello
@@ -648,13 +714,9 @@ exports[`enzyme shallow with prop containing css element with other label 1`] =
`;
exports[`enzyme shallow with prop containing css element with other props 1`] = `
-.emotion-0 {
- background-color: blue;
-}
-
Hello
@@ -675,11 +737,14 @@ exports[`enzyme shallow with styles on top level 1`] = `
background-color: red;
}
-
- Hello
-
+
+
+
+ Hello
+
+
`;
exports[`enzyme with prop containing css element in fragment 1`] = `
@@ -689,10 +754,13 @@ exports[`enzyme with prop containing css element in fragment 1`] = `
x
-
- y
-
+ Array [
+ "",
+
+ y
+
,
+ ]
`;
diff --git a/packages/react/src/class-names.js b/packages/react/src/class-names.js
index 1ac618f3bb..deabcdce78 100644
--- a/packages/react/src/class-names.js
+++ b/packages/react/src/class-names.js
@@ -88,6 +88,8 @@ type Props = {
}) => React.Node
}
+const Noop = () => null
+
export const ClassNames: React.AbstractComponent =
/* #__PURE__ */ withEmotionCache((props, cache) => {
let rules = ''
@@ -125,21 +127,25 @@ export const ClassNames: React.AbstractComponent =
}
let ele = props.children(content)
hasRendered = true
+ let possiblyStyleElement =
if (!isBrowser && rules.length !== 0) {
- return (
- <>
-
- {ele}
- >
+ possiblyStyleElement = (
+
)
}
- return ele
+ // Need to return the same number of siblings or else `React.useId` will cause hydration mismatches.
+ return (
+ <>
+ {possiblyStyleElement}
+ {ele}
+ >
+ )
})
if (process.env.NODE_ENV !== 'production') {
diff --git a/packages/react/src/emotion-element.js b/packages/react/src/emotion-element.js
index 8330c14acf..8514f93767 100644
--- a/packages/react/src/emotion-element.js
+++ b/packages/react/src/emotion-element.js
@@ -57,6 +57,8 @@ export const createEmotionProps = (type: React.ElementType, props: Object) => {
return newProps
}
+const Noop = () => null
+
let Emotion = /* #__PURE__ */ withEmotionCache(
(props, cache, ref) => {
let cssProp = props.css
@@ -121,6 +123,7 @@ let Emotion = /* #__PURE__ */ withEmotionCache(
newProps.className = className
const ele = React.createElement(type, newProps)
+ let possiblyStyleElement =
if (!isBrowser && rules !== undefined) {
let serializedNames = serialized.name
let next = serialized.next
@@ -128,20 +131,23 @@ let Emotion = /* #__PURE__ */ withEmotionCache(
serializedNames += ' ' + next.name
next = next.next
}
- return (
- <>
-
- {ele}
- >
+ possiblyStyleElement = (
+
)
}
- return ele
+ // Need to return the same number of siblings or else `React.useId` will cause hydration mismatches.
+ return (
+ <>
+ {possiblyStyleElement}
+ {ele}
+ >
+ )
}
)