Skip to content

Conversation

CampbellOwen
Copy link
Contributor

@CampbellOwen CampbellOwen commented Sep 17, 2025

Related: https://github.com/microsoft/fluentai/pull/3349

When the styles.ts files are preprocessed by griffel's AoT compilation, navItemTokens becomes dead code. However, in certain cases it can still cause the tokens import to be included in the final bundle if webpack can't do module concatenation. This can happen when multiple components from this package are used across separate chunks (e.g. lazy loading one of the components). When this happens, even though navItemTokens itself is removed as dead code, the import of tokens can still remain as Terser doesn't know about sideEffects:false from package.json.

This change moves navItemTokens to a different file. Now when the styles are preprocessed this object is not present in the styles file and is just an import that's unused. Unused imports seem to be much easier for webpack to prune and this makes it more unlikely that these styles will force tokens to be included in the final bundle.

This shouldn't change the bundle size in general, but it should make it easier for downstream apps to not face bloated bundle sizes in certain conditions.

Copy link

github-actions bot commented Sep 17, 2025

📊 Bundle size report

Package & Exports Baseline (minified/GZIP) PR Change
react-components
react-components: entire library
1.284 MB
323.352 kB
1.284 MB
323.325 kB
-161 B
-27 B
react-nav
Nav (including children components)
0 B
0 B
244.93 kB
68.778 kB
🆕 New entry
Unchanged fixtures
Package & Exports Size (minified/GZIP)
react-components
react-components: Button, FluentProvider & webLightTheme
68.796 kB
19.903 kB
react-components
react-components: Accordion, Button, FluentProvider, Image, Menu, Popover
236.691 kB
68.567 kB
react-components
react-components: FluentProvider & webLightTheme
43.63 kB
14.257 kB
react-portal-compat
PortalCompatProvider
8.386 kB
2.624 kB
react-timepicker-compat
TimePicker
109.935 kB
36.335 kB
🤖 This report was generated against fdb651c09b833a2cd9a7ae219000f33a4a906dd6

Copy link

Pull request demo site: URL

@@ -0,0 +1,7 @@
{

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕵🏾‍♀️ visual changes to review in the Visual Change Report

vr-tests-react-components/Avatar Converged 1 screenshots
Image Name Diff(in Pixels) Image Type
vr-tests-react-components/Avatar Converged.badgeMask.normal.chromium.png 1 Changed
vr-tests-react-components/Charts-DonutChart 2 screenshots
Image Name Diff(in Pixels) Image Type
vr-tests-react-components/Charts-DonutChart.Dynamic - RTL.default.chromium.png 30793 Changed
vr-tests-react-components/Charts-DonutChart.Dynamic.default.chromium.png 27053 Changed
vr-tests-react-components/Drawer 1 screenshots
Image Name Diff(in Pixels) Image Type
vr-tests-react-components/Drawer.overlay drawer large - Dark Mode.chromium.png 715 Changed
vr-tests-react-components/Positioning 2 screenshots
Image Name Diff(in Pixels) Image Type
vr-tests-react-components/Positioning.Positioning end.updated 2 times.chromium.png 932 Changed
vr-tests-react-components/Positioning.Positioning end.chromium.png 911 Changed

@CampbellOwen CampbellOwen changed the title Extract shared tokens react-nav: Improve tree shaking by moving token exports out of styles file Sep 19, 2025
@CampbellOwen CampbellOwen marked this pull request as ready for review September 19, 2025 00:32
@CampbellOwen CampbellOwen requested review from marcosmoura and a team as code owners September 19, 2025 00:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant