Skip to content
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

[system] Use a custom sheet to set prepend for GlobalStyles #43632

Merged
merged 4 commits into from
Sep 11, 2024

Conversation

siriwatknp
Copy link
Member

@siriwatknp siriwatknp commented Sep 6, 2024

closes #43482

Root cause

Emotion does not pass prepend in GlobalStyles, see https://github.com/emotion-js/emotion/blob/main/packages/react/src/global.js#L94-L99, so the global CSS always inject at the end of head for client-side apps.

This PR create a custom sheet that will preserve the prepend flag.

Before: The text is blue index.css cannot override even using <StyledEngineProvider injectFirst>, see sandbox

After: The text is now red due to index.css overrides, see sandbox

image

@siriwatknp siriwatknp added package: system Specific to @mui/system customization: theme Centered around the theming features labels Sep 6, 2024
@mui-bot
Copy link

mui-bot commented Sep 6, 2024

Netlify deploy preview

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

@mui/joy: parsed: +0.06% , gzip: +0.08%

Bundle size report

Details of bundle changes (Toolpad)
Details of bundle changes

Generated by 🚫 dangerJS against b5b72c2

@DiegoAndai
Copy link
Member

DiegoAndai commented Sep 6, 2024

Thanks for working on this @siriwatknp!

Emotion does not pass prepend in GlobalStyles, see https://github.com/emotion-js/emotion/blob/main/packages/react/src/global.js#L94-L99, so the global CSS always inject at the end of head for client-side apps.

Does this mean that injectFirst never worked? Or is this a special case? In the CSS injection order section of our docs we use use prepend: true, is that not working either?

Emotion does not pass prepend in GlobalStyles

I agree with you that we should fix it on our side, but let's also create an issue in Emotion's repo to see if this is a bug on their side that they can eventually fix. We shouldn't wait for it, but if they eventually fix it we can simplify our implementation.

@siriwatknp
Copy link
Member Author

Does this mean that injectFirst never worked?

Yes and No, it works with styled but not GlobalStyles.

@siriwatknp
Copy link
Member Author

I agree with you that we should fix it on our side, but let's also create an issue in Emotion's repo to see if this is a bug on their side that they can eventually fix. We shouldn't wait for it, but if they eventually fix it we can simplify our implementation.

The issue is already there emotion-js/emotion#2790 (I put a comment here)

…neProvider.js

Co-authored-by: Diego Andai <[email protected]>
Signed-off-by: Siriwat K <[email protected]>
@siriwatknp siriwatknp enabled auto-merge (squash) September 10, 2024 03:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customization: theme Centered around the theming features package: system Specific to @mui/system
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CSS Variables Being Overridden After Page Load
3 participants