Skip to content

Add --computed: computed-style diff and a dom identical signal - #30

Merged
tmashara merged 5 commits into
mainfrom
claude/computed-mode-9e9d4a
Oct 29, 2026
Merged

tmashara merged 5 commits into
mainfrom
claude/computed-mode-9e9d4a

Conversation

@tmashara

@tmashara tmashara commented Oct 29, 2026 •

Copy link
Copy Markdown
Owner

Adds --computed (config computed: true). After each shot it reads the computed style of every rendered element on both sides, then diffs them. It also reports whether the markup is identical. Pixels still decide the score and the exit code.

What it does

  • Full-page walk inside locate.ts's probe, so it reuses PROPS, part() (hashed-class filter, nth-of-type) and the mask set.
    • Captures PROPS plus content, and ::before/::after wherever they generate content.
    • Skips masked and display: none subtrees. Finishes script-started animations first; STILL_CSS already stops CSS ones.
    • Stops at 15s or 50k elements and reports computed: null with computedError saying which.
    • With --selector, walks only the selected subtree, keyed from :scope.
  • Stable keys. Elements are matched by a selector path (tag + id or sorted stable classes + nth-of-type only when ambiguous), never by DOM index. An injected banner doesn't misalign the rest.
  • Inherited cascades collapse. An inherited property's change is dropped when the parent has the same change, and width/height when the parent resized too. One body font change is one finding.
  • Grouped output. Findings are grouped by (key, property, left→right) across routes and widths, most widespread first. summary.computed in results.json holds all of them.
  • One-sided pseudo-elements. A ::before/::after that only one side generates is a content … → none finding, which is what a removed icon rule looks like.
  • DOM identical. Per element: tag, attributes and own text, ignoring bundler hashes in src/href/srcset and generated class names. Each route shows dom identical or dom differs (N). When it differs, the summary calls the findings hints and lists unmatched elements separately.
computed: 4 findings; dom identical on 2 of 3 route(s), differs /inserted (1), so findings there are hints
  body > div.page > nav.chips > a[href="#blog"] margin-left 24px→16px  /margin@1440,375
  …
  unmatched /inserted@1440 +body > div.page > div.blocks > section:nth-of-type(3)

Values are left first (left→right), the same as dom. With left as the change, a removed rule reads as value-without-rule→value-with-rule.

Tests and docs

  • tests/unit/computed.test.ts covers collapse, pseudo, unmatched, hash normalization, grouping and format.
  • One e2e test in tests/visual/controls.test.ts runs the /margin, /color and /inserted fixtures.
  • Docs: docs/output.md (new section), README, skills/renderdiff/SKILL.md and reference.md, and the example config.

Review fixes

  • Keys: walk keys are computed linearly per parent, and :nth-of-type is added whenever siblings share a step, duplicate ids included. Keys can't collide, so nothing is dropped. Class sorting applies only to the walk, so pixel-mode selectors and accepted fingerprints are unchanged.
  • Hidden elements: a display: none element is snapshotted (its subtree isn't). A removed hiding rule becomes one display finding and doesn't count against dom identical.
  • Sizes: a width change collapses into its parent's; a height change collapses into the child that caused it.
  • Reporting:
    • Truncation past 500 changes is counted (truncated) and shown.
    • Accepted shots feed the findings.
    • normalizeAssets matches only hash-shaped tokens.
  • Tests: tests/visual/computed.test.ts drives the walk on handmade pages: duplicate ids, sibling keys, injected nodes, a display toggle, a selector root, 10k siblings and pixel-mode selector order.

Follow-ups (out of scope)

  • CSS.forcePseudoState to snapshot :hover/:focus/:active.
  • --all-props to diff every property (non-default values only).
  • Keys that survive an inserted same-tag sibling or an ancestor class rename; both are documented as limits today.
  • Walk SVG descendants (icon <path> swaps currently read as dom identical).
  • Settle script-driven inline style after the shot before snapshotting.
  • parentOf splits keys on " > ", which can appear inside a quoted attribute value in a key.

🤖 Generated with Claude Code

tmashara and others added 5 commits October 29, 2026 10:15
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…m per element

Tightens asset-hash normalization, bounds the in-page walk and the
unmatched lines, and documents what the walk skips.

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

Keys are disambiguated linearly per parent (duplicate ids included) and
sorted classes stay out of pixel-mode selectors. display:none elements
are snapshotted so a removed hiding rule is a display change. Height
collapses toward the child that caused it. Truncation, accepted shots
and snapshot failure reasons are reported; --selector walks only its
subtree; asset-hash normalization matches hash-shaped tokens only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…et is the check

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…9e9d4a

# Conflicts:
#	skills/renderdiff/reference.md
#	src/cli.ts
#	src/config.ts
#	tests/unit/cli-args.test.ts
@tmashara
tmashara merged commit 34dd3cd into main Oct 29, 2026
3 checks passed
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.

1 participant