-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Current behavior:
We are getting hydration errors in development on pages that render components which are styled MUI components, after updating the following dependencies:
@emotion/cache
from11.11.0
to11.13.0
@emotion/react
from11.11.4
to11.13.0
@emotion/styled
from11.11.5
to11.13.0
Warning: Prop `className` did not match. Server: "MuiTableCell-root MuiTableCell-body MuiTableCell-sizeSmall e18whkzw0 mui-az1ynu-MuiTableCell-root-TableCellLinkContainer" Client: "MuiTableCell-root MuiTableCell-body MuiTableCell-sizeSmall e18whkzw0 mui-1odz46y-MuiTableCell-root-TableCellLinkContainer"
Notably, we did not update MUI or any related dependencies at the same time.
It only affects components created using the styled
helper, e.g.:
import styled from "@emotion/styled";
import TableRow from "@mui/material/TableRow";
const StyledTableRow = styled(TableRow)({
"&:last-child > th, &:last-child > td": {
borderBottom: 0,
},
});
export default StyledTableRow;
It seems to be a problem with one of those packages' underlying dependencies, because the issue disappears when we use the old package-lock.json
, but not if we nuke and recreate it.
I've been trying to identify the root cause but I'm finding it difficult, I'm not very familiar with the internals of emotion. I think it could be a problem with the serialiser, because the client <style>
tags being inserted look to me like the data-emotion
attributes are missing the serialized classnames that typically seem to follow the cache prefix mui
, e.g.:
It could also be a problem with the hash
package, since the hashed part of the className is different.
The issue is not present in production builds of the app.
To reproduce:
CSB: TODO later if I have some more time
- Make a styled MUI component as described above, put it on a Next.js page.
- Visit that route in a browser, open devtools.
Expected behavior:
Classnames should match on both client & server, no hydration errors.
Environment information:
"react": "^18.3.1",
"@emotion/react": "^11.13.0",
"@emotion/cache": "^11.13.0",
"@emotion/server": "^11.11.0",
"@emotion/styled": "^11.13.0",
"@mui/material": "^5.16.4",
"@mui/material-nextjs": "^5.16.4",