Styles not added to shadow DOM when wrapping MUI in a library #42992
Labels
external dependency
Blocked by external dependency, we can’t do anything about it
package: system
Specific to @mui/system
Steps to reproduce
Link to live example: https://6698f74d46bade9e76f1d058--guileless-sorbet-bf347d.netlify.app/
https://github.com/MartinJaskulla/reproduction-library
https://github.com/MartinJaskulla/reproduction-library-user
<Button>
is unstyled, because emotion style sheets are added to<head>
instead of shadow DOMButton,
and comment in// import {Button} from "@mui/material";
in main.jsxCurrent behavior
<Button>
looks like a native html<button>
inside shadow DOM.Expected behavior
<Button>
should look like a MUI button inside shadow DOM.Context
I created a component library for my company that wraps MUI and makes some adjustments. Everything works flawlessly.
For a new feature we have to use my library inside shadow DOM meaning the project that is installing my component library is creating a custom element and wants to use the wrapped MUI components from my library inside it. I followed the documentation (https://mui.com/material-ui/customization/shadow-dom/) to do that. Somehow the styles do get added to the
<head>
instead of the shadow DOM.I created a new library for my reproduction, in which I just re-export MUI as is (that is the only thing the library is doing):
https://github.com/MartinJaskulla/reproduction-library/blob/main/src/main.jsx
If I install this library in a new project (https://github.com/MartinJaskulla/reproduction-library-user), then
import { Button } from "@mui/material";
adds the styles correctly to the shadow DOM, butimport { Button } from "reproduction-library";
adds the styles to the<head>
although the code of both buttons should be identical.To me it looks like MUI only works inside shadow DOM if imported from
"@mui/material";
.Your environment
npx @mui/envinfo
Search keywords: shadowdom library styles emotion
The text was updated successfully, but these errors were encountered: