-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
[styled-engine-sc] MUI + styled-components + Next.js CSS rules ordering issue #29742
Comments
Today I've tried same code with example using emotion (no Maybe it's |
I've tried wrapping components tree with |
@mnajdova could you please take a look at this one? |
+1 this, found I didn't remove emotion completely and added in the required to my package.json (I'm using yarn if it makes any difference here)
Now upon a deployment I've found my emotion is correctly removed but I have now styling inconsistencies. Edit: It looks like there are several instances of 'styled-components' initialized in this application. This may cause dynamic styles to not render properly, errors during the rehydration process, a missing theme prop, and makes your application bigger without good reason. Haven't checked if this is occurring in a fresh NextJs, Material ui, styled-components but is probably my next step. Edit again: Further investigation found #24109 which the moral of the story is inconsistencies with styling in injection order due to emotion / styled-components and seems to have been removed from the milestone v5.1 |
For now the only solution that I've found, was to switch my whole project to emotion... |
@zibra not my favourite resolution but also the direction I'll probably take. |
This is the same issue as #29210 , the problem is the compatibility with the |
@AndyW22 Is it the same problem? I noticed in your example you don't use the provided example from material so therefore you are lacking the custom Link component. that they provide. In the sandbox url above the Link component provided by the example is the one being utilised. |
unfortunately their example repo doesnt actually use styled components at all, it simply sets it up in the project but doesnt use the I also added it to the sandbox example and the same issue occurs at the same time as the other styling bugs, and, like with my example, using an |
I will look more into this tomorrow and post my findings |
I spent some time on this today, but haven't resolved it. At the start I thought the issue is that the On this matter, I found the topLevelImportPaths option thanks to https://xstyled.dev/docs/migrate-from-styled-components/#babel-plugin (thank you @gregberge :)) I've tried updating the .babelrc
There were some issues thrown at the start, that indicated that package.json
This did not work too. I even tried transpaling the mui packages using: next.config.js
But with no luck. the issue was still there. If someone wants to push further the investigation, make sure to use the packages from #29873, for example:
I've pushed what I've tried in #29873 |
cc @mui-org/core maybe someone will have a better idea than me |
Similar issues found on the styled-components repo:
|
I have the same problem on my project |
One more update on the test project in #29873 I've copied our Typography component from mui locally there (I literally just changed the imports) and even added the custom |
I don't think I will have much more time to spend on this, but if someone from the community wants to help I can provide some guidance. |
@mnajdova thanks for looking into it! Just had a busy week at work myself, I'll look into what you've done over the weekend and might touch base if you don't mind. |
I am facing the same issue. Is there anything one can do to fix it in the meantime? |
@kdelmonte we haven't find any solution to this problem yet, and it looks like there is no response to:
|
Thank you @mnajdova. I migrated yesterday to emotion because I could not wait anymore and like you say, the migration was pretty easy. Thanks again. |
Sure thing @kdelmonte, and sorry for the delayed answer. |
I have a PR up to fix styled-components/babel-plugin-styled-components#365: styled-components/babel-plugin-styled-components#380 However I haven't made a fix for styled-components/babel-plugin-styled-components#364. |
@rbong I haven't been looking into this for quite some time. I can try to refresh my view on it next week and provide more feedback if I can. Thanks a lot for the effort put there 🙏 |
@mnajdova Any new updates on this issue? |
As far as I know, we are still blocked by styled-components/babel-plugin-styled-components#365 and styled-components/babel-plugin-styled-components#364. There wasn't much activity there honestly, I left now comment on one of the issues. Haven't tested with nextjs 13 if that makes any difference, but I doubt honestly. |
Any new updates on this issue? |
Hello, is there a plan how to fix this? 🙏 |
Nota: Essa solução foi compartilhada comigo por meio de um colega de trabalho. Vale a pena o teste. Solução: Aqui está um exemplo de como fazer isso:
Essas etapas devem ajudar a resolver o problema de incompatibilidade entre o Material UI, o Emotion e o Next.js SSR. Vale ressaltar que estou compartilhando com o intuito de ajudar quem chegou agora e está procurando essa resposta. Caso haja algum erro só informar que eu edito o post para corrigir. |
@mircea-dinoiu that is really encouraging news! Any chance you could share some code examples of your working setup? Particularly your Even after upgrading to styled-components v6 I still get the |
I tried creating a brand new repository using Next.js 13, Material UI + styled-components v6, but the same problems arise. This is the testing repo: https://github.com/mnajdova/nextjs13-material-ui-styled-components. Unfortunately, we still need to apply the If someone is interested in looking into more details, check the repository and maybe we can start with opening issues about the specific mentioned in #29742 (comment) this time on next.js repository, as they are the one who offers now in house support for this in their config. |
This comment was marked as off-topic.
This comment was marked as off-topic.
tag me when it is closed please :) |
The only solution I found was add this to resolutions, they recommend use latest, but for me only worked if I specify this version: |
I had a issue with MUI lab on v4 where the styles of
|
Duplicates
Latest version
Current behavior 😯
Next.js projects using MUI + styled-components based on the example configuration from:\ have incorrect MUI components styling on production. The order of the CSS rules is different from SSR and after hydration.
Expected behavior 🤔
UI elements looks always same (on dev run and on production). CSS rules are applied always in the same order.
Steps to reproduce 🕹
Steps:
Video preview:
https://www.youtube.com/watch?v=A0dqNA8IO4Q
Context 🔦
When I was testing it locally it happened only on production builds, but in code sandbox it happens also on development mode. Just css class order is different between dev and prod.
Privided code sanbox is a fork for from official example from: https://github.com/mui-org/material-ui/tree/master/examples/nextjs-with-styled-components-typescript
I've just added 2 more buttons.
There are different states for the buttons depending on the scenario:
Correct styling:
Incorrect styling:
CSS rules order comparison:
Your environment 🌎
I've tested this issue on Windows 10, Mac OS, AWS Amplify and at the end I've found that it also happens on CodeSandbox example. Always with latest versions with MUI, Next, node and styled-components
The text was updated successfully, but these errors were encountered: