Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong CSS classes take precedence #28889

Closed
keo-hgsdk opened this issue Oct 7, 2021 · 10 comments
Closed

Wrong CSS classes take precedence #28889

keo-hgsdk opened this issue Oct 7, 2021 · 10 comments
Labels
component: data grid This is the name of the generic UI component, not the React module! v5.x migration

Comments

@keo-hgsdk
Copy link

keo-hgsdk commented Oct 7, 2021

TL;DR
Needed to npm uninstall @mui/x-data-grid and npm install @mui/x-data-grid@next

After migrating from v4 to v5, and having refactored out @mui/styles, I now see that my MuiButtons, when rendered, have classes on the form: css-xyz1234-MuiButtonBase-root-MuiButton-root.

On some pages in my app, styles coming from css-xyz1234-MuiButtonBase-root-MuiButton-root are overridden by the styles coming from MuiButton-root, which causes buttons to seem unstyled.

On other pages, the styles from css-xyz1234-MuiButtonBase-root-MuiButton-root correctly take precedence, giving buttons the intended styling.

If I inspect a MuiButton component in the docs, I see no classes of the long form, but instead css-xyz1234.

I tried using StyledEngineProvider as described in https://mui.com/guides/migration-v4/#style-library without effect.

Although I suspect that this is an issue with my project and not material-ui, I'm posting this since I'm out of ideas on how to move forward and hoping that it might help others migrating.

@michaldudak michaldudak added the status: waiting for author Issue with insufficient information label Oct 7, 2021
@michaldudak
Copy link
Member

Would you be able to reproduce this behavior on CodeSandbox?

@keo-hgsdk
Copy link
Author

I haven't been able to so far, which I realize limits your ability to help me.. I was hoping that it would ring a bell to someone

@michaldudak
Copy link
Member

@mnajdova, perhaps you would have a clue what may be going on?

@mnajdova
Copy link
Member

mnajdova commented Oct 7, 2021

Let me try to clarify few things and we can go step by step.

The difference between: css-xyz1234-MuiButtonBase-root-MuiButton-root and css-xyz1234 is simply coming from development vs production build. We are adding the components names in dev mode so that it could be easier for debugging. In production we are removing these to improve the size of the styles generated.

If there are styles coming from the class: MuiButton-root it is likely that v4 is injected somewhere. Note that in v5 we are not assigning any styles to these classes, we are simply adding them on the component as a utility classes that people can use for styling the components, for example with pure CSS. The other option is that, there is a component that has a nested selector that adds these styles, for example:

const Wrapper = styled('div')({
  '& .MuiButton-root': {
    // some styles that have bigger specificity?
  }
});

Could you provide package or yarn lock so that we can take a look at the dependencies? and the version installed?

@keo-hgsdk
Copy link
Author

Thank you for that in depth response! It does clear up a lot. Styles coming from the class MuiButtonBase-root are definitely the culprit - removing the class in dev tools makes everything look as intended. I think you are probably correct that v4 is injected somehow. I have ruled out the other option you mentioned.

Here's my package-lock.json, in a .txt:

package-lock.json.txt

@mnajdova
Copy link
Member

mnajdova commented Oct 7, 2021

I can definitely see @material-ui/core, it comes as being dependency on @mui/x-data-grid I believe. I think you need to upgrade to v5 on @mui/x-data-grid too, but probably @m4theushw can provide more info on this. The goal is to try to remove @material-ui/core everywhere from package-lock.json

@keo-hgsdk
Copy link
Author

keo-hgsdk commented Oct 7, 2021

Good catch, that was sneaky! Thank you so much for pointing me in the right direction. @material-ui/core is no longer to be found after npm uninstall @mui/x-data-grid

@mnajdova mnajdova added v5.x migration and removed status: waiting for author Issue with insufficient information labels Oct 7, 2021
@mnajdova
Copy link
Member

mnajdova commented Oct 7, 2021

You probably want to upgrade @mui/x-data-grid to v5 instead of removing it :)

@keo-hgsdk
Copy link
Author

Yep, I did! Updated original question with TL;DR :)

@mnajdova
Copy link
Member

mnajdova commented Oct 7, 2021

Great thanks! I am closing.

@mnajdova mnajdova closed this as completed Oct 7, 2021
@oliviertassinari oliviertassinari added the component: data grid This is the name of the generic UI component, not the React module! label Oct 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: data grid This is the name of the generic UI component, not the React module! v5.x migration
Projects
None yet
Development

No branches or pull requests

4 participants