Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ renderdiff <left-origin> <right-origin> <route…> [options]
| `--accept <reason>` | Record this run's differences as accepted, with a reason. See **Accepted differences and reruns**. |
| `--rerun-failed` | Rerun only what the last run in `--out` didn't find clean or accepted, keeping the rest. |
| `--cache-right` | Replay the right side's network traffic from the last `--cache-right` run in `--out`, when it's under an hour old and covers every shot; otherwise load it live and record it. Keeps `<out>/.cache/` when the out dir is wiped. See **Accepted differences and reruns**. |
| `--computed` | Also diff the computed style of every rendered element and its `::before`/`::after`, and say per route whether the markup is identical apart from asset hashes. Pixels still decide the score and exit code. See [docs/output.md](docs/output.md#computed-styles---computed). |
| `--dry-run` | Print the URL pairs and exit. No browser. |
| `--open` | Open the report when the run finishes. |
| `--progress` | A line per shot as it finishes, then the worst scores. The default on a terminal; piped, renderdiff prints one compact summary at the end. |
Expand Down Expand Up @@ -194,6 +195,7 @@ only.
| `dom +sel` / `-sel` | Element only on the left / only on the right. |
| `dom sel x+8` | It moved without its own style changing; the neighbour or parent listed after it is the cause. |
| `dom sel` | On both sides and unchanged in style or position, so its own pixels changed (an image or canvas). |
| `computed: N findings` | With `--computed`: each `key prop left→right` once, with the routes and widths it was seen at; `dom identical`: the markup matches apart from asset hashes and generated class names, so look at CSS or script. |
| `crops …` | Up to 3 PNGs per comparison, bands first, relative to `results.json`. Left is on top or on the left, and the change is boxed in red. |
| `ERROR …` | Unmeasured, which is neither a pass nor a fail. Exits 3. |
| `accepted:` / `stale accepted:` | Shots whose every difference was accepted, and accepted entries the run no longer saw. See below. |
Expand Down Expand Up @@ -276,6 +278,7 @@ Everything lands in the out dir (`./renderdiff-out` by default):
}],
"text": { "added": [], "removed": ["Pricing"] }, // added: left only; removed: right only
"failed": { "left": [], "right": [] }, // stylesheets and font faces that didn't load: "font Inter 700", "stylesheet https://…"
"computed": { "dom": 1, "changes": [], "truncated": 0, "unmatched": { "left": [], "right": ["body > nav > a[href=\"/pricing\"]"] } }, // --computed only; null: snapshot failed, "computedError" says why
"images": { "left": "about.1440.left.png", "right": "about.1440.right.png", "diff": "about.1440.diff.png" },
"crops": [{
"path": "about.1440.c1.png", "kind": "band", // or "region"
Expand All @@ -292,7 +295,8 @@ Everything lands in the out dir (`./renderdiff-out` by default):
"belowThreshold": 0, // accepted shots aside
"differing": 1, // shots with any differing pixel, accepted ones aside
"accepted": 0, // shots whose every difference was accepted
"stale": [] // accepted entries the run measured but didn't see
"stale": [], // accepted entries the run measured but didn't see
"computed": [] // --computed: { key, prop, values: [left, right], at: [{ url, widths }] }
}
}
```
Expand Down
58 changes: 58 additions & 0 deletions docs/output.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,64 @@ band names only what one side added, not what it pushed down, so it can name not
fixed chrome covers isn't named. Probing gives up after 5s, leaving the elements out. Shadow
DOM and iframes aren't searched.

## Computed styles (`--computed`)

With `--computed`, after the shot renderdiff reads the computed style of every rendered
element on both sides: the properties `dom` compares, plus `content`, and `::before` and
`::after` wherever they generate content. Masked subtrees and `script`/`style`-like tags
are skipped; a `display: none` element is read, its subtree isn't. Script-driven
animations are finished first. The summary gets one block, after the rows:

```
computed: 2 findings; dom identical on 2 of 3 route(s), differs /pricing (1), so findings there are hints
body > div.page > nav.chips > a[href="#blog"] margin-left 24px→16px /about@1440,375 /@1440,375
body > footer > a.cta::after content "→"→none /about@1440
unmatched /pricing@1440 -body > main > section.plans:nth-of-type(3)
```

- Each finding is `key property left→right`, left first like `dom`, followed by every
route and width it was seen at. The same change on 300 pages is one line, most widespread
first, accepted shots included. The summary shows 20; `summary.computed` in results.json
has them all. Each result's `computed.changes` keeps its first 500, and `truncated`
counts the rest (the summary says where).
- The key is a selector path from `body`, or from `:scope` with `--selector`, where only
the selected element's subtree is walked. Each step is the id, or the tag with a naming
attribute and up to two classes that don't look generated (sorted). `:nth-of-type` is
added only where siblings would otherwise share the step, a duplicated id included. The
key works with `querySelector`.
- Elements are matched by key, not by position, so a cookie banner injected on one side
doesn't misalign everything after it.
- An inserted sibling of the same tag and classes still shifts the `:nth-of-type` of the
ones after it.
- A class renamed on an ancestor unmatches its whole subtree.
- One change high in the tree is one finding. An inherited property (`font-*`,
`line-height`, `letter-spacing`, `text-*`, `white-space`, `color`, `visibility`) is
dropped where the parent has the same change, so a `body` font change is one line, not
one per element. A `width` is dropped inside a parent whose width changed, and a
`height` around a child whose height changed, so the box that caused it is what's left.
- An element shown on one side and `display: none` on the other is one `display` finding;
its subtree counts neither as unmatched nor against `dom identical`.
- A `::before`/`::after` that only one side generates shows as `content` against `none`.
That is how a removed rule that drew an icon shows up.
- `dom identical` means that on every width, each walked element's tag, attributes and own
text are the same on both sides.
- Bundler hashes in `src`/`href`/`srcset` are ignored (`hero.3f9a8c1d.png`, `?v=…`), and
so are generated class names (`css-1q2w3e`, `Button_root__a1b2c`).
- A pixel difference on such a route comes from CSS or script, not from walked markup.
SVG internals, shadow DOM, iframes and `display: none` subtrees aren't walked.
- Hash-shaped tokens only: 8 or more letters and digits that alternate, between
separators in a file name. `team_photo_2024.jpg` and `/p/abcdef123456` count as changes.
- `dom differs (N)` counts the elements that differ or that one side lacks. Treat that
route's findings as hints.
- `unmatched` lists the outermost elements only one side has: `+` left, `-` right. The
summary shows five routes, five each.
- The HTML report shows the same block and puts `dom identical` / `dom differs (N)` on each
card. A snapshot that fails, takes over 15s or meets more than 50,000 elements is
reported as failed, with why (`computed: null`, `computedError`), and the pixel result
stands. Pixels still decide the score and the exit code.

`:hover`/`:focus` states aren't snapshotted.

## Text

A line diff of each side's visible text (`document.body.innerText`, or the element's with a
Expand Down
4 changes: 4 additions & 0 deletions renderdiff.config.example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ export default {
// a selector list cannot express.
extraCss: `.hero video { visibility: hidden !important }`,

// Also diff every element's computed style, and say whether the markup is identical
// apart from asset hashes. Same as --computed. Pixels still decide the score.
computed: false,

// Content that renders on both sides but whose value drifts. Painted over on both,
// so the noise cancels out instead of scoring against you.
//
Expand Down
3 changes: 3 additions & 0 deletions skills/renderdiff/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ legitimate: [reference.md](reference.md).
6. `dom` before crops. `sel prop l→r`: computed value, left first; find the *rule*.
`+sel`/`-sel`: only left/right. `sel x+8`: moved; the cause is listed after it.
Bare `sel`: its own pixels changed (image, canvas).
CSS refactor or dead-CSS removal: add `--computed`. Each `computed:` finding is
`key prop left→right`, collapsed across routes and widths. `dom identical` means the
cause is CSS or JS, not markup.
7. `Read` the crops under each row (next to results.json) for what `dom` doesn't explain.
Left is on top or left; red box = change, red seam = missing rows.
8. Fix or justify every band, region and text line. After each migration step,
Expand Down
6 changes: 4 additions & 2 deletions skills/renderdiff/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@ px), band, their `elements` (`selector`, `side`, each side's box, `changed`, `te
`rightSelector` when the right was found under another selector; absent when not looked
at, `[]` when nothing was named), full text diff, image path and crop (`kind`, each side's box with `h` 0 at an
insertion point, `layout` `stacked` = left on top or `side` = left on the left, `scale`,
`clipped`), `selector` (`{ left, right }` or null), one result per line, so `grep '"url":"/about"'` pulls a route.
`clipped`), `selector` (`{ left, right }` or null), with `--computed` a `computed` per result
(`dom`, the count of elements whose markup differs, with 0 meaning identical; `changes`
`{ key, prop, values }`, the first 500, `truncated` counting the rest; `unmatched` keys per side; null if the snapshot failed, with `computedError`), one result per line, so `grep '"url":"/about"'` pulls a route.
Paths are relative to the out dir. `summary` has `compared`, `errors`, `mean`, `worst`,
`belowThreshold` and `differing` (unaccepted shots with any differing pixel: without
`--threshold`, any exits 1); `meta` records origins, widths, threshold, the pinned clock, block
`--threshold`, any exits 1), plus `computed` with `--computed`: every change once, with the routes and widths it was seen at. `meta` records origins, widths, threshold, the pinned clock, block
patterns, hidden selectors, mask reasons, the browser (`chromium`, or `chrome` when it fell
back to the system Chrome), each side's storage state file name, and `rightReplayedFrom`
(with `--cache-right`, when the replayed recording was made; also on each replayed result). `hook: true` marks a
Expand Down
3 changes: 3 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ function parseArgs(argv: string[]): Args {
else if (v === "--no-progress") a.progress = false;
else if (v === "--rerun-failed") a.rerunFailed = true;
else if (v === "--cache-right") a.cacheRight = true;
else if (v === "--computed") a.computed = true;
else if (v === "--mask-media") a.maskMedia = true;
else if (v === "--accept") {
a.accept = next().trim();
Expand Down Expand Up @@ -213,6 +214,8 @@ const HELP = `
--cache-right Replay the right side's network from the last --cache-right run
in --out, if under an hour old and covering every shot; else load
it live and record it. The page still renders and is shot fresh.
--computed Also diff every element's computed style and ::before/::after,
and say whether the markup is identical. Pixels still decide.
--dry-run Print the URL pairs and exit. No browser.
--open Open the report when the run finishes.
--progress A line per shot as it finishes. The default on a terminal;
Expand Down
Loading
Loading