feat(rrweb-snapshot): support more user-action pseudo-classes for rebuild#1897
feat(rrweb-snapshot): support more user-action pseudo-classes for rebuild#1897hi-ogawa wants to merge 4 commits into
Conversation
…ebuilding `pseudoClassPlugin` only mirrored `:hover` to an escaped class. Add a `hackCssPseudoClasses` rebuild option (default `[':hover']`, unchanged) so consumers that rebuild snapshots without the event replayer can also mirror `:active`, `:focus`, `:focus-visible` and `:focus-within` for replay. The selected set is threaded through `rebuild` -> `adaptCssForReplay` and folded into its cache key. Each pseudo-class regex ends with a `(?![-\w])` boundary so `:focus` is not rewritten inside `:focus-visible` / `:focus-within`. Co-authored-by: OpenCode (claude-opus-4-8) <noreply@opencode.ai>
Co-authored-by: OpenCode (claude-opus-4-8) <noreply@opencode.ai>
🦋 Changeset detectedLatest commit: f7431c4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 22 packages
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 |
| /** | ||
| * User-action pseudo-classes to mirror as escaped classes when `hackCss` is | ||
| * enabled, e.g. `foo:focus` becomes `foo:focus, foo.\:focus`. | ||
| * Defaults to `[':hover']`. | ||
| */ | ||
| hackCssPseudoClasses?: HackCssPseudoClass[]; |
There was a problem hiding this comment.
Alternative API may be to extend hackCss option like:
hackCss: boolean | { pseudoClasses: HackCssPseudoClass[] }Please let me know if you have any API preference 🙏
Backs the `(?![-\w])` boundary: `:focus` must not be rewritten inside `:focus-visible` / `:focus-within`. Co-authored-by: OpenCode (claude-opus-4-8) <noreply@opencode.ai>
Co-authored-by: OpenCode (claude-opus-4-8) <noreply@opencode.ai>
There was a problem hiding this comment.
Pull request overview
Adds an opt-in mechanism in rrweb-snapshot’s rebuild pipeline to mirror additional “user-action” CSS pseudo-classes (beyond :hover) as escaped class selectors, enabling snapshot consumers (e.g. static viewers) to paint interaction states by toggling classes on rebuilt nodes.
Changes:
- Add
hackCssPseudoClassestorebuild/rebuildIntoSandboxedIframeto control which pseudo-classes are mirrored (default remains[':hover']). - Generalize the CSS rewriting plugin to mirror
:active,:focus,:focus-visible, and:focus-within, with tests covering correct boundary handling. - Extend integration coverage to validate that rebuilt snapshots paint the mirrored pseudo-class styles when the corresponding escaped classes are added.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| packages/rrweb-snapshot/src/css.ts | Generalizes the PostCSS selector rewrite to mirror a configurable set of supported pseudo-classes. |
| packages/rrweb-snapshot/src/rebuild.ts | Threads hackCssPseudoClasses through rebuild + updates CSS rewrite caching to include the selected pseudo-class set. |
| packages/rrweb-snapshot/test/css.test.ts | Updates and extends unit tests to cover new pseudo-class mirroring and boundary correctness. |
| packages/rrweb-snapshot/test/integration.test.ts | Adds integration tests proving rebuilt snapshots can paint mirrored pseudo-class styles and that default remains hover-only. |
| .changeset/hack-css-pseudo-classes.md | Documents the new option as a patch-level change for rrweb-snapshot. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This PR adds
hackCssPseudoClassesoption torebuildso snapshots can mirror:active,:focus,:focus-visibleand:focus-within(not just:hover) as escaped classes for replay. Defaults to[':hover'], so existing behavior is unchanged.This is a suggested change for #1896. Happy to iterate or close depending on the maintainers' decision. I wanted to open a PR first so there's a concrete scope of changes to discuss. Thanks for the review!