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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple instances of Material UI get imported using web components #24547

Closed
2 tasks done
gbalatckii opened this issue Jan 22, 2021 · 3 comments
Closed
2 tasks done

Multiple instances of Material UI get imported using web components #24547

gbalatckii opened this issue Jan 22, 2021 · 3 comments
Labels
support: question Community support but can be turned into an improvement

Comments

@gbalatckii
Copy link

Multiple instances of Material UI get imported using web components

  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 馃槸

  1. Two react components are created. Both of them are using material ui button and makeStyles hook to change the background of this button. First one is yellow, the second one is blue.

Bildschirmfoto 2021-01-22 um 11 26 58

  1. The second component was build productive as a web component (using direflow, but it shouldn't matter) and imported in the first component
  2. Second button is placed near the first button. Project started
  3. The first button is purple instead of yellow

Bildschirmfoto 2021-01-22 um 11 29 04

Expected Behavior 馃

Yellow button and the blue button near the first one

While loading the page and inspecting it, it is too see, that multiple instances of Material UI were loaded. This also overrides the rules, that were defined in the upper stylesheet.

As we can see the second load from material UI (from component 2) sets .Mui classes on top of makeStyles-button-1
If you delete the second component then the button will be yellow

Your Environment 馃寧

`npx @material-ui/envinfo`
  Don't forget to mention which browser you used: **Chrome**
  Output from `npx @material-ui/envinfo` goes here.

  System:
    OS: macOS 10.15.7
  Binaries:
    Node: 14.15.4 - ~/.nvm/versions/node/v14.15.4/bin/node
    Yarn: 1.22.10 - ~/.nvm/versions/node/v14.15.4/bin/yarn
    npm: 6.14.10 - ~/.nvm/versions/node/v14.15.4/bin/npm
  Browsers:
    Chrome: 88.0.4324.96
    Edge: Not Found
    Firefox: 84.0.1
    Safari: 13.1.3
  npmPackages:
    @material-ui/core: ^4.11.2 => 4.11.2 
    @material-ui/styles:  4.11.2 
    @material-ui/system:  4.11.2 
    @material-ui/types:  5.1.0 
    @material-ui/utils:  4.11.2 
    @types/react: 16.9.3 => 16.9.3 
    react: 16.13.1 => 16.13.1 
    react-dom: 16.13.1 => 16.13.1 
    typescript: ^3.9.3 => 3.9.7 
@gbalatckii gbalatckii added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Jan 22, 2021
@oliviertassinari
Copy link
Member

oliviertassinari commented Jan 22, 2021

You need to configure JSS to inject the style in each shadow dom. Unless you have a strong use case for use web components, I wouldn't encourage them. I'm closing for #17473.

@oliviertassinari oliviertassinari added support: question Community support but can be turned into an improvement and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Jan 22, 2021
@gbalatckii
Copy link
Author

You need to configure JSS to inject the style in each shadow dom. Unless you have a strong use case for use web components, I wouldn't encourage them. I'm closing for #17473.

But I'm not using shadow dom. You can see it on the last screenshot in Chrome Dev Tools.

@oliviertassinari
Copy link
Member

oliviertassinari commented Jan 22, 2021

@GeorgeBalat Please provide a reproduction in this case. A live example would be perfect. This codesandbox.io template may be a good starting point. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
support: question Community support but can be turned into an improvement
Projects
None yet
Development

No branches or pull requests

2 participants