Skip to content

[styled-engine] Prevent enableCssLayer styles from being overridden by unlayered styles#48603

Merged
Janpot merged 4 commits into
mui:masterfrom
Janpot:styled-engine/dedicated-cache-key
Jun 9, 2026
Merged

[styled-engine] Prevent enableCssLayer styles from being overridden by unlayered styles#48603
Janpot merged 4 commits into
mui:masterfrom
Janpot:styled-engine/dedicated-cache-key

Conversation

@Janpot

@Janpot Janpot commented Jun 1, 2026

Copy link
Copy Markdown
Member

Summary

This was showing up in the visual regression tests after #48575, depending on when the injectFirst fixture runs.

When enableCssLayer is set, StyledEngineProvider wraps MUI's styles in @layer mui but keeps emotion's default cache key css - the same key used by the default and injectFirst caches, which insert unlayered. Since the generated class name is ${key}-${hash}, the same style produces the same class name in both the layered and the unlayered caches. An unlayered rule outranks every cascade layer, so whenever a style ends up inserted both unlayered (default / injectFirst) and layered, the unlayered copy silently overrides MUI's own layered style.

@code-infra-dashboard

code-infra-dashboard Bot commented Jun 1, 2026

Copy link
Copy Markdown

Deploy preview

https://deploy-preview-48603--material-ui.netlify.app/

Bundle size

Bundle Parsed size Gzip size
@mui/material 🔺+8B(0.00%) 🔺+4B(0.00%)
@mui/lab 0B(0.00%) 0B(0.00%)
@mui/private-theming 0B(0.00%) 0B(0.00%)
@mui/system 🔺+8B(+0.01%) 🔺+5B(+0.02%)
@mui/utils 0B(0.00%) 0B(0.00%)

Details of bundle changes


Check out the code infra dashboard for more information about this PR.

@zannager zannager added the package: styled-engine Specific to @mui/styled-engine label Jun 1, 2026
@zannager zannager requested a review from siriwatknp June 1, 2026 12:38
@Janpot Janpot force-pushed the styled-engine/dedicated-cache-key branch 2 times, most recently from 8ecd8ba to 99c77f9 Compare June 1, 2026 13:49

@siriwatknp siriwatknp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

solid!

@Janpot Janpot merged commit 9ed7242 into mui:master Jun 9, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package: styled-engine Specific to @mui/styled-engine

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants