Skip to content

--computed: rule coverage for style rules only one side has - #140

Merged
tmashara merged 2 commits into
mainfrom
claude/issue-121-rules
Nov 3, 2026
Merged

tmashara merged 2 commits into
mainfrom
claude/issue-121-rules

Conversation

@tmashara

@tmashara tmashara commented Nov 3, 2026 •

Copy link
Copy Markdown
Owner

Closes #121.

Where each #121 item stands

User-facing changes

With --computed, a new block appears after computed::

rules: 3 changed groups, 1 never matched, 2 matched on some shots
  +inline#… (1 rule)  matched nothing: /rules@960,959
  +inline#… @media (width >= 960px) (1 rule)  matched /rules@960; nothing /rules@959
  -inline#… @media (min-width: 960px) (1 rule)  matched /rules@960; nothing /rules@959

How rules are compared

  • Each side's style rules come from document.styleSheets. renderdiff's own CSS is adopted, so it is never read.
  • A rule is compared as Chrome serializes it: its enclosing at-rules, its selector with nesting resolved, and its declarations. The left origin and asset hashes in url() are normalized.
  • So rgb() notation changes are no change, but min-width: → width >= is.

How matches are counted

  • Rules only one side has are grouped by stylesheet and by enclosing at-rules. A <style> is named inline# plus a hash of its text, so a block inlined into every page is one group, and a page's own block stays separate.
  • On each shot, a group records how many elements on its side it could style there: its @media/@supports must hold and a selector must match.

What the block lists

  • Groups that matched nothing anywhere come first, then groups that matched on some shots only, with widths. This is the 959/960 proof.
  • Groups that matched on every shot are only counted (, all matched). The block shows at most 20 lines.
  • rules: no style rule differs between the sides when, once parsed, both sides' rules are the same.

Known limits

  • Matching leans toward "matched": :hover/:focus/:active/:visited and pseudo-elements match any element (so ::selection {} counts as matched), and @container counts as holding.
  • Other states lean the other way: :checked, :target, [open], classes added by script, and <link media=print> count as unmatched unless the shot is in that state.
  • A group matches if any one of its rules does, so a never-matched rule among matched ones isn't singled out.
  • Cross-origin sheets can't be read. They are listed once in meta.unreadableSheets and left out of the comparison.

Fields

  • results.json: computed.rules per result ({ side, sheet, conditions, rules, elements }), summary.rules ({ side, sheet, conditions, rules, matched, unmatched }), and meta.unreadableSheets. merge recomputes summary.rules and unions meta.unreadableSheets.
  • Coverage runs after the snapshot, with its own 5 s timeout. If it fails or times out, only the shot's computed.rules is left out.
  • Plain runs (no --computed) do no extra page work.

Tests

A new rules guard-rail fixture renders the same on both sides. Its left side rewrites @media (min-width: 960px) to (width >= 960px), adds a .bubble rule that matches nothing, adds state-only ::selection and :focus-visible rules (which must count as matched), and changes only notation in rgb() and the hash in a url(). The test runs at 960 and 959 and asserts:

  • summary.rules;
  • the elements counted per group at 960;
  • the console block.

The rgb() and url() changes must produce no group.

A base-vs-base run of metabase.com / and /docs/latest/ gives rules: no style rule differs between the sides, with 6 cross-origin sheets listed per side.

🤖 Generated with Claude Code

tmashara and others added 2 commits November 3, 2026 21:05
A clean run couldn't show that a changed rule ever applied. With --computed, each
side's style rules (document.styleSheets, so renderdiff's adopted CSS is left out)
are compared as Chrome serializes them, origin and url() hashes normalized. Rules
only one side has are grouped by stylesheet and enclosing at-rules, and each shot
records how many elements they could style there. The summary lists groups that
matched nothing anywhere, then ones that matched on some shots only (a breakpoint's
two sides); all-matched groups are only counted. Cross-origin sheets are listed once
in meta.unreadableSheets.

Closes #121

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

Stripped states and pseudo-elements now read as :where(*), so ::selection or
:focus-visible alone is matched instead of nothing. A <style> is named inline#
plus a hash of its text, so a block inlined into every page is one group. The page
is walked once; node keys, diffs and groups the rows, and a second evaluate only
counts matches. Coverage runs after the snapshot's race, with its own timeout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tmashara
tmashara merged commit 6b9da56 into main Nov 3, 2026
3 checks passed
@tmashara
tmashara deleted the claude/issue-121-rules branch November 3, 2026 20:30
@tmashara tmashara mentioned this pull request Nov 4, 2026
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.

Feedback from a CSS-only docs run (0.12.0): rule coverage, PR crops of clean shots, hidden subtrees in dom, results.json fields

1 participant