Skip to content

feat(react): emit per-component CSS token slices#132

Merged
wangdicoder merged 2 commits intomasterfrom
feat/per-component-css-token-slices
Apr 25, 2026
Merged

feat(react): emit per-component CSS token slices#132
wangdicoder merged 2 commits intomasterfrom
feat/per-component-css-token-slices

Conversation

@wangdicoder
Copy link
Copy Markdown
Owner

@wangdicoder wangdicoder commented Apr 25, 2026

Summary

  • Replaces the monolithic 240 KB base.css token registry with per-tier (foundation.css, semantic.css) and per-component slice files (components/<name>.css).
  • Each compiled component entry now imports only the slices it actually needs, computed by closure over both var(--ty-*) references and style/index.tsx SCSS imports.
  • base.css is still emitted for backward compatibility — no breaking change for direct importers.
  • ConfigProvider source is unchanged; runtime theming (inline styles + data-tiny-theme attribute) works identically.

Bundle impact (Vite 5, esbuild minify)

Bundle Before After Change
Button-only CSS 261 KB raw / 36 KB gzip 103 KB raw / 7.5 KB gzip −60% raw, −79% gzip
Modal-only CSS 270 KB raw / 37 KB gzip 116 KB raw / 9.0 KB gzip −57% raw, −76% gzip
Full-library CSS 509 KB raw 515 KB raw +1% (negligible)

JS bundle size is unchanged.

Release

  • Bump: minor
  • Affected: @tiny-design/react, @tiny-design/tokens (fixed-version group bumps @tiny-design/icons along)

Test plan

  • pnpm --filter @tiny-design/tokens test passes (consumer contract check still validates 1283/1665 vars)
  • pnpm --filter @tiny-design/react test passes (98 suites, 810 tests, 81 snapshots)
  • pnpm --filter @tiny-design/docs build succeeds
  • Bundle isolation verified: Button-only build contains only --ty-button-* component vars (1056 declarations across light/dark/system), zero leakage from --ty-modal-*, --ty-form-*, --ty-table-*
  • Cross-component closure correct: modal → [button, modal, overlay], tour → [button, popover, popup, tour], transfer → [button, checkbox, empty, input, transfer]
  • Visual regression on docs site (manual): toggle light/dark mode, click through Button/Modal/Form/Select/Table/Tour pages

What changed

  • packages/tokens/scripts/build-runtime.js — adds closure computation that scans each packages/react/src/<dir> for var(--ty-*) refs and follows style/index.tsx SCSS imports transitively. Emits per-tier + per-component slice files plus a component-deps.json manifest.
  • packages/react/scripts/build-styles.js — copies the new CSS files and manifest into es/style/ and lib/style/.
  • packages/react/scripts/inject-style-imports.js — reads the manifest and injects foundation.css + semantic.css + per-component slice imports into each component's compiled index.js. Barrel injects only foundation + semantic; component slices come through component imports.

🤖 Generated with Claude Code

Replaces the monolithic 240KB base.css with per-tier (foundation,
semantic) and per-component slice files. Each component entry now
imports only the slices it actually needs, computed by closure over
both var(--ty-*) references and style/index.tsx SCSS imports.

Per-component CSS bundles drop ~60% raw / ~80% gzipped (Button:
261KB->103KB raw, 36KB->7.5KB gzip). Full-library bundle size is
unchanged. base.css is still emitted for backward compatibility.
@wangdicoder wangdicoder force-pushed the feat/per-component-css-token-slices branch from 0c81c84 to 4b5b141 Compare April 25, 2026 10:39
@wangdicoder wangdicoder merged commit e5335cf into master Apr 25, 2026
1 check passed
@wangdicoder wangdicoder deleted the feat/per-component-css-token-slices branch April 25, 2026 10:41
@github-actions github-actions Bot mentioned this pull request Apr 25, 2026
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