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.

Nested theme providers not working correctly when used with webpack module federation

See original GitHub issue
  • 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 😯

Two ThemeProviders are nested. One is the outer and spans the whole Application tree, setting primary color to green the other one is nested into it, setting primary color to hotpink. I also have two buttons - one inside the outer ThemeProvider, sibling to the inner ThemeProvider, the other inside the inner ThemeProvider.

A little like this:

<ThemeProvider theme={/* green primary */}>
  <Button color="primary">should always be green</Button>
  <ThemeProvider theme={/* hotpink primary */}>
    <Button color="primary">should always be hotpink</Button>
  </ThemeProvider>
</ThemeProvider>

However, the inner ThemeProvider is asynchronously loaded, using webpack module federation (not sure if this even matters, it’s a rather basic React.lazy think, lazy loading a webpack chunk). However, it is coming from a different application - so there might be something about “seed” that i don’t get here.

What happens ins that as long as only the outer ThemeProvider is rendered, the Button that should be green is green. Once the inner ThemeProvider is loaded and rendered aswell, the outer Button switches to hotpink and thus has the same color as the inner Button - which it shouldn’t.

Expected Behavior 🤔

Outer Button stays green.

Steps to Reproduce 🕹

Not easily reproducible on codesandbox due to module federation.

This is the commit with the reproduction: https://github.com/codepunkt/react-microfrontend-eval/commit/b5e9284cadc9bf964442c0ed191530edc4dcca6c

Steps:

  1. Clone
  2. Switch to commit
  3. Run “yarn” in toplevel folder
  4. Change directory to “federation” folder
  5. Run “yarn start” in federation folder
  6. See problem in effect on localhost:3000

Your Environment 🌎

Tech Version
Material-UI v4.11.0
React v16.13.1
Browser Any
TypeScript v3.9.6, should not be related

Issue Analytics

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

github_iconTop GitHub Comments

5reactions
codepunktcommented, Sep 25, 2020

@AlessandroAnnini I had to tread @material-ui/styles as a singleton

1reaction
vishalrajolecommented, Feb 4, 2021

Okay, so if I understood it correctly, we don’t need to make @material-ui/core singleton as it is partially singleton? but rest like below needs to be singleton? @oliviertassinari

  '@material-ui/styles': {
          singleton: true,
        },
        '@emotion/core': {
          singleton: true,
        },
        '@emotion/styled': {
          singleton: true,
        },
Read more comments on GitHub >

github_iconTop Results From Across the Web

Nested theme providers not working correctly when used with ...
Not easily reproducible on codesandbox due to module federation. ... Steps: Clone; Switch to commit; Run "yarn" in toplevel folder; Change ...
Read more >
When should you leverage Module Federation, and how?
Webpack's Federation is immensely useful if used properly. The tricky part is there's not much information on how and where to leverage the...
Read more >
Webpack module federation is not working with eager shared ...
I used dynamic load technique for my remote library and it seems shared modules are not being fetched again and again now. They...
Read more >
Micro Frontends with Module Federation and Angular 12
Full video course: https://angularmaster.dev0:00 - Start of transmission12:49 - Start of the webinar : Micro Frontends with Module ...
Read more >
Module scss ampersand class selector not working-Reactjs
Coding example for the question Module scss ampersand class selector not working-Reactjs.
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