Material-ui/lab and material-ui/pickers overriding styles when being imported from remote federated modules
See original GitHub issueWe are using webpack 5 and a design system that hosts federated modules from material ui. As of now we have the following setup for the ModuleFederationPlugin.
new ModuleFederationPlugin({
name: 'rosters-web-app',
// TODO: Make optional depending if the DS is running locally
remotes: {
'dataeng-ds': federationUrl
},
shared: {
...pkgJson.dependencies,
"@material-ui/core": {
singleton: true,
},
react: {
singleton: true,
requiredVersion: pkgJson.dependencies.react
},
"react-dom": {
singleton: true,
requiredVersion: pkgJson.dependencies["react-dom"]
}
},
})
This is how a page on the app displays:
However, when we use a component from material-ui/lab or material-ui/pickers it seems the styles get messed up.
Notice the buttons are now unstyled/overwritten
Does anyone have an idea on why this is happening?
Note: I have also tried adding
"@material-ui/lab": {
singleton: true,
},
to the shared list and it still does not work.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:4
- Comments:20 (7 by maintainers)
Top Results From Across the Web
Best practices for avoiding duplicate contexts in re-export ...
Presumably I can import both entrypoints and use both of the duplicate ... styles when being imported from remote federated modules #1071.
Read more >Module Federation - webpack
This plugin adds specific references to containers as externals and allows to import remote modules from these containers. It also calls the override...
Read more >Unable to import a component using material-ui via webpack ...
Configure the Module Federation for your nav component in this way: ... `new ModuleFederationPlugin({ name: "Appliaction", remotes: ...
Read more >Micro Frontends Architecture with Webpack Module ... - Medium
In order to use Module Federation, it is necessary to switch to ... For example, although Craco allowed us to override the standard...
Read more >Tutorial - A Guide to Module Federation for Enterprise
js bootstraps Webpack chunks with the correct URLs based on the current environment. Host / Remote. chunks.config.json is an array of Webpack ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Although this has been marked as closed, i would like to continue and try to understand the issue. Is this material-ui specific thing?? We don’t notice this with other libraries that we’re using.
The effects of this issue are understood. It seems to download and load the same component twice (For example, Button or Typography) and if this happens at various times of the page, it will cause the component to create styles once more and add them to <head>. The big question is why it does that.
To my understanding, the solution of using
material-ui/core/
(With a Trailing Slash) will make everything under this as a shared component individually, which in turn creates a whole bunch of files (As they are all shared individually). Although this should not make an issue since the browser can cache them, and initially if it uses http2 it will download a bunch of them together, it still creates a bunch more files. BUT, this does solve the issue since webpack notices the file paths are exactly the same…?Can it be that, due to different tree-share combinations of those components, it bundles Button in different files between the remotes and therefore forces the loading of that component once more?
Yeah, from what I understand, the libraries that use a context should be shared as singletons. I think the issue here could be the way that material-ui imports and exports some components for the lab. In particular the Button component. I traced my issue back to the Button.
An extra styled sheet for ButtonBase was being added to the <head> of my index.html doc which was over-writing the styles.
I have not solved this issue yet.