[v5] CSS injection order is wrong
See original GitHub issueI’m using the following pattern in my code, but it doesn’t work anymore in v5 (tested with 5.0.0-alpha.20). My custom styles get overwritten by other styles (likely coming from the new styling mechanism):
const styles = theme => ({
title: {
[theme.breakpoints.down('sm')]: theme.typography.body1
}
})
function App({ classes }) {
return <Typography variant="h5" classes={{h5:classes.title}}>Hello</Typography>;
}
const StyledApp = withStyles(styles)(App);
Issue Analytics
- State:
- Created 3 years ago
- Reactions:22
- Comments:59 (35 by maintainers)
Top Results From Across the Web
Style tag seems to be in the wrong order when updating to ...
I found something in the doc of material-ui about css injection order but seems like it doesn't relate to this kind of situation....
Read more >Material UI v5 CSS injection order - CodeSandbox
VS Code's tsserver was deleted by another application such as a misbehaving virus detection tool. Please reinstall VS Code. Manage Extension.
Read more >Releases - styled-components
Escape every CSS ident character necessary when converting component ... Backport fix where classnames are composed in the wrong order if custom class...
Read more >Style library interoperability - Material UI - MUI
Note: Most CSS-in-JS solutions inject their styles at the bottom of the HTML ... In order for the injection order to still be...
Read more >JSS integration with React
Critical CSS extraction - only CSS from rendered components gets extracted. ... Custom setup; Multi-tree setup; Injection order; Usage with TypeScript ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I was aware of
injectFirst
attribute, but it didn’t work in my app. After some testing with the codesandbox, it appears the problem come from importingStylesProvider
from@material-ui/core/styles
(v4 code, which I’m currently migrating) instead of@material-ui/core
. You can verify that in your codesandbox.@goffioul now that the Typography, Button, etc components are migrated to emotion, you need to use the
StylesProvider
exported from ‘@material-ui/core’ with theinjectFirst
option, in order for the CSS injection order to be correct between emotion and JSS. It is explained here: https://next.material-ui.com/guides/interoperability/#css-injection-order.This is only required for the time of the migration (v5-alpha phase). Once we do no longer depend on JSS, the order should be correct.
Here is a codesandbox with a working example - https://codesandbox.io/s/devtools-material-demo-forked-ethyg?file=/index.js You will notice that the
<Demo />
is wrapped with theStylesProvider
component.