Skip to content

fix: preserve CSS pseudo states in snapshots#323

Merged
AriPerkkio merged 1 commit intomainfrom
ari/fix-css-pseudo-state-preserve
May 4, 2026
Merged

fix: preserve CSS pseudo states in snapshots#323
AriPerkkio merged 1 commit intomainfrom
ari/fix-css-pseudo-state-preserve

Conversation

@AriPerkkio
Copy link
Copy Markdown
Member

@AriPerkkio AriPerkkio commented Apr 23, 2026

Issue: Related to #295

Requires chromaui/rrweb#7

What Changed

When a snapshot is taken, store IDs (rrweb serialized DOM IDs) of elements with CSS pseudo states right next to the snapshot in the archive file. When we rebuild the DOM in Storybook, we "hydrate" the states back to the DOM by applying CSS classes with corresponding names as the state had. rrweb-snapshot makes sure CSS is rewritten during serialization: chromaui/rrweb#7.

How to test

  1. Setup this PR locally
  2. Run css-pseudo-states test of each test runner package
  3. Build Storybooks and verify CSS is applied correctly.
rrweb-pseudo-css-fixes.mov

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 23, 2026

🦋 Changeset detected

Latest commit: 8256a68

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@chromatic-com/playwright Patch
@chromatic-com/cypress Patch
@chromatic-com/shared-e2e Patch
@chromatic-com/vitest Patch

Not sure what this means? Click here to learn what changesets are.

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

These Cypress tests are completely written by Github Copilot. I've reviewed them.

We need to use CDP for these actions so that browser doesn't see events as simulated ones. CSS requires real events. There is a third party cypress-real-events package that provides better API for this, but as we need these only for this one test file I think it's fine to inline the helpers here. It's isolated and maintainable.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, this great!

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.06%. Comparing base (ed87541) to head (8256a68).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #323      +/-   ##
==========================================
+ Coverage   91.47%   92.06%   +0.59%     
==========================================
  Files          22       22              
  Lines         598      605       +7     
  Branches      109      109              
==========================================
+ Hits          547      557      +10     
+ Misses         48       45       -3     
  Partials        3        3              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@AriPerkkio AriPerkkio force-pushed the ari/fix-css-pseudo-state-preserve branch from 4b34acb to 8256a68 Compare April 28, 2026 05:58
@AriPerkkio AriPerkkio marked this pull request as ready for review April 28, 2026 06:30
@AriPerkkio AriPerkkio self-assigned this Apr 29, 2026
// @ts-expect-error rebuild is typed incorreclty, cache and mirror are optional
const html = (await rebuild(htmlNode, { doc: document })) as HTMLElement;
const mirror = createMirror();
const html = rebuild(htmlNode!, { doc: document, mirror, cache: createCache() }) as HTMLElement;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

we're not awaiting rebuild here anymore and I just want to confirm that that is intentional.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member

@skitterm skitterm left a comment

Choose a reason for hiding this comment

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

@AriPerkkio this looks great!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, this great!

@AriPerkkio AriPerkkio merged commit e4f8c87 into main May 4, 2026
12 checks passed
@AriPerkkio AriPerkkio deleted the ari/fix-css-pseudo-state-preserve branch May 4, 2026 05:09
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.

3 participants