Skip to content

Refactor exports for improved tree-shaking and add sideEffects declarations#1

Open
it-rec wants to merge 266 commits into
mainfrom
claude/tree-shaking-bundle-size-nndbmc
Open

Refactor exports for improved tree-shaking and add sideEffects declarations#1
it-rec wants to merge 266 commits into
mainfrom
claude/tree-shaking-bundle-size-nndbmc

Conversation

@it-rec

@it-rec it-rec commented Jun 9, 2026

Copy link
Copy Markdown
Owner

This PR improves tree shaking across Carbon packages by adding explicit sideEffects declarations and removing module-scope patterns that bundlers cannot prove side-effect-free.

Changelog

Changed

  • Added sideEffects declarations to package.json:
    • @carbon/layout, @carbon/motion, @carbon/type, @carbon/grid, @carbon/elements: only style entry points (index.scss, scss/, css/) are declared side-effectful
    • @carbon/icons, @carbon/pictograms: "sideEffects": false
  • Annotated top-level token initializers (rem(), px(), miniUnits()) in @carbon/layout and @carbon/type with /*#__PURE__*/
  • @carbon/type: exported font weights, font families, and type scale steps (scale01scale23) as scalar constants and referenced them as plain identifiers in token definitions — module-scope member accesses like fontWeights.regular or scale[0] read as potential getter side effects to bundlers and block tree shaking of otherwise-unused tokens
  • @carbon/type: fluid() computes the breakpoint name list lazily instead of at module scope
  • @carbon/type: inlined the two spread-based expressiveHeading01/02 tokens so each token can be dropped independently

Unchanged

  • Public APIs, export lists (verified: 69 exports in @carbon/type, zero diff vs. published), and all token values (deep-compared built outputs against the published packages)
  • @carbon/react and @carbon/web-components configuration — @carbon/react already tree-shakes correctly, and web-components' custom-element registration is an intentional side effect

Bundle size impact

Measured by bundling a single token import (e.g. import { blue60 } from '@carbon/elements') in production mode, React externalized, one isolated build per entry. "Before" = published packages (@carbon/type@11.61.0 et al.); "after" = this branch. Sizes are minified bytes (gzip).

Bundler @carbon/elements @carbon/type @carbon/layout
webpack 5 1,351 (456) → 46 (78) 1,420 (505) → 176 (175) 309 (186) → 69 (96)
esbuild 6,140 (1,313) → 32 (64) 6,131 (1,303) → 142 (149) 518 (301) → 63 (89)
Vite 7 (rolldown-vite) 2,221 (756) → 23 (55) 2,278 (755) → 121 (135) 288 (174) → 56 (86)
Rollup 4 (+terser) 24 (56) → 24 (56) 136 (150) → 126 (143) 39 (68) → 47 (76)¹

¹ +8 B from an un-folded IIFE in the rebuilt output (cosmetic terser artifact, same semantics).

Per-bundler notes for reviewers:

  • esbuild benefits most — it treats any module-scope call or member access as potentially side-effectful, so before this change a single type token dragged in the entire 6 KB token bundle.
  • webpack partially compensated via its innerGraph analysis but still left 1.3–1.4 KB of unused tokens per import; now near-optimal.
  • Vite (rolldown) sits between the two and needed both the sideEffects metadata and the purity fixes to reach ~optimal output (95–99 % reduction).
  • Rollup was already near-optimal thanks to its deep statement-level purity analysis — it is unaffected by this change, which also serves as an independent regression check that the rewritten modules are semantically equivalent.
  • @carbon/react component bundles (Button: ~50 KB min across bundlers) are unchanged — the package was already correctly configured; the wins land for anyone importing from the token packages directly or transitively (e.g. @carbon/elements).

Testing / Reviewing

  • All @carbon/type and @carbon/layout unit tests pass (261 tests, 67 snapshots)
  • Public export lists and token values deep-compared against the published packages — zero differences
  • Bundle measurements above reproduce with single-import fixtures against the built es/ outputs

PR Checklist

  • Reviewed every line of the diff
  • Updated documentation and storybook examples
  • Wrote passing tests that cover this change
  • Addressed any impact on accessibility (a11y)
  • Tested for cross-browser consistency
  • Validated that this code is ready for review and status checks should pass

https://claude.ai/code/session_01TtzyHZUPcnLbC128bSn9Lr

riddhybansal and others added 30 commits April 30, 2026 18:38
* feat: fluid combo box

* fix: ai label styles

* chore: format

---------

Co-authored-by: Mahmoud <maradwan26@gmail.com>
…em#22146)

* fix(docs-multiselect): unnecessary type assertion

* refactor: remove unnecessary type assertions

---------

Co-authored-by: Heloise Lui <71858203+heloiselui@users.noreply.github.com>
… from submenu item to parent menu item" (carbon-design-system#22142)

* Revert "fix(menu): nested menu closes unexpectedly when hovering back from su…"

This reverts commit 4790820.

* test: add test
…gn-system#21297)

* fix(a11y): use aria-errormessage for invalid text inputs

* fix(a11y): use aria-errormessage for invalid text inputs and add tests

* Apply suggestion from @sangeethababu9223

Co-authored-by: Sangeetha Babu <sangeetha9223@gmail.com>

* fix(textinput): yarn format

* fix(text-input): align invalid helper aria and add tests

---------

Co-authored-by: Heloise Lui <71858203+heloiselui@users.noreply.github.com>
Co-authored-by: Sangeetha Babu <sangeetha9223@gmail.com>
Co-authored-by: “heloiselui” <helolui27@gmail.com>
…esign-system#22061)

* chore(deps): update dependency typescript-eslint to v8.58.2

* chore: yarn dedupe

* chore: yarn dedupe

* chore(button): refactor kind predicate param into an overload signature

* fix: remove brace-expansion resolution

* chore: yarn dedupe

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Taylor Jones <taylor.jones826@gmail.com>
Co-authored-by: Riddhi Bansal <41935566+riddhybansal@users.noreply.github.com>
Co-authored-by: riddhybansal <41935566+riddhybansal@users.noreply.github.com>
…n-design-system#22154)

* feat(react): add hidden story for Pagination tooltip hover VRT

* fix: added delay for chromatic
* chore: upgrade Storybook to 10.3.5

* chore: yarn dedupe

* chore(deps): remove brace-expansion resolutions entry

* fix(tests): remove storybook actions call

* fix(tests): refactor storybook actions use in tests
…design-system#22175)

Bumps [github/codeql-action](https://github.com/github/codeql-action) from 4.35.2 to 4.35.3.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](github/codeql-action@95e58e9...e46ed2c)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-version: 4.35.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…arbon-design-system#22174)

Bumps [slackapi/slack-github-action](https://github.com/slackapi/slack-github-action) from 3.0.2 to 3.0.3.
- [Release notes](https://github.com/slackapi/slack-github-action/releases)
- [Changelog](https://github.com/slackapi/slack-github-action/blob/main/CHANGELOG.md)
- [Commits](slackapi/slack-github-action@03ea543...45a88b9)

---
updated-dependencies:
- dependency-name: slackapi/slack-github-action
  dependency-version: 3.0.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…n-system#22176)

Bumps [chromaui/action](https://github.com/chromaui/action) from 16.6.0 to 16.6.3.
- [Release notes](https://github.com/chromaui/action/releases)
- [Changelog](https://github.com/chromaui/action/blob/main/CHANGELOG.md)
- [Commits](chromaui/action@cad4097...42839e8)

---
updated-dependencies:
- dependency-name: chromaui/action
  dependency-version: 16.6.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* feat(cds-fluid-form): new wc component

* fix(fluid-components): add flex style

* fix: hide modal-container overflow

* feat: sync stories

* feat(fluidform): storycontrols in react and wc

* fix(fluid-password-input): remove excess bottom padding

* test: add tests

* fix: datepicker controls

* chore: clean up imports

* fix: passwordinput default alignment

---------

Co-authored-by: Heloise Lui <71858203+heloiselui@users.noreply.github.com>
…2179)

Bumps [axios](https://github.com/axios/axios) from 0.21.1 to 0.21.4.
- [Release notes](https://github.com/axios/axios/releases)
- [Changelog](https://github.com/axios/axios/blob/v0.21.4/CHANGELOG.md)
- [Commits](axios/axios@v0.21.1...v0.21.4)

---
updated-dependencies:
- dependency-name: axios
  dependency-version: 0.21.4
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…#22163)

* fix: use controls exclude for fixed story props

* fix: remove unnecessary story controls
* chore: update Next.js examples to v16

* fix(examples): correct root pathing problems with turborepo

* ci(examples): add elements previews ci check
…design-system#22091)

The vertical-tabs nav-item-label rule in
packages/styles/scss/components/tabs/_tabs.scss was emitting a
hard-coded --cds-body-compact-01-line-height literal, breaking
consumers who configure $prefix to anything other than the default.
Per review feedback, the token reference now resolves through
custom-property.get-var('body-compact-01-line-height'), matching the
existing usage of the same utility further up in the file (line 62,
layout-size-height-xl) and centralising the variable naming in one
place.

Also adds a SassRenderer test that compiles the tabs mixin with
$prefix: 'test' and asserts the emitted CSS references
--test-body-compact-01-line-height rather than the --cds- literal.

Signed-off-by: gabrielhamalwa <75419495+gabrielhamalwa@users.noreply.github.com>
Co-authored-by: Sangeetha Babu <sangeetha9223@gmail.com>
* refactor: replace any with stricter types

* refactor: simplify ComboButton middleware typing
…sign-system#22139)

* fix: number input react controlled vs uncontrolled handling

* refactor: move tests to respective controlled and uncontrolled blocks

* chore: add todo for re-organizing stories for better clarity

* fix: ai-label story

---------

Co-authored-by: Heloise Lui <71858203+heloiselui@users.noreply.github.com>
Co-authored-by: riddhybansal <41935566+riddhybansal@users.noreply.github.com>
* revert overflowmenu child typing

* test(overflowmenu): cover mixed children

* fix(actions): update dockerfile to use npm

---------

Co-authored-by: Heloise Lui <71858203+heloiselui@users.noreply.github.com>
…ck (carbon-design-system#22187)

Co-authored-by: Mahmoud <132728978+maradwan26@users.noreply.github.com>
baadhira and others added 29 commits June 30, 2026 19:17
…on-design-system#21517)

* chore: clean up unnecessary and non-working storybook overrides

* fix: text selection highlight color and backgrounds

* fix: multiple storybook inconsistencies

* fix: wc multiple storybook issues

* fix: wc text selection highlight issue

* revert: fluid search role description

---------

Co-authored-by: Sunny Kukkar <sunny.kukkar@ibm.com>
Co-authored-by: Sangeetha Babu <sangeetha9223@gmail.com>
Co-authored-by: Taylor Jones <tay1orjones@users.noreply.github.com>
…21840)

* docs: rewrite README and drop all-contributors

* docs: remove deprecated Angular icons reference
…em#22552)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Mahmoud <132728978+maradwan26@users.noreply.github.com>
…-system#22492)

* fix(accordion): apply hover styles only with any-hover

* fix(accordion): guard hover styles with any-hover

* style(accordion): remove redundant hover comments

---------

Co-authored-by: Heloise Lui <71858203+heloiselui@users.noreply.github.com>
Co-authored-by: heloiselui <71858203+heloiselui@users.noreply.github.com>
* chore: upgrade typescript to v6

* test(tabs): add hidden tab check after auto-height effect

* chore: add ts dependency to react and webcomponent packages

* test(vertical-tabs): fix auto-height test target

* test(tabs): apply pr review suggestion

---------

Co-authored-by: Heloise Lui <71858203+heloiselui@users.noreply.github.com>
Co-authored-by: Taylor Jones <taylor.jones826@gmail.com>
…al (carbon-design-system#22528)

- Added @query decorator for slot[name='panel'] element
- Replaced shadowRoot querySelector with cached property
- Improved performance through Lit's automatic query caching
- tabs.ts already uses @query decorators correctly

Closes carbon-design-system#22505
…arbon-design-system#22566)

* fix(overflow-menu): improve color contrast for danger button option

* chore: use the convert to

* fix: add boxshadow for menu and combo button

---------

Co-authored-by: Heloise Lui <71858203+heloiselui@users.noreply.github.com>
…ption (carbon-design-system#22488)

* fix(Notification): use status icon description for icon label

* test(Notification): remove hanging actionable notification test

* test(notification): add test for accessible status icon label
Co-authored-by: Sangeetha Babu <sangeetha9223@gmail.com>
…arbon-design-system#22530)

* fix(web-components): replace querySelector with @query in toggletip

- Added @query decorators for button, content, and caret elements
- Replaced 3 querySelector calls with cached properties
- Improved performance through Lit's automatic query caching
- Simplified updated() method logic

Closes carbon-design-system#22503

* Update packages/web-components/src/components/toggle-tip/toggletip.ts

Co-authored-by: Adam Alston <aalston9@gmail.com>

---------

Co-authored-by: Adam Alston <aalston9@gmail.com>
…-design-system#22533)

* fix(web-components): replace querySelector with @query in search

- Added @query decorators for input and magnifier elements
- Replaced 2 querySelector calls with cached properties
- Removed non-null assertion for better code safety
- Improved performance through Lit's automatic query caching

Closes carbon-design-system#22499

* test(web-components): add @query decorator tests for search

Added 8 comprehensive test cases to verify @query decorator functionality
including focus management, element caching, and keyboard interactions.

Related to carbon-design-system#22499
…ign-system#22535)

* refactor(tags): use query decorator for tag elements

* refactor(tag): remove nullability from properties
* test: run scss generator tests separately

* test: collect scss generator coverage

* ci: merge scss generator coverage before upload

---------

Co-authored-by: Sangeetha Babu <sangeetha9223@gmail.com>
…22615)

* chore(deps): bump sigstore from 4.0.0 to 4.1.1

Bumps [sigstore](https://github.com/sigstore/sigstore-js) from 4.0.0 to 4.1.1.
- [Release notes](https://github.com/sigstore/sigstore-js/releases)
- [Commits](https://github.com/sigstore/sigstore-js/compare/sigstore@4.0.0...sigstore@4.1.1)

---
updated-dependencies:
- dependency-name: sigstore
  dependency-version: 4.1.1
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

* chore: yarn dedupe

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: “heloiselui” <helolui27@gmail.com>
Co-authored-by: Heloise Lui <71858203+heloiselui@users.noreply.github.com>
…em#22215)

* chore: initial commit

* chore: update js docs

* refactor: reuse definition tooltip

* test: add test coverage

* revert: 20 size story

* chore: expose props

* revert: revert to commit 3398908

Reverting changes made after commit 3398908 to restore the
initial compact mode implementation for IconIndicator component.

* feat: add compact feature in wc in parity with react

* feat: compact mode in shape indicator react & wc

* fix: auto align in definition tooltip

* fix: hover glitch

* fix: test on mouse leave

* fix: update public api for preview/unstable icon shape indicators

* test: 100% coverage

* test: bump remaining files test coverage

* fix: custom incomplete svg test and add cleanup todo

* chore: clean up old styles

* docs: mention compact mode in storybook docs

* docs: update jsdocs for description in compact mode

* fix: unset line-height on shape indicator to match icon size

* refactor: simplify css var block padding

* Revert "refactor: simplify css var block padding"

This reverts commit f0a003f.

* fix: re-use custom property mixin

* chore: remove any and comment

* chore: update copyright years

* Apply suggestion from @adamalston

Co-authored-by: Adam Alston <aalston9@gmail.com>

* Update packages/react/src/components/IconIndicator/__tests__/IconIndicator-test.js

Co-authored-by: Adam Alston <aalston9@gmail.com>

* fix: review suggestions

---------

Co-authored-by: Kritvi <158570656+Kritvi-bhatia17@users.noreply.github.com>
Co-authored-by: Adam Alston <aalston9@gmail.com>
…m#22322)

* docs: add pagination data table stories

* fix: render issue with react definition

* chore: update to toolbar example as per spec

* fix: add settings icon

* fix: header text case

* chore: add new year in license

* Update packages/web-components/src/components/data-table/stories/data-table-pagination.stories.ts

Co-authored-by: Heloise Lui <71858203+heloiselui@users.noreply.github.com>

* fix: review comments reuse getProps

* feat: add filtering support

* docs: update stories with performant examples

---------

Co-authored-by: Heloise Lui <71858203+heloiselui@users.noreply.github.com>
Co-authored-by: Sangeetha Babu <sangeetha9223@gmail.com>
…n-system#22633)

Bumps [chromaui/action](https://github.com/chromaui/action) from 17.8.0 to 18.0.1.
- [Release notes](https://github.com/chromaui/action/releases)
- [Changelog](https://github.com/chromaui/action/blob/main/CHANGELOG.md)
- [Commits](chromaui/action@98132da...94713c5)

---
updated-dependencies:
- dependency-name: chromaui/action
  dependency-version: 18.0.1
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…gn-system#22631)

Bumps [dorny/paths-filter](https://github.com/dorny/paths-filter) from 4.0.1 to 4.0.2.
- [Release notes](https://github.com/dorny/paths-filter/releases)
- [Changelog](https://github.com/dorny/paths-filter/blob/master/CHANGELOG.md)
- [Commits](dorny/paths-filter@fbd0ab8...7b450ff)

---
updated-dependencies:
- dependency-name: dorny/paths-filter
  dependency-version: 4.0.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Declare sideEffects in package.json for @carbon/layout, @carbon/motion,
@carbon/type, @carbon/grid, @carbon/elements, @carbon/icons, and
@carbon/pictograms so bundlers can drop unused modules instead of
assuming every module is side-effectful. Style entry points (index.scss,
scss/, css/) remain declared side-effectful where the packages ship them.

Remove module-scope patterns that blocked statement-level tree shaking of
individual tokens:

- Annotate top-level rem()/miniUnits()/px() token initializers in
  @carbon/layout and @carbon/type with /*#__PURE__*/.
- Export font weights, font families, and type scale steps as scalar
  constants and reference them as plain identifiers, since module-scope
  member accesses like fontWeights.regular or scale[0] read as potential
  getter side effects to bundlers and block tree shaking of otherwise
  unused tokens.
- Compute the breakpoint name list in @carbon/type fluid() lazily.
- Inline the two spread-based expressive heading tokens.

Public APIs, export lists, and token values are unchanged.

Signed-off-by: Mika <19797875+it-rec@users.noreply.github.com>
@it-rec
it-rec force-pushed the claude/tree-shaking-bundle-size-nndbmc branch from 3006e2b to f34b6a7 Compare July 7, 2026 20:33
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.