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.

Material UI style specificity issues

See original GitHub issue

Since we have multiple instances of material-ui each one of them injects styles into the head without awareness of what the others are injecting.

Each instance only injects the styles that are needed at that moment, so you can get into weird states like this: One instance of material-ui renders a MenuItem which uses both Button and MenuItem styles, so it injects Button styles first and MenuItem second so that the MenuItem styles override Button. but then the other instance of material-ui is only rendering a Button so it injects styles for Button and if that happens after MenuItem then you end up with Button > MenuItem > Button with Button incorrectly overriding MenuItem styles.

There’s a few possible fixes:

  • Wrap all of JupyterLab inside of a StylesProvider component (the best solution, if possible)
  • have a classname generator with disableGlobal set to true (This will make all the Mui style names non-deterministic, so we won’t be able to override styles via css, but I believe we can override them via a theme)
  • create our own classname generator that allows us to create deterministic Mui classes, but with each mui instance prefixed with something custom

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
kevin-batescommented, Mar 15, 2021

If you run jupyter lab in a folder with git the dropdown will be broken. If you run jupyter lab in a normal non-git project folder the dropdown will render correctly

To clarify this, it’s really a function of where your notebook-dir is pointing relative to a git configuration. Since I always run lab with --notebook-dir=~/notebooks and git is not configured in ~/notebooks, I did not see this problem when when invoking jupyter lab from my elyra dev tree. However, based on this information, if I perform that same invocation, but do not add --notebook-dir=~/notebooks, the issue reproduces. Nice find @bourdakos1!

1reaction
bourdakos1commented, Mar 15, 2021

I was able to make the original issue we were seeing reproducible. The issue is the git extension, it uses material-ui for tabs, but the tabs only render if you are in a git initialized folder. If you run jupyter lab in a folder with git the dropdown will be broken. If you run jupyter lab in a normal non-git project folder the dropdown will render correctly

Read more comments on GitHub >

github_iconTop Results From Across the Web

material-ui and styled override specificity issue #1253 - GitHub
I'm using styled function from styled-components to override default styles of Typography component like this:
Read more >
Material UI override styles with increased specificity
I have a vertical Slider with marks and for the marks, I want to get rid of the text-transformation. I am setting the...
Read more >
Style library interoperability - Material UI - MUI
In MUI, all child elements have an increased specificity of 2: .parent .child {} . When writing overrides, you need to do the...
Read more >
Advanced (LEGACY) - MUI System
They gain more specificity than any other style tags on your page e.g. CSS modules, styled components. injectFirst. The StylesProvider component has an ......
Read more >
Migrating to v5: getting started - Material UI - MUI
If you want to apply styles to components by importing a CSS file, you need to bump up the specificity to be able...
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