Skip to content

Enable Chromatic TurboSnap for the WC Storybook - #1494

Merged
brentswisher merged 7 commits into
developfrom
chore/turbosnap-tracing
Nov 11, 2026
Merged

brentswisher merged 7 commits into
developfrom
chore/turbosnap-tracing

Conversation

@brentswisher

@brentswisher brentswisher commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

This change: (check at least one)

  • Adds a new feature
  • Fixes a bug
  • Improves maintainability
  • Improves documentation
  • Is a release activity

Is this a breaking change? (check one)

  • Yes
  • No

Is the: (complete all)

  • Title of this pull request clear, concise, and indicative of the issue number it addresses, if any?
  • Test suite(s) passing?
  • Code coverage maximal?
  • Changeset added? (not needed: Storybook and CI only, no consumer-facing change)

What does this change address?

Resolves #514. Supersedes draft #1344.

Every Chromatic build currently is performing a full run (~1,230 snapshots: 246 stories × 4 browsers + a11y). TurboSnap can reduce our usage, but has never worked because WC stories rendered <storybook-pharos-*> tags registered globally by .storybook/initComponents.js from the gitignored lib/ build, so Chromatic couldn't trace any story to the components it renders.

How does this change work?

  • Adds a new helper (utils/_storybook/registerStorybookComponents.ts) which wraps registerComponents('storybook', …) and imports the actual component. This allows us to get the benefits of TurboPack while still using our current custom elements.
  • Every web component storiy now imports the classes it renders from src and registers them, so the build's import graph matches what each story renders.
  • The new helper skips tags that have already been defined on the page.
  • An afterEach errors for any story that renders an unregistered custom element. This prevents a silent failure if a new custom element is added without importing its component.
  • There were two things we needed to do to get things rendering correctly from src instead of lib
    • Icons use a dynamic import, which have no file extension in the src. (lib gets .js from build:replace:dynamic) Since the stores now use the source directly, a small Vite plugin in .storybook/wc/main.ts was added to add .ts to the icons so the icon files are bundled.
    • The HTML minification that happens at build removes a space between form elements and the required asterisk. Without the minification the stories rendered differently than the actual build so I also added a small vite plugin to match the minification when building the stories.

The following changes were also made to the chromatic config:

  • turns on onlyChanged
  • builds with --stats-json and fails if preview-stats.json is missing
  • adds externals for SCSS, tokens and assets, which can't be traced and trigger a full run

Testing Chromatic

I pushed a throwaway change to confirm TurboSnap works to this branch, then reverted it:

Commit Change Chromatic build Result
0c2ceba4 This PR 3388
85a94817 Added a one-line comment to pharos-alert.ts 3389 TurboSnap enabled. 2 affected story files (pharos-alert.wc.stories.ts, pharos-modal.wc.stories.ts); 50 snapshots captured, 944 copied; 10 of 246 tests run.
fccf4a3f Reverted the comment 3390 TurboSnap enabled. Same 2 story files; 50 captured, 944 copied.

@brentswisher brentswisher self-assigned this Nov 9, 2026
@changeset-bot

changeset-bot Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 285a17b

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size
packages/pharos/lib/index.js 56.4 KB (0%)

@brentswisher brentswisher changed the title chore(storybook): enable Chromatic TurboSnap for the WC Storybook (#514) Enable Chromatic TurboSnap for the WC Storybook Nov 9, 2026
brentswisher and others added 3 commits November 10, 2026 08:49
Stories now import and register the components they render, so
TurboSnap can trace which stories a change affects instead of
snapshotting every story on every build.

- Add registerStorybookComponents helper; each WC story and page
  template registers its own components from src
- Stop loading the global initComponents in the WC preview and fail
  stories that render unregistered elements
- Bundle src icon imports in the WC Storybook build
- Enable onlyChanged, stats file and externals in the Chromatic
  workflow; record PR head SHA/branch on manual runs

Resolves #514

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…erted)"

This reverts commit 85a9481.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@brentswisher
brentswisher force-pushed the chore/turbosnap-tracing branch from fccf4a3 to 21baa92 Compare November 10, 2026 13:49
brentswisher and others added 4 commits November 10, 2026 10:24
The build scripts and Style Dictionary config generate gitignored files
that the Storybook bundle imports, so TurboSnap cannot trace changes to
them. Listing them as externals forces a full Chromatic run instead of
silently skipping affected stories.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The TurboSnap commit reformatted seven component files and part of
reports-table.ts with no code changes. Restore their develop formatting
so the diff only contains the TurboSnap work and those components'
stories aren't flagged as changed. reports-table.ts keeps its
registerStorybookComponents call.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Stories now load components from src, whose html templates keep the
whitespace that build:minify:html strips from lib. The extra whitespace
rendered as a wider gap before the required indicator on form elements.
Apply minify-html-literals to component sources in the WC Storybook so
it renders identically to the published package.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Manual dispatch runs report the dispatching branch's SHA to Chromatic,
so TurboSnap could trace the wrong diff and skip changed stories. Keep
manual runs on the original /merge checkout with full snapshots, and
only enable onlyChanged for push events.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
storybookBuildDir: .storybook-static/wc
exitZeroOnChanges: true
exitOnceUploaded: true
onlyChanged: ${{ github.event_name == 'push' }}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This means manual runs will still run full suites but the changes to make that work seemed like it was adding a lot of complexity for something that happens pretty infrequently, so I went with this

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The workflow still targets the PR merge commit without SHA/branch overrides and groups manual runs by workflow ref, contradicting its description and allowing dispatches for different PRs to cancel one another.

1 open issue
What changed in this PR

Enables Chromatic TurboSnap for the web-component Storybook by making story dependencies traceable to component source files, addressing #514 without changing public component APIs.

Changes:

  • Adds duplicate-safe registration and explicit component imports across stories, page examples, and the CLI template.
  • Updates Storybook to bundle source icons, minify component HTML, detect unregistered elements, and filter internal documentation fields.
  • Enables changed-only snapshots for push builds, verifies dependency statistics, and configures full-run triggers for shared assets and styles.
File Description
packages/​pharos/​src/​utils/​_storybook/​registerStorybookComponents.ts Adds duplicate-safe Storybook registration.
packages/​pharos/​src/​utils/​_storybook/​GuidelineLink.tsx Registers the documentation link component.
packages/​pharos/​src/​styles/​tokens.wc.stories.ts Registers icons used in token stories.
packages/​pharos/​src/​pages/​shared/​wc/​header.ts Registers shared header dependencies.
packages/​pharos/​src/​pages/​shared/​wc/​header-revised.ts Registers revised header dependencies.
packages/​pharos/​src/​pages/​shared/​wc/​footer.ts Registers shared footer dependencies.
packages/​pharos/​src/​pages/​search/​wc/​search.pages.stories.ts Registers search page components.
packages/​pharos/​src/​pages/​search/​wc/​search-results/​search-results.ts Registers result-list controls.
packages/​pharos/​src/​pages/​search/​wc/​search-results/​search-results-item.ts Registers individual result components.
packages/​pharos/​src/​pages/​search/​wc/​image-results/​image-results.ts Registers image-list controls.
packages/​pharos/​src/​pages/​search/​wc/​image-results/​image-results-item.ts Registers image-result components.
packages/​pharos/​src/​pages/​search/​wc/​facets/​single-select-facet.ts Registers radio facet components.
packages/​pharos/​src/​pages/​search/​wc/​facets/​multi-select-facet.ts Registers checkbox facet components.
packages/​pharos/​src/​pages/​search/​wc/​facets/​facet-filters.ts Registers facet headings.
packages/​pharos/​src/​pages/​search/​wc/​facets/​date-range-facet.ts Registers date-filter controls.
packages/​pharos/​src/​pages/​reports/​wc/​sidenav.ts Registers report navigation components.
packages/​pharos/​src/​pages/​reports/​wc/​reports-table.ts Registers report-table controls.
packages/​pharos/​src/​pages/​reports/​wc/​reports-example.ts Registers report page components.
packages/​pharos/​src/​pages/​reports/​wc/​create-report-modal.ts Registers report-modal controls.
packages/​pharos/​src/​pages/​item-detail/​wc/​metadata.ts Registers metadata headings.
packages/​pharos/​src/​pages/​item-detail/​wc/​item-detail.pages.stories.ts Registers item-detail page components.
packages/​pharos/​src/​pages/​item-detail/​wc/​item-carousel/​item-carousel.ts Registers item-carousel controls.
packages/​pharos/​src/​pages/​item-detail/​wc/​item-carousel/​item-carousel-item.ts Registers item-carousel content components.
packages/​pharos/​src/​pages/​item-detail/​wc/​collection-carousel/​collection-carousel.ts Registers collection-carousel controls.
packages/​pharos/​src/​pages/​item-detail/​wc/​collection-carousel/​collection-carousel-item.ts Registers collection-carousel content components.
packages/​pharos/​src/​pages/​home/​wc/​home.pages.stories.ts Registers home page components.
packages/​pharos/​src/​pages/​home/​wc/​hero-search.ts Registers the search icon.
packages/​pharos/​src/​pages/​home/​wc/​collection-card.ts Registers collection-card components.
packages/​pharos/​src/​components/​tooltip/​pharos-tooltip.wc.stories.ts Registers tooltip story dependencies.
packages/​pharos/​src/​components/​toggle-button-group/​pharos-toggle-button-group.wc.stories.ts Registers toggle buttons and groups.
packages/​pharos/​src/​components/​toast/​pharos-toast.wc.stories.ts Registers toaster and story controls.
packages/​pharos/​src/​components/​textarea/​pharos-textarea.wc.stories.ts Registers textarea story dependencies.
packages/​pharos/​src/​components/​text-input/​pharos-text-input.wc.stories.ts Registers text-input story dependencies.
packages/​pharos/​src/​components/​tabs/​pharos-tabs.wc.stories.ts Registers tabs and table dependencies.
packages/​pharos/​src/​components/​table/​pharos-table.wc.stories.ts Registers table story dependencies.
packages/​pharos/​src/​components/​switch/​pharos-switch.wc.stories.ts Registers the switch component.
packages/​pharos/​src/​components/​slider/​pharos-slider.wc.stories.ts Registers slider story dependencies.
packages/​pharos/​src/​components/​sidenav/​pharos-sidenav.wc.stories.ts Registers sidenav story dependencies.
packages/​pharos/​src/​components/​sheet/​pharos-sheet.wc.stories.ts Registers sheet story dependencies.
packages/​pharos/​src/​components/​select/​pharos-select.wc.stories.ts Registers select story dependencies.
packages/​pharos/​src/​components/​radio-group/​pharos-radio-group.wc.stories.ts Registers radio-group story dependencies.
packages/​pharos/​src/​components/​radio-button/​pharos-radio-button.wc.stories.ts Registers dependencies and adds component metadata.
packages/​pharos/​src/​components/​progress-bar/​pharos-progress-bar.wc.stories.ts Registers the progress-bar component.
packages/​pharos/​src/​components/​popover/​pharos-popover.wc.stories.ts Registers popover story dependencies.
packages/​pharos/​src/​components/​pill/​pharos-pill.wc.stories.ts Registers pill story dependencies.
packages/​pharos/​src/​components/​pagination/​pharos-pagination.wc.stories.ts Registers the pagination component.
packages/​pharos/​src/​components/​multiselect-dropdown/​pharos-multiselect-dropdown.wc.stories.ts Registers multiselect story dependencies.
packages/​pharos/​src/​components/​modal/​pharos-modal.wc.stories.ts Registers modal story dependencies.
packages/​pharos/​src/​components/​loading-spinner/​pharos-loading-spinner.wc.stories.ts Registers spinner story dependencies.
packages/​pharos/​src/​components/​link/​pharos-link.wc.stories.ts Registers link story dependencies.
packages/​pharos/​src/​components/​layout/​pharos-layout.wc.stories.ts Registers layout story dependencies.
packages/​pharos/​src/​components/​input-group/​pharos-input-group.wc.stories.ts Registers input-group story dependencies.
packages/​pharos/​src/​components/​image-card/​pharos-image-card.wc.stories.ts Registers image-card story dependencies.
packages/​pharos/​src/​components/​icon/​pharos-icon.wc.stories.ts Registers the icon component.
packages/​pharos/​src/​components/​heading/​pharos-heading.wc.stories.ts Registers heading story dependencies.
packages/​pharos/​src/​components/​header/​pharos-header.wc.stories.ts Registers header story dependencies.
packages/​pharos/​src/​components/​dropdown-menu/​pharos-dropdown-menu.wc.stories.ts Registers dropdown-menu story dependencies.
packages/​pharos/​src/​components/​dropdown-menu-nav/​pharos-dropdown-menu-nav.wc.stories.ts Registers dropdown navigation dependencies.
packages/​pharos/​src/​components/​combobox/​pharos-combobox.wc.stories.ts Registers combobox story dependencies.
packages/​pharos/​src/​components/​coach-mark/​pharos-coach-mark.wc.stories.ts Registers the coach-mark component.
packages/​pharos/​src/​components/​checkbox/​pharos-checkbox.wc.stories.ts Registers checkbox story dependencies.
packages/​pharos/​src/​components/​checkbox-group/​pharos-checkbox-group.wc.stories.ts Registers checkbox-group story dependencies.
packages/​pharos/​src/​components/​button/​pharos-button.wc.stories.ts Registers button and form dependencies.
packages/​pharos/​src/​components/​breadcrumb/​pharos-breadcrumb.wc.stories.ts Registers breadcrumb components.
packages/​pharos/​src/​components/​alert/​pharos-alert.wc.stories.ts Registers dependencies and aligns component metadata.
packages/​pharos-cli/​src/​templates/​wc-story-file-template.js Generates stories with explicit registration.
.storybook/​wc/​preview.ts Replaces global registration with validation; filters docs fields.
.storybook/​wc/​main.ts Adds source icon and HTML transforms.
.github/​workflows/​chromatic.yml Configures TurboSnap statistics, selection, and externals.

Review effort: Balanced

Comment thread .github/workflows/chromatic.yml Resolved
@brentswisher
brentswisher marked this pull request as ready for review November 11, 2026 13:01
@brentswisher
brentswisher requested a review from a team as a code owner November 11, 2026 13:01
@brentswisher
brentswisher requested review from daneah, jialin-he, lizlove and satya-achanta-venkata and removed request for a team November 11, 2026 13:01
@brentswisher
brentswisher merged commit 6c5ba96 into develop Nov 11, 2026
12 checks passed
@brentswisher
brentswisher deleted the chore/turbosnap-tracing branch November 11, 2026 19:50
@daneah daneah mentioned this pull request Nov 18, 2026
5 of 11 tasks
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.

Configure TurboSnap for faster Chromatic builds

3 participants