Making Storybook and Chromatic useful instead of noisy
The problem: alert fatigue kills visual testing
Almost every frontend team goes through the same arc with Storybook and Chromatic. Someone sets it up with great intentions, hooks it into CI, and opens the first pull request.
Chromatic comes back with 38 visual diffs. Thirty-seven of them are false alarms: a timestamp ticked forward by one minute, a skeleton shimmer was captured mid-pulse, or a web font loaded half a second late on one runner.
After two weeks of clicking “Accept all” just to unblock merges, nobody actually looks at the screenshots anymore. The first time a real layout bug slips in, it gets rubber-stamped along with the noise.
Visual regression testing only works when every single flagged diff means something actually changed.
Where false-positive diffs actually come from
Chromatic is just comparing pixels between your base branch and your PR branch. If a story produces different pixels on two identical runs, CI will flag it every single time. Almost all flaky diffs come from four culprits:
- Live clocks and relative dates: calling
new Date()orDate.now()inside a component or story means “2 minutes ago” or today’s date changes every build. - Random mock data: generating random avatars, random prices, or
Math.random()IDs guarantees a different screenshot on every run. - Unfrozen animations: blinking cursors, spinning loaders, and pulsing skeletons get captured at arbitrary keyframes.
- Flaky external images: hotlinking third-party image URLs causes timeouts or slow loads that leave half-rendered frames.
How to make stories boring and deterministic
Fixing flaky snapshots takes a few simple rules in your Storybook setup:
1. Freeze all mock data
Pass explicit, hardcoded props into every story. Never compute dates or pick random array items at render time.
// Flaky: changes every day
export const Default: Story = {
args: {
updatedAt: new Date().toISOString(),
avatarUrl: "https://picsum.photos/80",
},
};
// Deterministic: identical pixels on every CI run
export const Default: Story = {
args: {
updatedAt: "2025-03-12T09:00:00Z",
avatarUrl: "/fixtures/avatar-demo.png",
},
};
2. Disable infinite motion in snapshot mode
Keep transitions smooth for humans browsing Storybook, but pause continuous animations when Chromatic is taking screenshots (or honor prefers-reduced-motion inside your global preview CSS). One small rule eliminates 90 percent of loader and caret flakes.
3. Wait for web fonts before capturing
If your design system uses custom fonts, wait for document.fonts.ready in your Storybook preview loader. Otherwise one build screenshots the system fallback font while the next screenshots your real font, flagging every text node on the page.
Write stories for the awkward states, not just the happy path
Every card component looks clean with a short title, a crisp square image, and a two-digit price. Real production bugs almost never happen there. They happen when real data hits the UI:
- A 90-character title that pushes an action button off screen
- Zero items (empty state) or 999+ items (huge counters)
- Missing optional fields or broken thumbnails
- Narrow 360px mobile viewports where flex rows refuse to wrap
Adding just one WorstCase story alongside your Default story turns Chromatic into a quiet safety net. Every time someone tweaks padding or updates a shared token, you immediately see whether any edge case broke, without opening ten different screens by hand.