-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
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
[zero] Fix wrong CSS order by moving import to last #41002
Conversation
map: result.sourceMap, | ||
}; | ||
} | ||
const cssId = `./${cssFilename}`; | ||
cssFileLookup.set(cssId, cssFilename); | ||
cssLookup.set(cssFilename, cssText); | ||
return { | ||
code: `import ${JSON.stringify(`./${cssFilename}`)};\n${result.code}`, | ||
code: `${result.code}\nimport ${JSON.stringify(`./${cssFilename}`)};`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to change this for vite as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line does not affect Vite at the moment because zero-vite-plugin
is not using zero-unplugin
but I can confirm that by importing CSS first, the order is wrong even with Vite.
- result.code += `\nimport ${JSON.stringify(cssFilename)};\n`; ✅ CSS order is correct.
+ result.code = `import ${JSON.stringify(cssFilename)};\n${result.code}`; ❌ CSS order is wrong.
result.code += `\nimport ${JSON.stringify(cssFilename)};\n`; |
So I think CSS should always be imported last.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there ways to create unit tests for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@siriwatknp vite plugin and unplugin both kind of duplicate the same code. So ideally, any changes done in unplugin should also be done in vite plugin.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@oliviertassinari We could have a snapshot test for it that verifies the built css file changes. I'll have to look into how we can have a proper unit test for the build tool itself.
Netlify deploy previewhttps://deploy-preview-41002--material-ui.netlify.app/ Bundle size report |
@oliviertassinari Why would you add |
Is zero different from system? They could be the same projet, where the CSS engine is more important and where Grid, theme, are more secondary/opinionated. But fair, it's a strategic product decision, it depends on how we want to play it. In Material UI v4, it was decouple. Tailwind CSS couple them (and people seem to like this about it). Styled components/emotion decouple them. |
Issue
Wrong CSS order injection when nested components are used.
Consider Material UI Button > ButtonBase > TouchRipple
Before the change, the compiled CSS is imported at the top of the file like this:
This produces CSS is this order:
Which causes the button styles to be overridden by button base and touch ripple
Change
Just move CSS import to the last.