Skip to content

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 scope: system The system, the design tokens / styling foundations used across components. eg. @mui/system with MUI customization: theme Higher level theming customizability. 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 <diego@mui.com>
Signed-off-by: Siriwat K <siriwatkunaporn@gmail.com>
@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 Higher level theming customizability. scope: system The system, the design tokens / styling foundations used across components. eg. @mui/system with MUI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CSS Variables Being Overridden After Page Load

3 participants