Skip to content

fix: narrow sideEffects globs so unused components tree-shake - #3436

Closed
sh0ji wants to merge 2 commits into
mainfrom
fix/GMT-1788-narrow-gamut-sideeffects-globs
Closed

sh0ji wants to merge 2 commits into
mainfrom
fix/GMT-1788-narrow-gamut-sideeffects-globs

Conversation

@sh0ji

@sh0ji sh0ji commented Sep 15, 2026 •

Copy link
Copy Markdown
Member

Overview

packages/gamut/package.json's sideEffects field includes two catch-all globs, dist/**/[A-Z]**/[A-Z]*.js and dist/**/[A-Z]**/index.js, which match nearly every component directory (all are capitalized). That makes webpack treat almost the entire compiled package as side-effecting, so it won't drop unused exports from the barrel (src/index.tsx) — including Video, which statically imports react-player. A consumer that pulls in gamut via a Module Federation shared singleton (loading the barrel directly, not through its own imports) ends up with react-player's per-provider chunks (DailyMotion, YouTube, Vimeo, etc.) in its bundle even when it never renders <Video>.

These globs came from #932 (2020), which replaced two explicit entries (dist/ButtonBase/index.js, dist/Card/CardShell.js) with the catch-all pattern. @jakemhiller's rationale: "all components that import CSS Modules have side-effects... going to keep popping up," flagging the approach as "kind of ugly" and expecting the then-in-progress Emotion migration to change the calculus later.

That migration is done. src has zero *.module.css/*.module.scss files today, and the one remaining raw CSS import (Video/lib/VidstackPlayer/index.tsx) is already covered by the separate **/*.css glob. The premise for the catch-all no longer holds, so this drops it and keeps only the CSS/SCSS globs — the same explicit-entry model #932 moved away from, minus the problem that motivated the move.

gamut-illustrations had the identical catch-all with no CSS imports anywhere in its source, so it moves to sideEffects: false, matching gamut-icons/gamut-patterns.

PR Checklist

  • Related to designs: n/a
  • Related to JIRA ticket: GMT-1788
  • Version plan added/updated (or not needed)
  • I have run this code to verify it works
  • This PR includes unit tests for the code change
  • This PR includes testing instructions tests for the code change
  • The alpha package of this PR is passing end-to-end tests in all relevant Codecademy repositories

Testing Instructions

  1. yarn nx build gamut and yarn nx run gamut:verify — both pass (build output and type-check unaffected by sideEffects metadata itself).
  2. sideEffects only affects consumer bundler behavior, not this repo's own build. Verify in a downstream consumer: run its production webpack build before/after bumping to this version and confirm the reactPlayer* provider chunks disappear when <Video> isn't used.
  3. Before merging, diff Storybook snapshots against main to confirm no component regresses from losing the catch-all — a regression would mean it has a real eval-order dependency independent of CSS Modules, and needs an explicit entry added back (same model as the pre-fix: add sideEffects globs that catch all components #932 ButtonBase/CardShell entries).

Jira

GMT-1788

dist/**/[A-Z]**/index.js and dist/**/[A-Z]**/[A-Z]*.js match nearly every
component directory, so webpack treats almost the whole compiled package
as side-effecting and won't drop unused barrel exports (e.g. Video, which
drags in react-player's per-provider chunks even when unused).

These globs replaced two explicit file entries in #932 (2020) to cover
CSS Modules side effects. That migration to Emotion is done; src has no
remaining *.module.css/scss files, and the one raw CSS import left
(VidstackPlayer) is already covered by the **/*.css glob. Dropping the
catch-all restores tree-shaking without losing real side-effect coverage.

gamut-illustrations had the identical catch-all with no CSS imports at
all, so it moves to sideEffects: false, matching gamut-icons/gamut-patterns.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@sh0ji
sh0ji requested a review from a team as a code owner September 15, 2026 20:26

@jakemhiller jakemhiller left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

worth testing the alpha package, but i think this will be fine

@nx-cloud

nx-cloud Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 21bd648


☁️ Nx Cloud last updated this comment at 2026-09-15 20:35:19 UTC

@codecov

codecov Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

⚠️ JUnit XML file not found

The CLI was unable to find any JUnit XML files to upload.
For more help, visit our troubleshooting guide.

@codecademydev

Copy link
Copy Markdown
Collaborator

📬 Published Alpha Packages:

Package Version npm Diff
@codecademy/gamut 73.6.2-alpha.ae5bae.0 npm diff
@codecademy/gamut-icons 10.2.1-alpha.ae5bae.0 npm diff
@codecademy/gamut-illustrations 1.1.1-alpha.ae5bae.0 npm diff
@codecademy/gamut-kit 3.0.25-alpha.ae5bae.0 npm diff
@codecademy/gamut-patterns 1.1.1-alpha.ae5bae.0 npm diff
@codecademy/gamut-styles 21.2.1-alpha.ae5bae.0 npm diff
@codecademy/gamut-tests 7.1.1-alpha.ae5bae.0 npm diff
@codecademy/variance 1.1.1-alpha.ae5bae.0 npm diff
eslint-plugin-gamut 3.1.1-alpha.ae5bae.0 npm diff

@github-actions

Copy link
Copy Markdown
Contributor

@sh0ji

sh0ji commented Sep 24, 2026

Copy link
Copy Markdown
Member Author

closing this because it doesn't solve the core problem and it's superseded by the much more robust #3439

@sh0ji sh0ji closed this Sep 24, 2026
@sh0ji
sh0ji deleted the fix/GMT-1788-narrow-gamut-sideeffects-globs branch September 24, 2026 19:36
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.

3 participants