Skip to content

build(storybook): swap Emotion's Babel transform for @swc/plugin-emotion - #18

Draft
dreamwasp wants to merge 1 commit into
cass-gmt-1741from
cass-gmt-1795
Draft

dreamwasp wants to merge 1 commit into
cass-gmt-1741from
cass-gmt-1795

Conversation

@dreamwasp

@dreamwasp dreamwasp commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Summary

Storybook's Vite preview build currently reaches for Babel just to run
@emotion/babel-plugin (readable class names + Emotion source maps) — Babel
is otherwise gone from this repo since the tsdown migration. This swaps that
one caller for @vitejs/plugin-react-swc + @swc/plugin-emotion, so
Storybook's build no longer touches Babel at all.

  • Dev-loop HMR turnaround is meaningfully faster: ~3–5x per-edit in local
    measurement (median ~43ms vs ~231ms across 5 warm samples each, editing one
    line in a story file and timing to Vite's page reload log line). This is
    the actual win — it compounds on every save during yarn storybook.
  • Cold yarn build-storybook time is roughly a wash (15.6–21.2s vs
    18.3–18.5s Vite build step across 2 runs each)
  • autoLabel/labelFormat parity confirmed — generated classes still come
    out as gamut-<hash>-<ComponentName>, matching the Babel plugin's output
    shape.
  • test:stories unchanged: 87/87 files, 493/493 tests passing.

Version pin is load-bearing, not incidental. @vitejs/plugin-react-swc,
@swc/plugin-emotion, and @swc/core (forced via resolutions) are pinned
to versions from the same release window (June–July 2026) rather than
latest. The latest of each (Sept 2026, days apart) crashes with an opaque
WASM panic on real .stories.tsx/.mdx files — an undocumented ABI
mismatch between the plugin and swc_core that plugins.swc.rs's own
compatibility lookup doesn't yet have data for. Left a comment in main.ts
so a routine dependency bump doesn't silently reintroduce this. Full repro
and investigation notes are in my local spike doc if anyone wants the details.

Test

  • yarn build-storybook succeeds, including all .mdx doc pages
  • yarn test:stories — 87/87 files, 493/493 tests
  • yarn start:storybook — dev server starts clean, no console errors
  • Generated class names match autoLabel: 'always' / labelFormat: '[local]' parity
  • BarChart/elements.tsx explicit target: 'gmt-category-label' call site unaffected (it's a styled() runtime arg, not transform output)
  • Second reviewer sanity-checks the version-pin approach before merge
  • Re-measure HMR latency against a plain component source file (not a .stories.tsx, which triggers full page reload rather than a granular HMR swap) if the number needs to hold up further

Storybook's Vite preview now uses @vitejs/plugin-react-swc +
@swc/plugin-emotion instead of @vitejs/plugin-react + @emotion/babel-plugin,
removing Babel from Storybook's build pipeline. Speeds up the dev-loop HMR
turnaround (~3-5x faster per-edit in local measurement); cold
build-storybook time is roughly a wash.

@vitejs/plugin-react-swc, @swc/plugin-emotion, and the @swc/core resolution
are pinned to versions from the same release window (June-July 2026) rather
than latest - newer combinations crash with an undocumented WASM/ABI
mismatch between the plugin and swc_core. Bump these three together.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@dreamwasp
dreamwasp changed the base branch from main to cass-gmt-1741 September 18, 2026 19:40
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