Shadow DOM: prune bundle size impact#30709
Merged
spmonahan merged 17 commits intomicrosoft:shadow-domfrom Mar 22, 2024
Merged
Conversation
Contributor
Author
|
/azp run Fluent UI React - Bundle-Size |
|
Azure Pipelines could not run because the pipeline triggers exclude this branch/path. |
c8b4d67 to
f301069
Compare
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
Collaborator
📊 Bundle size reportUnchanged fixtures
|
* fix: improve focus rects support in shadow DOM Moves the FocusRectsProvider to be outside of the shadow DOM, removing a <div> inside the shadow root. Now the FocusRects class name is applied to the shadow root host element and the focus visibility styles are applied by using the `:host()` selector on the shadow root. * update snapshots * link: supports focus rects in shadow dom * checkbox: supports focus rects in shadow dom * update styles to support focus rects in shadow dom * update snapshots * update snapshots * Updating snapshots. --------- Co-authored-by: KHMakoto <Humberto.Morimoto@microsoft.com>
This commit works to minimize the bundle size impact of the v8 shadow DOM feature for users who have NOT opted in to using shadow DOM. In other words, this commit makes shadow DOM as pay-to-play as possible. Or at least starts to. The biggest change is to make MergeStylesRootProvider's context into a dependency injection container. All the hooks necessary for the shadow DOM feature are injected into this container with noop defaults being provided for non-shadow DOM users. This helps minimize the additional code for all components as the actual shadow DOM implementation is only injected for users that opt in to it. Additionally, Stylesheet has been refactored, pulling out optional code like style projection and minimizing other code in the class. Stylesheet still accounts for the bulk of the increased bundle size so there is future bundle reductions will likely come from here.
f301069 to
acc275b
Compare
Contributor
Author
|
/azp run Fluent UI React - Bundle-Size |
|
Azure Pipelines successfully started running 1 pipeline(s). |
spmonahan
commented
Mar 11, 2024
| export * from './interfaces/index'; | ||
| export * from './MergeStyles'; | ||
| export * from './cdn'; | ||
| export { AnimationClassNames, FontClassNames, ColorClassNames } from './classNames/index'; |
Contributor
Author
There was a problem hiding this comment.
This exports the same API. The change just addresses a lint warning to be specific about exports (i.e., no export * ...)
khmakoto
reviewed
Mar 13, 2024
packages/utilities/src/shadowDom/contexts/MergeStylesShadowRootContext.tsx
Show resolved
Hide resolved
This encapsulates all the functionality for the `styled` HOC into a single hook, making the bundle size impact smaller.
747189a to
34e98e8
Compare
There are some edge case bugs and this is a net new feature (non-shadow DOM mergeStyles lacks this feature) so it's being removed from now to avoid further delaying this feature.
This class extends Stylesheet, augmenting it with shadow DOM support. Refactoring the implementation this way allows us to avoid a large bundle size hit for non-shadow DOM users.
spmonahan
added a commit
that referenced
this pull request
Mar 23, 2024
Co-authored-by: KHMakoto <Humberto.Morimoto@microsoft.com>
spmonahan
added a commit
that referenced
this pull request
Mar 26, 2024
Co-authored-by: KHMakoto <Humberto.Morimoto@microsoft.com>
spmonahan
added a commit
that referenced
this pull request
Mar 28, 2024
Co-authored-by: KHMakoto <Humberto.Morimoto@microsoft.com>
spmonahan
added a commit
to spmonahan/fluentui
that referenced
this pull request
Mar 29, 2024
Co-authored-by: KHMakoto <Humberto.Morimoto@microsoft.com>
spmonahan
added a commit
that referenced
this pull request
Apr 4, 2024
Co-authored-by: KHMakoto <Humberto.Morimoto@microsoft.com>
spmonahan
added a commit
that referenced
this pull request
Apr 15, 2024
Co-authored-by: KHMakoto <Humberto.Morimoto@microsoft.com>
spmonahan
added a commit
that referenced
this pull request
Apr 18, 2024
Co-authored-by: KHMakoto <Humberto.Morimoto@microsoft.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.


Previous Behavior
The Shadow DOM feature in Fluent v8 introduces a large bundle size hit for users who are not using the shadow DOM feature.
New Behavior
There is still a bundle size hit but it has be reduced a fair bit. There is more work to do here I think but this is a good start and ready to be merged into
shadow-dom.This refactor focuses on two things:
@fluentui/merge-styles. This is accomplished by refactoringStylesheetto have less code and moving optional functions out ofStylesheetso they become pay-to-play.