Wrong css injection order with multiple react apps
See original GitHub issue- This is not a v0.x issue.
- I have searched the issues of this repository and believe that this is not a duplicate.
Expected Behavior 🤔
Css injection order should be like this: App1 MUI CSS App1 overrides CSS App2 MUI CSS App2 overrides CSS
Current Behavior 😯
Css injection order is currently like this: App1 MUI CSS App1 overrides CSS App2 overrides CSS App2 MUI CSS
This is how it looks on Chrome devtools:
App on Chrome:
Steps to Reproduce 🕹
- Create a page with 2 react apps that both use MUI
- Create some custom styles on each app
- View on the browser, only the first app overrides are visible
Your Environment 🌎
Tech | Version |
---|---|
Material-UI | v3.9.0 |
React | 16.7.0 |
Browser | Chrome |
TypeScript | 3.3.0 |
App1 Code
import { Button, createGenerateClassName, createStyles, jssPreset, withStyles } from '@material-ui/core';
import { create } from 'jss';
import * as React from 'react';
import JssProvider from 'react-jss/lib/JssProvider';
const jss = (create as any)({ plugins: [...jssPreset().plugins] });
const generateClassName = createGenerateClassName({ productionPrefix: 'app1_' });
const styles = createStyles({
button: {
backgroundColor: 'blue',
},
});
export const App = withStyles(styles)(({ classes }) => (
<JssProvider jss={jss} generateClassName={generateClassName}>
<Button className={classes.button}>App1</Button>
</JssProvider>
));
App2 Code
import { Button, createGenerateClassName, createStyles, jssPreset, withStyles } from '@material-ui/core';
import { create } from 'jss';
import * as React from 'react';
import JssProvider from 'react-jss/lib/JssProvider';
const jss = (create as any)({ plugins: [...jssPreset().plugins] });
const generateClassName = createGenerateClassName({ productionPrefix: 'app2_' });
const styles = createStyles({
button: {
backgroundColor: 'red',
},
});
export const App = withStyles(styles)(({ classes }) => (
<JssProvider jss={jss} generateClassName={generateClassName}>
<Button className={classes.button}>App1</Button>
</JssProvider>
));
Example:
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
Wrong css injection order with multiple react apps #14338
I have searched the issues of this repository and believe that this is not a duplicate. Expected Behavior. Css injection order should be...
Read more >Bad injection CSS order when change history with React ...
I having an issue with CSS injection order using material-ui components and theme providers, when I use react router dom .
Read more >Styling in React: 5 ways to style React apps - LogRocket Blog
In this article, we will review styling React components with inline styling, styled-components, CSS modules, Tailwind CSS, and Sass and CSS ...
Read more >Releases - styled-components
Fix speedy rule insertion when css contains multiple rules by ... Backport fix where classnames are composed in the wrong order if custom...
Read more >Higher-Order Components - React
A higher-order component (HOC) is an advanced technique in React for reusing component logic. HOCs are not part of the React API, per...
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 Free
Top 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
I’ve managed to solve this by providing an
insertionPoint
for each app.If this is a good enough solution (Still not sure what’s the problem is), you can close this issue. And thanks for the fast response!
@gilamran You are using two different JSS instances, it’s the correct solution 👍