Does Material-ui v4 display component names within the class attributes of the html DOM?

Upon transitioning from material-ui v3 to v4, it was observed that the react component/function names were included in the class attribute within the HTML.

Is this normal? Could this potentially cause issues when trying to override class properties with new styles that are not being applied?

Furthermore, is there a way to remove these component names?

The component names include: WrapperComponent, withRouter, CustomerDetailsContainer, and others.

https://i.sstatic.net/XoAPS.png

Answer №1

Material-UI utilizes a unique class name generator to create distinct class names for styled components in order to achieve style isolation. The prefix of the class name varies depending on the current environment.

  • During non-production mode, the component's displayed name is used as the class name prefix
  • In production mode, the default prefix jss is utilized

To observe the change in class name prefix, you can simulate different environments by adjusting process.env.NODE_ENV at the start of your program.

// Set to "production" to view the difference in class name prefix
process.env.NODE_ENV = "development";

class App extends React.Component {
  static displayName = "MyAmazingApp";

  render() {
    const { classes } = this.props;
    return <div className={classes.root}>Hello world</div>;
  }
}

const styles = {
  root: {
    backgroundColor: "grey"
  }
};

const AppWithRouter = withRouter(App);
const MyApp = withStyles(styles)(AppWithRouter);

console.log(AppWithRouter.displayName); // withRouter(MyAmazingApp)-root-1

Generated class name for the element in development:

withRouter(MyAmazingApp)-root-1

In a production environment:

jss1

Interactive Demo

Check out the live demo here!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Having trouble getting collision events to trigger in ThreeJS when using the PhysiJS physics engine?

When an object falls and collides with the ground, an alert box should pop up displaying the message "Box just hit the ground". However, there seems to be an issue as the alert box is not being created upon collision. Additionally, no relevant JavaScript ...

`Why is Node.js Express response.download() Not Functioning Properly?`

I have implemented the code below to track active download counts: router.get('/download/:fileName', (req, res) => { let fileName = req.params.fileName; let baseFilePath='/home/filePath'; incrementDownloadCount(fileName) ...

Firefox returns a "null" error when attempting to access the Vimeo API, whereas there are no errors reported when accessing the YouTube API or when

I tried researching this issue on multiple platforms, including Google and other forums, but I am still unable to resolve it. I recently transitioned from a proxy request approach (using AJAX to communicate with a server-side script that then interacts wit ...

Guide to transforming an array into JSON format and displaying the JSON data in a table within a React JS environment

I have an array that contains some data, I want to convert this array into JSON format, so I can display the data in a Bootstrap table. Here's an example of how it could be done: import "bootstrap/dist/css/bootstrap.min.css"; import Table f ...

Ensure input integrity within Node.js/Express server before transferring outcome to React client-side

Checking the validity of a domain entered by a user in my React front-end is crucial. The process involves sending the domain to my Nodejs/Express back-end and utilizing the Node function dns.lookup for validation. app.post('/new-cert', function ...

`The mobile viewport is displaying the webpage with double the width`

After spending several hours trying to optimize my website for mobile, I'm still unable to get it working properly. It seems like one of the elements is exceeding its container width, causing issues. Any assistance would be greatly appreciated. If yo ...

Is there a way to modify Bootstrap tabs when they are hovered over?

This may seem like a simple question, but I've been struggling to figure it out. I'm attempting to have the bootstrap tabs switch when the mouse hovers over them. <div class="container"> <nav class="nav nav-tabs" ...

What is the best way to prevent a fetch request from being initiated before the authentication token has been received

After successfully logging in, the data request fetch function needs to send the request with the saved token bearer. However, the data fetch is not waiting for the token and is receiving an Unauthorized access code. This is how my data request fetch func ...

Making adjustments to the Bootstrap CSS design by removing certain elements

I have inserted a styling link from Bootstrap into the header section of my page, but it is applying additional styles to my cards which I don't want. Is there a way to eliminate these unwanted styles without removing the Bootstrap CSS link? Below, y ...

Input ENTER triggered JSON path loading

Upon clicking "enter", I am looking to display the description corresponding to the title. To achieve this, I have defined a variable to store the path of the description: var descri = json.query.results.channel.item.map(function (item) { return item. ...

glitch in animation when quickly mousing over and out

How can I resolve an animation glitch that occurs when quickly hovering over and then off an element? You can view the live version of the website at - Whenever I rapidly hover on and off the circle, it starts acting buggy. It happens consistently, so I& ...

PHP 5.5 fails to populate the $_POST array

UPDATE: I mistakenly placed var_dump($_POST) OUTSIDE of the if statement. Despite attempting various solutions, none have been successful in resolving the issue at hand. My final effort involves troubleshooting a form created in HTML that is sending data ...

Displaying content based on changing conditions fetched from the database

We are currently developing a dynamic form system where users can create custom questions in the admin panel and set conditions to display them based on the values of other questions. ng-show="((UserCode==10003 && Name=='Ankur') ||(State ...

Step-by-step guide on eliminating the modal post-validation

Newbie in reactjs looking for help with modal validation issue. Goal: Press submit button inside modal, validate, then close the modal. Want to reuse modal for another row. Problem: I'm having trouble making the function work for a new row after ...

I desire my grid to exhibit an identical appearance to that of the jquery datepicker

I have an interactive element called the "open grid" that, when clicked on, reveals a grid of buttons. I'm looking for help with coding it so that instead of being displayed below the textbox, the grid of buttons can be hovered over the "open grid" li ...

Having difficulty understanding why the Javascript regex is not functioning as expected

Can you help me validate user input to ensure it is a positive currency value in the correct format? Examples of valid formats include: 0.5, 0.55, 5 (please note this one), 5.5, 5.55, 55, etc. This is the code I am currently using: if ($("#gross").val() ...

Display a specific paragraph inside a div using jQuery

I am having trouble getting my jQuery code to display a specific paragraph when a particular div is clicked on. My goal is for the content "v" to be displayed if the user clicks on the ".Virus" div, and for the contents of ".screenInfo" to be shown if the ...

Online collection-based game

This is my first attempt at creating a web-based game and I have some questions about the necessary technologies. Specifically, I want to enable users to gather items and save their progress within the game. Currently, I am focusing on mastering HTML, CS ...

Develop and share a function to be assessed within a different scope's context in JavaScript

Currently, I'm exploring the use of angular and bootstrap tour and I have a challenge in trying to isolate objects within their own area without storing them in the controller. My goal is to store an object in the service, which also contains function ...

The tab contents are colliding and merging with each other, creating an overlap

I have created a code with two tabs that should appear when the tab header is clicked. However, there seems to be an issue where the content from the second tab is also previewing in the first tab when the page is loaded. Strangely, when I switch to the ...