Loading...
Loading...
Audit and update repositories to follow Workleap's Chromatic best practices for snapshot cost control and CI optimization. Use this skill when: (1) Auditing a repository for Chromatic best practices compliance (2) Implementing Chromatic cost optimizations in a project (3) Fixing TurboSnap-disabling patterns in code (4) Setting up chromatic.config.json with the untraced option (5) Updating CI workflows for conditional Chromatic execution (6) Refactoring barrel file imports in Storybook preview files (7) Reviewing PRs for Chromatic cost impact (8) Setting up Chromatic in a new Turborepo project (9) Checking for local Chromatic usage that should be removed
npx skill4agent add workleap/wl-web-configs workleap-chromatic-best-practiceschromatic.config.json
.storybook/preview.ts
.storybook/preview.tsx
.github/workflows/*chromatic*.yml
.github/workflows/*storybook*.yml
package.json (scripts section)untracedchromatic.config.json{
"$schema": "https://www.chromatic.com/config-file.schema.json",
"untraced": ["**/package.json"]
}package.jsonuntraceduntraceduntraceduntraced.storybook/preview.ts.storybook/preview.tsx// BAD - barrel file import triggers full build when ANY export changes
import { ThemeProvider, I18nProvider } from "@app/providers";
import { something } from "../src";
import { util } from "@app/utils";// GOOD - direct imports only trigger rebuilds for specific file changes
import { ThemeProvider } from "@app/providers/ThemeProvider";
import { I18nProvider } from "@app/providers/I18nProvider";/index@app/utils../srcpackage.json{
"scripts": {
"chromatic": "chromatic",
"test:visual": "chromatic --project-token=...",
"storybook:test": "chromatic"
}
}on:
push:
branches:
- main
pull_request:
branches:
- main
types:
- opened
- labeled
workflow_dispatch:
jobs:
chromatic:
steps:
- name: Early exit if "run chromatic" label is not present
if: github.event_name == 'pull_request' && !contains(github.event.pull_request.labels.*.name, 'run chromatic')
run: |
echo "No \"run chromatic\" label present. Skipping Chromatic workflow."
exit 78# BAD - runs on every PR without label check
on:
pull_request:
jobs:
chromatic:
# No label checkrun chromatic- name: Chromatic
uses: chromaui/action@latest
with:
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
onlyChanged: true # Enables TurboSnap
exitOnceUploaded: true # Faster CI, doesn't wait for build
autoAcceptChanges: main # Auto-accept on main branchonlyChanged: trueexitOnceUploaded: trueautoAcceptChanges: main- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0 # Required for TurboSnap
ref: ${{ github.event.pull_request.head.ref }}
env:
CHROMATIC_BRANCH: ${{ github.event.pull_request.head.ref || github.ref_name }}
CHROMATIC_SHA: ${{ github.event.pull_request.head.sha || github.ref }}
CHROMATIC_SLUG: ${{ github.repository }}fetch-depth: 0fetch-depth: 0chromatic.config.json# BAD - doubles/triples snapshot count
npx chromatic --browsers chrome,firefoxrenovate/*changeset-release/*.storybook/preview.ts[x]**/resources.json**/translations/*.json# Concurrency to cancel in-progress runs
concurrency:
group: chromatic-${{ github.ref }}
cancel-in-progress: true
# Label removal after completion
- name: Remove "run chromatic" label after Chromatic completion
if: github.event_name == 'pull_request'
uses: actions/github-script@v8
with:
script: |
github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
name: 'run chromatic'
});## Chromatic Best Practices Audit
### Findings
| Practice | Status | Action Required |
|----------|--------|-----------------|
| `untraced` config (optional) | ✅/❌/N/A | [action or user declined] |
| Preview barrel imports | ✅/❌ | [action] |
| No local Chromatic scripts | ✅/❌ | [action] |
| CI label-based triggering | ✅/❌ | [action] |
| CI `onlyChanged: true` flag | ✅/❌ | [action] |
| CI `fetch-depth: 0` | ✅/❌ | [action] |
| CI Chromatic env vars | ✅/❌ | [action] |
| Chrome-only snapshots | ✅/❌ | [action] |
| CI concurrency settings | ✅/❌ | [action] |
| CI label auto-removal | ✅/❌ | [action] |
| Large file dependencies | ✅/❌ | [action] |
### Changes Made
- [list of files modified]
### Recommendations
- [list of suggested improvements that require user decision]
- Consider adding `untraced` for package.json (trade-off: may miss UI library regressions)
- Configure branch ruleset to exclude Renovate/Changesets branches
- Add `run chromatic` as a required status check| Change Type | Files |
|---|---|
| Storybook preview | |
| Barrel file dependencies | Any |
| Package dependencies | |
| Large shared files | Routes, constants, localization |
| Shallow git clone | Missing |
| Configuration | Snapshots per Story |
|---|---|
| Chrome only | 1x |
| Chrome + Safari | 2x |
| Chrome + Safari + Firefox | 3x |
run chromaticchromatic.config.json- name: Restore Turborepo cache
uses: actions/cache/restore@v5
with:
key: ${{ runner.os }}-turbo-chromatic-${{ github.sha }}
restore-keys: |
${{ runner.os }}-turbo-chromatic-
${{ runner.os }}-turbo-
path: .turbo