-
-
Notifications
You must be signed in to change notification settings - Fork 32.7k
[styled-engine-sc] MUI + styled-components + Next.js CSS rules ordering issue #29742
Copy link
Copy link
Open
Labels
external dependencyBlocked by external dependency, we can’t do anything about it.Blocked by external dependency, we can’t do anything about it.nextjspackage: styled-engine-scSpecific to styled-componentsSpecific to styled-componentspriority: importantThis change can make a difference.This change can make a difference.scope: systemThe system, the design tokens / styling foundations used across components. eg. @mui/system with MUIThe system, the design tokens / styling foundations used across components. eg. @mui/system with MUItype: bugIt doesn't behave as expected.It doesn't behave as expected.
Metadata
Metadata
Assignees
Labels
external dependencyBlocked by external dependency, we can’t do anything about it.Blocked by external dependency, we can’t do anything about it.nextjspackage: styled-engine-scSpecific to styled-componentsSpecific to styled-componentspriority: importantThis change can make a difference.This change can make a difference.scope: systemThe system, the design tokens / styling foundations used across components. eg. @mui/system with MUIThe system, the design tokens / styling foundations used across components. eg. @mui/system with MUItype: bugIt doesn't behave as expected.It doesn't behave as expected.
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