-
-
Notifications
You must be signed in to change notification settings - Fork 32.6k
Closed
Labels
type: bugIt doesn't behave as expected.It doesn't behave as expected.
Description
The css class names definitions are duplicated for some components - in my case it is duplicated (I guess from my debugging) for MuiIconButton
and MuiModal
- check current behavior
- I have searched the issues of this repository and believe that this is not a duplicate.To pick up a draggable item, press the space bar. While dragging, use the arrow keys to move the item. Press space again to drop the item in its new position, or press escape to cancel.
Expected Behavior
The class names should not be duplicated across components.
Current Behavior
My button styles:
The class is duplicated.
Styles definition:
It is working in development mode:
My buttons styles:
Steps to Reproduce (for bugs)
I can try to prepare the environment to reproduce the problem but right now I just wanted to report it here.
Context
I'm trying to release my application with the production environment.
Your Environment
Tech | Version |
---|---|
Material-UI | 1.0.0-beta.10 |
React | 15.6.1 |
browser | any |
webpack | ^3.3.0 |
I need some hints where may be the problem. I'm not using withStyles
solution anywhere - I use styled components for styles overriding.
robophil, brianfeister, oliviertassinari, grigored, benwinding and 16 more
Metadata
Metadata
Assignees
Labels
type: bugIt doesn't behave as expected.It doesn't behave as expected.
Projects
Milestone
Relationships
Development
Select code repository
Activity
oliviertassinari commentedon Sep 15, 2017
I have already seen some issue around this problem. It was always linked to duplicated className generator instances. I can't help more without a reproduction.
oliviertassinari commentedon Sep 15, 2017
I'm closing the issue for now as not actionable. Let me know if you have a reproduction example.
darkowic commentedon Sep 19, 2017
@oliviertassinari I was able to reproduce the problem. Here is the webpack bin - https://www.webpackbin.com/bins/-KuO6ia3h-JDpBOJncZ3
In my case, I have 2 application roots which are mounted independently to 2 different div. Both use the same material-ui
ThemeProvider
wrapped withJssProvider
to overrideinsertionPoint
from jss.Based on
createGenerateClassName
function, you use counter to have unique class namesAnd my screenshot confirms that for some reason the counter is duplicated.
I need help. I don't know what I'm doing wrong right now.
oliviertassinari commentedon Sep 19, 2017
@darkowic You need to share the jss instance between the different react trees. You should be good with such change.
darkowic commentedon Sep 19, 2017
@oliviertassinari I think I'm doing it using my custom
ThemeProvider
I wrap my every react tree with this.
darkowic commentedon Sep 21, 2017
This issue should be opened.
oliviertassinari commentedon Sep 21, 2017
Sure, let's sum up what we know so far. This issue arise as soon as you are using multiple react rendering tree. The jss provider is going to create two class name generators, one for each tree. Hence we end up with class name conflicts.
@kof Should we extend the JssProvider from
react-jss
to accept a class name generator?[-]V1 production build - classnames conflicts[/-][+]production build - classnames conflicts[/+]55 remaining items
oliviertassinari commentedon Apr 13, 2019
@kopax It's hard to tell without something I can debug. I'm happy to hear it's working now.
I have noticed you are using styled-components with Material-UI. If you have some time, I would love to chat about the integration on Gitter.
kopax commentedon Apr 13, 2019
The working solution isn't natural. Which means it involve task that cannot be run with npm. I will not use it, i gave this as a hint.
We'll have the chance on monday, I'll join the mui gitter channel.
roytz commentedon Apr 22, 2019
Hi @kopax, did you manage to find a solution?
kopax commentedon Apr 22, 2019
No not yet. Not without the provider. @oliviertassinari I am on gitter.
griiettner commentedon Apr 24, 2019
@andrewkslv Your solution really worked for me. I'm also using
react-admin
and AWS Amplify. Anytime I would deploy my react application to a S3 bucket, the style would be all broken, and your solution really saved me.koutsenko commentedon Apr 25, 2019
Same issue here. Why adding JssProvider helps?
oliviertassinari commentedon Apr 25, 2019
I have added a warning in v4 to warn when duplicated style instances are used: #15422.
andrewkslv commentedon Apr 25, 2019
I don't know. I raised this issue in
react-admin
when they were implementing a new version of material ui to the framework but it was ignored.marmelab/react-admin#3102 (comment)
beran24 commentedon Oct 8, 2019
Where i can find the solution about production build - classnames conflicts #8223 ?
Thanks,
KannugoPrithvi commentedon Nov 20, 2019
@oliviertassinari Facing this issue again, even though i have followed all the instructions. Since it is working for others, i guess i might be missing something basic.
https://stackoverflow.com/questions/58938080/jssprovider-not-generating-class-prefix-with-classnameprefix
I'm using following versions of the packages.
"@material-ui/core": "^4.6.1",
"@material-ui/icons": "^4.5.1",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-jss": "^10.0.0",
"react-scripts": "3.2.0"
Update: Issue got resolved. Sorry for not going through documentation thoroughly. This part of the documentation solved my issue.
https://material-ui.com/styles/api/#creategenerateclassname-options-class-name-generator
But somehow, the JSSProvider solution which was working for all others, was not working for me. Anyways, thank you :)
appli-intramuros commentedon Nov 2, 2020
Thanks @KannugoPrithvi , this is the good solution ! https://material-ui.com/styles/api/#creategenerateclassname-options-class-name-generator