fluentui
fluentui copied to clipboard
[Feature]: Add ShadowDOM support to mergeStyles in Fluent React v8
Library
React / v8 (@fluentui/react)
Describe the feature that you would like added
Fluent React v8's mergeStyles package should support rendering styles into Shadow DOM via adoptedStyleSheets and constructable stylesheets.
This feature will allow FUIv8 users to place components inside ShadowDOM to better manage light DOM size and style recalculations. Constructable stylesheets will reduce memory impact and allow for management of styles similar to the existing solution.
This feature is entirely opt-in and will not be enabled by default.
A design goal of this feature is to require minimal changes for users to leverage shadow DOM and minimal changes to Fluent UI v8 itself to support shadwo DOM.
Have you discussed this feature with our team
@layershifter
Additional context
A proof of concept has been implemented here (diff).
To see it in action:
- Pull the branch
yarnyarn start>@fluentui/react- Navigate to the DefaultButton example.
The changes are a bit messy and the implementation is not 100% working but it proves the general plan.
Overview
- Changes are almost 100% internal to
merge-stylesand thestyledfunction.- Introduces a new concept called "stylesheet key" which is analogous to
styled's "scope". This is used to bucket styles into different constructable stylesheets so all "SpinButton" styles are in one sheet and nothing else is in there. - In the event something doesn't have a key it is put in the "global" bucket. All shadow roots and the document adopt this sheet.
- Introduces a new concept called "stylesheet key" which is analogous to
- To target shadow roots with specific styles a
MergeStylesContexthas been introduced.- Context keeps track of which styles have been adopted and correctly adopts styles into the shadow root.
- This will likely be rolled into
react-shadow's proxy - Will need to interop with Fluent v9 and app styles
- Not all components use
styled:(- Notably,
DefaultButtonuses@customizable. - It is also possible to plumb the stylesheet key through this code path.
- Notably,
Validations
- [X] Check that there isn't already an issue that request the same feature to avoid creating a duplicate.