NextJS example with CSS Modules gives wrong order of styles
See original GitHub issue- The issue is present in the latest release.
- I have searched the issues of this repository and believe that this is not a duplicate.
Current Behavior 😯
Custom styles defined in CSS Modules appear above Material UI styles (I’m talking about the injected <style>
blocks) so they don’t override Material UI styles properly (assuming same specificity).
Expected Behavior 🤔
Custom styles defined in CSS Modules should appear below Material UI styles so they can override styles like expected.
Steps to Reproduce 🕹
https://codesandbox.io/s/sleepy-khorana-e0l22?file=/src/ProTip.js
This is a fork from the NextJS example where I moved styles from the ProTip
component to ProTip.module.scss
. I also added a color that should override the typography color to make the issue clear (it doesn’t override the typography color).
Context 🔦
I love that Material UI gives developers the options to choose their favorite styling tools as it’s shipped with hooks, HOCs and styled-components. I hope this never changes looking at the discussions about styled-components.
I’ve always been a fan of the hooks approach and been using it extensively but recently run into some issues (using React’s strict mode) that made me want to try CSS Modules again. That’s when I ran into this override issue.
Regardless of the issues with hooks I think this should be fixed somehow as it gives developers more options to choose their styling tools.
Your Environment 🌎
All environments, see CodeSandbox.
Thanks for reading! ❤
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:6 (2 by maintainers)
Top GitHub Comments
Okay the solution seems simply adding a
StylesProvider
with theinjectFirst
prop, updated my CodeSandbox to reflect that.Seems like the
StylesProvider
has some more options regarding class name generation, maybe it can fix the issue in strict mode too where the counter seems to be off by one. But that’s a different issue so I will close this one. Thanks!StyledEngineProvider is not working in MUI v5 with Next.js. Not sure if I am missing something here. Any insights would be helpful. Here’s the codesandbox forked from the Next.js example