-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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
[examples] Nextjs CSS modules insert before emotion #29648
Comments
Seems like it is your mistake in SCSS file. .LightBulb {
color: orange; // "orange" does not work, double-quote is invalid in CSS.
} Here is a working sandbox I fork from you. https://codesandbox.io/s/peaceful-solomon-d0db0?file=/src/ProTip.js |
My bad! But I don't see this working for some reason in our application. The MUI styles keep loading after my CSS despite the StyledEngineProvider hook. Any thoughts based on your experience? |
@siriwatknp Actually, this is still not working. Notice the margin css I added in my original sandbox. That's not taking affect and this is the screenshot from the developer tools. See MUI margin css took precedence over mine |
I dig a little bit deeper and I guess this is on NextJS. If you look at how NextJS insert style to head, you will see that the CSS (including SCSS) stylesheet is injected before the Related issues about injection order: |
@siriwatknp Thanks for debugging this 👍🏻 |
I also struggled with this when trying to upgrade next.js (12) with (s)cssmodules to mui v5. I found that I had to add const cache = createCache({
key: 'css',
prepend: true,
}); I tested it in both dev and prod build and now my global and cssmodule injection order seems to be correct. Hope this might help. |
@ShuPink Thanks for the info! @PraveenPeri Can you try it out? |
@ShuPink @siriwatknp Thanks for the workaround! That resolved the issue |
Anyone who would like to submit a PR to improve the example and docs is welcome! |
I dig a little bit deeper. At the built time, emotion styles are not at the top of |
@siriwatknp Yes FOUC effect for my custom css module styles happens, if user has a slow internet connection, my custom styles don't apply until the site is hydrated, even though I'm using |
#30381 should also improve the integration with Tailwind CSS with the In the future, I think that we could consider having more examples. For instance, we could have:
|
@oliviertassinari I think now we need other examples to accommodate for the experimental
In |
Duplicates
Latest version
Current behavior 😯
Trying to override MUI styles through .scss file isn't working in v5 and Next.js. I could repro the issue in the codesandbox forked your official Next.js example. This is same problem we are facing in our application where the css is loaded before MUI styles even with
StyledEngineProvider
hook.Expected behavior 🤔
MUI styles should be loaded into the page before the css so that custom styles can take effect
Steps to reproduce 🕹
Steps:
StyledEngineProvider
hook to ensure the correct injection orderContext 🔦
No response
Your environment 🌎
`npx @mui/envinfo`
The text was updated successfully, but these errors were encountered: