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.

[system] unstable_classNameGenerator does not support multiple scopes

See original GitHub issue

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior 😯

I am migrating to MUI v5 and I found some issues with styles collisions. On our projects, we use a micro front-end structure. That is, we have a Shell application and several micro-frontends which consume a custom library with differents components (like a custom table, custom breadcrumb, dropdown, etc.). This library that is consumed by all the micro frontends and shell is created with Storybook.

Before this migration, our collision issues were fixed with createGenerateClassName. On each micro-frontend, we used to have at the root this declaration:


const microfrontOne = createGenerateClassName({
  seed: "microfrontOne ",
});

...

return (
     <StylesProvider generateClassName={microfrontOne }>
       ....
     </StylesProvider>

Also, on our custom library, we used to have the same stylesProvider tag to make each component have its own name:

const sidebar = createGenerateClassName({
  seed: "sidebar",
});

export const SideBar: React.FC= () => {
    <StylesProvider generateClassName={sidebar}>
       ...
    </StylesProvider>

In this way, the styles of each component were correctly set and there was no chance to overlap.

image

All the microsites and the Shell imports Material FROM the library, so they all have the same version.

With the new library upgrade, the createGenerateClassName was deprecated so this behavior was no longer possible. I tried with unstable_classNameGenerator because I don’t find a better solution (TBH I don’t like to use something that has unstable on its name), but this does not work on the library with Storybook. As I already mention, I need to custom EACH component that I have in order to avoid styles collision. As the unstable_classNameGenerator is designed to be global, this does not work for me.

I can’t provide reproduction to this issue because there are several projects involved, but basically, I think that the issue is that I can’t provide specific tags for a specific component. I can bring more information if it is needed, please let me know. I really want this to be fixed because if it is not, I can’t use the new version of Material UI anymore.

Expected behavior 🤔

Have a way to give a custom tag to a React Component (not global to the app)

Steps to reproduce 🕹

No response

Context 🔦

No response

Your environment 🌎

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:22 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
oliviertassinaricommented, Nov 30, 2021

Lastly, this means that @BiancaArtola will face the issue if you want to migrate JSS (@mui/styles) to emotion | styled-components. cc @oliviertassinari

@siriwatknp I would expect no issues. I believe it’s only a problem with @mui/styles because there are two elements with the .jss21 class name on the DOM. This is because JSS uses a class name counter, so the apps need to be configured so two counters don’t conflict. But with emotion, it’s a hash-based class name, so it only colid if the styles are identical, not if the style rule index is the same (1, 2, 3, … 21, etc.). In any case, a reproduction will tell us this for sure.

1reaction
siriwatknpcommented, Nov 30, 2021

@oliviertassinari thanks for pointing this out. This is a note to @BiancaArtola for clarity, @mui/styles v5 is exactly the same engine (JSS) that you are using in v4, however in @mui/material v5 we have changed the default engine from JSS to emotion so the styles generated when you render a component is by emotion (there is a way to change to styled-components).

From what I read in the discussion above, you still need to use @mui/styles for style customization. I hope this helps.

Lastly, this means that @BiancaArtola will face the issue if you want to migrate JSS (@mui/styles) to emotion | styled-components. cc @oliviertassinari

Read more comments on GitHub >

github_iconTop Results From Across the Web

[system] unstable_classNameGenerator does not support ...
I tried with unstable_classNameGenerator because I don't find a better solution (TBH I don't like to use something that has unstable on its...
Read more >
Support multiple scopes during GitLab Registry authentication
Presently GitLab only supports a single scope per token exchange. While this works for some tools, other tools attempt to utilize multiple ......
Read more >
Applying UML and Patterns - The University of Texas at Dallas
A general principle of object design and responsibility assignment? Assign a responsibility to the information expert — the class that has the information ......
Read more >
Jdbi 3 Developer Guide
Executing multiple SQL operations in a single transaction ... Jdbi does not aim to provide a complete database management framework.
Read more >
Allure Framework
Allure Framework is a flexible lightweight multi-language test report tool that not only shows a very concise representation of what have ...
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