You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am currently using material-ui (MUI v5.6.3) along with emotion v11 and tailwindcss v3.0.15.
Emotion style/CSS files should be injected above my custom styling files so that my custom styling can have more specificity.
I observed that the order of emotion style files injected into the head tag is different on local and different on production. On local, the emotion styling files are injected on top under the head tag, which seems to be correct. But on production it is not working as expected.
Que: Am I importing StyledEngineProvider from the wrong location?
I noticed one more thing If I locally build the production using next build and serve the prod build locally using yarn start, then the order of styling file is working fine, i.e. emotion styling files are getting injected at the top. But when I deploy the production build to the actual test/live environment, the order of styling files is not as expected.
Expected behavior 🤔
The order of emotion styling/css files should be injected on top of my head tag or injected above my custom styling/css files so that the specificity of my custom styling will have more priority.
For those who are here from search, here are my findings: following an official setup example helps indeed. I had an issue with clashing MUI and Tailwind inside a Next.js app with pages router. I fixed it by copying _document.tsx and a bunch of other files from here: https://github.com/mui/material-ui/tree/master/examples
I looked into an example named material-ui-nextjs-pages-router-ts, but you may need to use a different one depending on your case. Examples may change over time, so a link to a specific one can end up broken. It’s best to check the latest ones available.
After adding <meta name="emotion-insertion-point" content="" /> to a new custom _document.tsx and copying a few more things into my codebase, the issues with prod styles were gone! Emotion styles now mount into a predictable place and seem to not ‘trump’ Tailwind ones in prod as before.
Duplicates
Latest version
Current behavior 😯
I am currently using material-ui (MUI
v5.6.3
) along with emotionv11
and tailwindcssv3.0.15
.Emotion style/CSS files should be injected above my custom styling files so that my custom styling can have more specificity.
I observed that the order of emotion style files injected into the head tag is different on local and different on production. On local, the emotion styling files are injected on top under the head tag, which seems to be correct. But on production it is not working as expected.
I have taken screenshots of both environments.
Styling files order on Local
Styling files order on Production
Currently, my code looks something like this:
Que: Am I importing StyledEngineProvider from the wrong location?
I noticed one more thing If I locally build the production using
next build
and serve the prod build locally usingyarn start
, then the order of styling file is working fine, i.e. emotion styling files are getting injected at the top. But when I deploy the production build to the actual test/live environment, the order of styling files is not as expected.Expected behavior 🤔
The order of emotion styling/css files should be injected on top of my head tag or injected above my custom styling/css files so that the specificity of my custom styling will have more priority.
Your environment 🌎
`npx @mui/envinfo`
The text was updated successfully, but these errors were encountered: