Skip to content

production build - classnames conflicts #8223

@darkowic

Description

@darkowic
Contributor

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.

Expected Behavior

The class names should not be duplicated across components.

Current Behavior

My button styles:
classnames_conflict
The class is duplicated.
Styles definition:
classnames_conflit_2

It is working in development mode:
My buttons styles:
development_class

and found the definitions:
mui-icon-button-dev

and from modal:
mui-modal-dev

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.

Activity

oliviertassinari

oliviertassinari commented on Sep 15, 2017

@oliviertassinari
Member

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.

added
waiting for 👍Waiting for upvotes. Open for community feedback and needs more interest to be worked on.
on Sep 15, 2017
oliviertassinari

oliviertassinari commented on Sep 15, 2017

@oliviertassinari
Member

I'm closing the issue for now as not actionable. Let me know if you have a reproduction example.

darkowic

darkowic commented on Sep 19, 2017

@darkowic
ContributorAuthor

@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 with JssProvider to override insertionPoint from jss.

generate_classnames_counter

Based on createGenerateClassName function, you use counter to have unique class names

export default function createGenerateClassName(): generateClassName {
  let ruleCounter = 0;

  return (rule: Rule, sheet?: StyleSheet): string => {
    ruleCounter += 1;
    warning(
      ruleCounter < 1e10,
      [
        'Material-UI: you might have a memory leak.',
        'The ruleCounter is not supposed to grow that much.',
      ].join(''),
    );

    if (process.env.NODE_ENV === 'production') {
      return `c${ruleCounter}`;
    }

    if (sheet && sheet.options.meta) {
      return `${sheet.options.meta}-${rule.key}-${ruleCounter}`;
    }

    return `${rule.key}-${ruleCounter}`;
  };
}

And 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

oliviertassinari commented on Sep 19, 2017

@oliviertassinari
Member

@darkowic You need to share the jss instance between the different react trees. You should be good with such change.

darkowic

darkowic commented on Sep 19, 2017

@darkowic
ContributorAuthor

@oliviertassinari I think I'm doing it using my custom ThemeProvider

  <JssProvider registry={context.sheetsRegistry} jss={context.jss}>
    <MuiThemeProvider
      theme={context.theme}
      sheetManage={context.sheetsManager}
      {...props}
    />
  </JssProvider>

I wrap my every react tree with this.

darkowic

darkowic commented on Sep 21, 2017

@darkowic
ContributorAuthor

This issue should be opened.

oliviertassinari

oliviertassinari commented on Sep 21, 2017

@oliviertassinari
Member

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?

added and removed
waiting for 👍Waiting for upvotes. Open for community feedback and needs more interest to be worked on.
on Sep 21, 2017
changed the title [-]V1 production build - classnames conflicts[/-] [+]production build - classnames conflicts[/+] on Sep 21, 2017

55 remaining items

oliviertassinari

oliviertassinari commented on Apr 13, 2019

@oliviertassinari
Member

@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

kopax commented on Apr 13, 2019

@kopax

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

roytz commented on Apr 22, 2019

@roytz

Hi @kopax, did you manage to find a solution?

kopax

kopax commented on Apr 22, 2019

@kopax

No not yet. Not without the provider. @oliviertassinari I am on gitter.

griiettner

griiettner commented on Apr 24, 2019

@griiettner

@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

koutsenko commented on Apr 25, 2019

@koutsenko

Same issue here. Why adding JssProvider helps?

oliviertassinari

oliviertassinari commented on Apr 25, 2019

@oliviertassinari
Member

I have added a warning in v4 to warn when duplicated style instances are used: #15422.

andrewkslv

andrewkslv commented on Apr 25, 2019

@andrewkslv

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

beran24 commented on Oct 8, 2019

@beran24

Where i can find the solution about production build - classnames conflicts #8223 ?

Thanks,

KannugoPrithvi

KannugoPrithvi commented on Nov 20, 2019

@KannugoPrithvi

@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

appli-intramuros commented on Nov 2, 2020

@appli-intramuros
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugIt doesn't behave as expected.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @kof@tlvince@Sewdn@christiaanwesterbeek@griiettner

        Issue actions

          production build - classnames conflicts · Issue #8223 · mui/material-ui