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
yarn
yarn 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-styles and the styled function.
- 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.
- To target shadow roots with specific styles a
MergeStylesContext has 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,
DefaultButton uses @customizable.
- It is also possible to plumb the stylesheet key through this code path.
Validations
Library
React / v8 (@fluentui/react)
Describe the feature that you would like added
Fluent React v8's
mergeStylespackage should support rendering styles into Shadow DOM viaadoptedStyleSheetsand 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:
yarnyarn start>@fluentui/reactThe changes are a bit messy and the implementation is not 100% working but it proves the general plan.
Overview
merge-stylesand thestyledfunction.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.MergeStylesContexthas been introduced.react-shadow's proxystyled:(DefaultButtonuses@customizable.Validations