fix: prevent overriding global theme from widget #589
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Which Jira task is linked to this PR?
https://lifi.atlassian.net/browse/LF-16412
Why was it implemented this way?
_UPD:
Using the example provided in #583, just removing
setMode()will not be sufficient.The problem is that MUI's mode switcher (
setMode()) always overwrites global html attributes, no matter what properties are set when defining the theme: when we definecolorSchemeSelector: 'class'(or any other attribute) in createTheme (from MUI), it is always attached to thehtmlnode.MUI's
ThemeProviderhas a propertycolorSchemeNodewhich allows to attach the color scheme attribute to a certain node (not only to globalhtml), which theoretically could scope the mode only within widget's container, but instead it just duplicates the attributes, setting them to both global html node and that specified node.So setting the node in this form still does not resolve the problem.
Screen.Recording.2025-11-07.at.15.26.48.mov
Instead, conditionally attaching widget to shadow root: https://mui.com/material-ui/customization/shadow-dom/
Checklist before requesting a review