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

ClassName generator not working with Next.js App router #45128

Open
NotYoojun opened this issue Jan 27, 2025 · 4 comments
Open

ClassName generator not working with Next.js App router #45128

NotYoojun opened this issue Jan 27, 2025 · 4 comments
Assignees
Labels
bug 🐛 Something doesn't work nextjs package: material-ui Specific to @mui/material package: utils Specific to the @mui/utils package

Comments

@NotYoojun
Copy link

NotYoojun commented Jan 27, 2025

Steps to reproduce

Steps:

  1. Open this link to live example: click here
  2. npm run dev
  3. Open the devtools and inspect the element tree

Current behavior

All the class names stay unchanged:

Image

Expected behavior

All class names should be transformed by the ClassNameGenerator.

Context

I also tried to import the 'init-cls.ts' as a client script, but that only affects the client side, and the server side is just doing nothing.
I'm following this doc: https://mui.com/material-ui/experimental-api/classname-generator/

Your environment

System:
OS: Linux 6.1 Debian GNU/Linux 12 (bookworm) 12 (bookworm)
Binaries:
Node: 20.9.0 - /usr/local/bin/node
npm: 9.8.1 - /usr/local/bin/npm
pnpm: 8.10.2 - /usr/local/share/npm-global/bin/pnpm
Browsers:
Chrome: Not Found
npmPackages:
@emotion/react: latest => 11.11.1
@emotion/styled: latest => 11.11.0
@mui/core-downloads-tracker: 6.0.0
@mui/icons-material: latest => 6.0.0
@mui/material: latest => 6.0.0
@mui/material-nextjs: latest => 6.0.0
@mui/private-theming: 6.0.0
@mui/styled-engine: 6.0.0
@mui/system: 6.0.0
@mui/types: 7.2.16
@mui/utils: 6.0.0
@types/react: ^19.0.0 => 19.0.2
react: ^19.0.0 => 19.0.0
react-dom: ^19.0.0 => 19.0.0
typescript: latest => 5.1.6

Search keywords: next, nextjs, app, classname, styles, experimental, css, class

@NotYoojun NotYoojun added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Jan 27, 2025
@zannager zannager added package: system Specific to @mui/system nextjs labels Jan 27, 2025
@NotYoojun
Copy link
Author

Anyone looking into this? please

@aarongarciah
Copy link
Member

Hi @NotYoojun, the CodeSandbox link is broken. Can you share a reproduction?

@NotYoojun
Copy link
Author

@aarongarciah Hi, what about this one?
https://codesandbox.io/p/devbox/mre-mui-cssclassgenerator-next-appdir-dp4zz2

@aarongarciah aarongarciah added package: material-ui Specific to @mui/material package: utils Specific to the @mui/utils package and removed package: system Specific to @mui/system labels Feb 11, 2025
@aarongarciah
Copy link
Member

@NotYoojun that sandbox works. We still not have a guide for Next.js App router specifically (and React Server Components in general) in the docs.

@siriwatknp is there a recommendation? It kinda works if you import the class name generator module in page.tsx instead of layout.tsx, but it's obviously not a good solution (the "entry" point is layout.tsx, but it's a RSC) and it's buggy: it duplicates the prefix in the Box component (probably calls twice the generator function). See this sandbox: https://codesandbox.io/p/devbox/mre-mui-cssclassgenerator-next-appdir-forked-mcj7gm?workspaceId=ws_TYgwg9BhnaH6MHvmXJ1vH9

@aarongarciah aarongarciah added bug 🐛 Something doesn't work and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work nextjs package: material-ui Specific to @mui/material package: utils Specific to the @mui/utils package
Projects
None yet
Development

No branches or pull requests

4 participants