Skip to content
Advertisement

Material-ui v4 shows component names in html DOM class attributes?

After migrating from material-ui v3 to v4, noticed the react component/function name in the class attribute inside the HTML.

Is that expected? Might this somehow affect overriding class properties already noticing issues when trying to override with new styles which do not apply.

Also is there a possibility to remove those?

The component names are: WrapperComponent, withRouter, CustomerDetailsContainer among others.

enter image description here

Advertisement

Answer

Material-UI uses class name generator to generate unique class names for styled components to enable style isolation. The classname prefix is different depending on the current environment.

  • In non-production mode, the displayed name of the component is used as classname prefix
  • In production mode, by default jss is used as classname prefix

You can fake the environment by setting process.env.NODE_ENV at the beginning of the program to see the change in classname prefix

JavaScript

Generated class name of the element in development

JavaScript

In production

JavaScript

Live Demo

Edit Material-UI - Classname Prefix

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement