question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

class from `makeStyles` is overridden, only in production build

See original GitHub issue

Current Behavior 😯

I am applying a style to hide an element when the size is lower than the sm breakpoint. This style is applied to a ListItem. When rendered, this overrides the display: flex style that is applied by the MuiListItem-root style. It looks like this:

const useStyles = makeStyles({
  drawerCategory: {
    [theme.breakpoints.down("sm")]: {
      display: "none",
    },
  }
})

const Component = () => {
  const classes = useStyles()

  return (
    <List>
      <ListItem className={classes.drawerCategory}>
        // list stuff blah blah blah
      </ListItem>
    </List>
    )
}

It works great when developing locally on create-react-app. When I build and serve the project (via npm run build && serve -s build -l 4000, or our deploy), the display: "none" is overridden by MuiListItem-root.

Inspector in dev environment: Screen Shot 2021-03-12 at 8 06 21 PM

Inspector in prod environment (I’ve confirmed .jss27 corresponds to makeStyles-drawerCategory-68). Screen Shot 2021-03-12 at 8 07 04 PM

Expected Behavior 🤔

The ListItem’s <li> element should be hidden when the screen is smaller than the sm breakpoint.

The Inspector screenshots from above should look the same, because the drawerCategory class overrides the MuiListItem-root class on the display property.

Steps to Reproduce 🕹

Working on this - it’ll take time to pull from company code. Posting now in case there’s a common pitfall I’m missing here.

Context 🔦

I am trying to hide an element when the screen is smaller than the default sm. This behaves differently between the dev server and a production build.

Your Environment 🌎

I am seeing this behavior on Firefox, Chrome, and Safari.

`npx @material-ui/envinfo` ``` System: OS: macOS 10.15.7 Binaries: Node: 10.23.3 - ~/.nvm/versions/node/v10.23.3/bin/node Yarn: 1.22.0 - /usr/local/bin/yarn npm: 6.14.11 - ~/.nvm/versions/node/v10.23.3/bin/npm Browsers: Chrome: 89.0.4389.82 Edge: Not Found Firefox: 86.0 Safari: 14.0.3 npmPackages: @material-ui/core: ^4.11.3 => 4.11.3 @material-ui/icons: ^4.11.2 => 4.11.2 @material-ui/lab: ^4.0.0-alpha.57 => 4.0.0-alpha.57 @material-ui/styles: 4.11.3 @material-ui/system: 4.11.3 @material-ui/types: 5.1.0 @material-ui/utils: 4.11.2 @types/react: ^17.0.2 => 17.0.2 react: ^17.0.1 => 17.0.1 react-dom: ^17.0.1 => 17.0.1 typescript: ^4.1.5 => 4.1.5 ```

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:18 (2 by maintainers)

github_iconTop GitHub Comments

12reactions
freedomherocommented, Sep 17, 2021

Same problem here with next.js & react, any suggestions?

3reactions
MattyMagscommented, Oct 21, 2021

Same problem here with next.js & react, is this going to ever be resolved?

Read more comments on GitHub >

github_iconTop Results From Across the Web

class from `makeStyles` is overridden, only in production build
Current Behavior I am applying a style to hide an element when the size is lower than the sm breakpoint. This style is...
Read more >
React CSS class gets override automatically on production ...
Issue to notice Only the class .makeStyles-root-1 gets replaced with some random class .jss16 when the build gets uploaded to the server and ......
Read more >
4 Ways to Override Material UI Styles | by John Au-Yeung
There are four main methodologies, implemented using pre-built components and hooks, for overriding styling in Material UI:.
Read more >
Frequently Asked Questions - Material UI - MUI
MUI uses the same theme helper for creating all its transitions. Therefore you can disable all transitions by overriding the helper in your...
Read more >
Cascade, specificity, and inheritance - Learn web development
The aim of this lesson is to develop your understanding of some of the most ... A class selector is more specific; it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found