react-nav: Improve tree shaking by moving token exports out of styles file #35207
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.
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 thetokens
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 thoughnavItemTokens
itself is removed as dead code, the import oftokens
can still remain as Terser doesn't know aboutsideEffects: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 forcetokens
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.