Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@emotion/server css prefix key mismatch #3275

Open
nikandlv opened this issue Nov 22, 2024 · 0 comments
Open

@emotion/server css prefix key mismatch #3275

nikandlv opened this issue Nov 22, 2024 · 0 comments

Comments

@nikandlv
Copy link

Current behavior:

The key property is ignored and css prefix is used instead of the provided cache key

Code

import createCache from "@emotion/cache";
import { Direction } from "@mui/material";
import { prefixer } from "stylis";

export default function createEmotionCache(customKey: string) {
  return createCache({
    key: `anything-${customKey}`,

    stylisPlugins:  [prefixer],
  });
}


const { renderStylesToString } = createEmotionServer(cache);
const initialProps = await Document.getInitialProps(ctx);
console.log(renderStylesToString(initialProps.html));

Output example

.css-17ajgef-MuiButtonBase-root-MuiButton-root::-moz-focus-inner{
    border-style:none;
}
.css-17ajgef-MuiButtonBase-root-MuiButton-root.Mui-disabled{
    pointer-events:none;
    cursor:default;
}

To reproduce:

Render the styles with nextjs server side

Expected behavior:

Use the provided cache key instead
This does work properly on the client side but not on the server

Environment information:

"@emotion/cache": "^11.13.5",
"@emotion/react": "^11.13.5",
"@emotion/server": "^11.11.0",
"@emotion/styled": "^11.13.5",
"@mui/material": "^6.1.8",
"@mui/material-nextjs": "^6.1.8",
"@types/stylis": "^4.2.6",
"i18next": "^23.16.8",
"jotai": "^2.10.3",
"next": "15.0.3",
"next-i18next": "^15.3.1",
"react": "18.3.1",
"react-dom": "18.3.1",
"react-i18next": "^15.1.1",
"stylis": "^4.3.4",
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant