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
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,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**. |
| `--no-recheck` | Don't reload a differing shot's right side to find content that varies per load. Off anyway under `--cache-right`. |
| `--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 and origin. 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. |
Expand All @@ -129,7 +130,7 @@ range rather than on a boundary, so a layout switch never flaps between runs.
| Exit | Meaning |
| --- | --- |
| `0` | No route errored and no shot differs (with `--threshold`: none scored below it). Accepted differences don't count; nor do unstable pixels or a failed asset alone, which still get their own row. |
| `1` | A shot differs, or with `--threshold` scored below it. Wins over `3` when both happen. A difference that can't be accepted (unstable pixels beside it, a width change, a height change whose rows don't align) exits 1 even on the `--accept` run. |
| `1` | A shot differs, or with `--threshold` scored below it. Wins over `3` when both happen. A difference that can't be accepted (unstable pixels beside it, content that varies per load, a width change, a height change whose rows don't align) exits 1 even on the `--accept` run. |
| `2` | Bad arguments or config, an origin that isn't responding, an unreadable storage state or `renderdiff.accepted.json`, an out dir holding files renderdiff didn't write, or a `--rerun-failed` that doesn't repeat the last run. |
| `3` | A route errored, so it went unmeasured, or the run crashed (e.g. no Chromium). |

Expand Down Expand Up @@ -240,7 +241,7 @@ banner, your verdict, crops embedded) to attach to a ticket or publish as proof:
- **Pins what varies between loads**: clock, `Math.random`, timezone, locale, colour scheme, reduced motion, animated image frames, video frames and video.js overlays.
- **Kills animation, transitions and caret blink**, and hides common consent banners and dev toolbars.
- **Settles the page**: lazy images, fonts and network idle before the shot.
- **Shoots until stable**, and excludes pixels still moving as `unstable`.
- **Shoots until stable**, and excludes pixels still moving as `unstable`; rechecks differing shots for content that varies per load.
- **Isolates state** per origin, **retries once** per shot, and **stitches tall pages** past 16,384px.

Each run's report ends with a "What was neutralized" section listing what was in effect.
Expand Down
4 changes: 4 additions & 0 deletions docs/how-it-works.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ honestly. This is what renderdiff does to make sure of that.
noise from that origin: they're painted magenta on both sides, reported per comparison
as `unstable`, and excluded from the measurement — the score is over the remaining
pixels. A route more than 25% unstable errors as `page did not settle`.
- **Rechecks a differing shot** — reloads the right side once in a fresh context. The
elements that differ between the two loads are `varies`: painted out on both sides like a
mask, excluded from the score, and listed with the mask that would cover them. Off with
`--no-recheck`, and under `--cache-right`, whose replay serves the same bytes each load.
- **Counts a pixel as changed** when pixelmatch's YIQ colour distance is over threshold
0.05 (a delta of about 88), with anti-aliased pixels left out. Its default of 0.1 passed
Tailwind v3 → v4 `pink-500` as identical; a recolour still smaller than that passes. The
Expand Down
9 changes: 7 additions & 2 deletions docs/output.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ as the largest. Under a row, `failed` lists stylesheets and font faces a side fa
(`@w` when the row covers several widths: the first one's), and `crops` lists that row's crop
files. Errors print in full, grouped across the widths that share a message. Clean means not
one pixel differs, none went unmeasured as unstable and no stylesheet or font failed; a route
with unstable pixels or a failed asset gets its own row. `--progress` gets the per-shot output
when piped, `--no-progress` the summary on a terminal.
with unstable pixels or a failed asset gets its own row. A shot whose only difference varied
between two loads of the right side is clean, but listed under `varies`. `--progress` gets
the per-shot output when piped, `--no-progress` the summary on a terminal.

## Tokens

Expand All @@ -46,6 +47,9 @@ when piped, `--no-progress` the summary on a terminal.
| `line -1px@y812` | A 1–2px line across the page only the right draws (`+`: only the left; no sign: both, differently). A lost border or divider; not counted in `reg`. |
| `3 reg` | Regions: connected patches of differing pixels. A missing link barely moves the score, but it is still a region. |
| `unstable 1,204px` | Pixels that kept changing between shots of the same load (a ticker, a carousel). Excluded from the score, so the route is never clean. |
| `varies /a @1440 148,480px div.drift` | After the routes: the right side differed between two fresh loads there (a counter, a rotating banner). Those elements are painted out on both sides like a mask and left out of the score; the shot can't be accepted. `(not located)`: no element was named, its region was painted. |
| ` --mask 'div.drift'` | The flag that masks every `varies` element, for the next run. |
| ` masks: [{ selector: … }]` | The same as config `masks` entries, with `reason: "varies per load"`. |
| `failed left: font Inter 700` | A stylesheet or font face that side failed to load (blocked URLs aside). Fix that first: a fallback font changes every line of text. |
| `text -"Pricing"` | A line of visible text only the reference has (`+`: only your change). Up to three, then `(+N more)`. |
| `dom sel prop a→b` | Element on both sides whose computed `prop` differs, left value first. |
Expand Down Expand Up @@ -305,6 +309,7 @@ pulls a route), scores rounded down to four decimals (so a shot that differs nev
"score": 0.9714, // share of measured pixels that match
"alignedScore": 1, // score over the aligned rows; null unless there are bands
"diffPixels": 33120, "totalPixels": 1158000, "unstablePixels": 0,
"varies": [], "variesPixels": 0, // absent unless a second right load differed: its regions, with elements, and the px painted out
"heightDelta": -24, "widthDelta": 0, // left − right
"regions": [], // left-page px; with bands, from the realigned rows
"bands": [{ "side": "right", "y": 196, "h": 24, // null: too different to align
Expand Down
10 changes: 5 additions & 5 deletions skills/renderdiff/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ Pixels decide the score and the exit code in every mode.
§ Reference and routes; moved page, component, sign-in, click state: § Scoping.
2. **Baseline**: base vs base. Before changing code, the untouched change side against the
reference; if the change is already made, the base build served on two ports. Whatever
differs varies per load: mask it (`--mask-media` for iframes, `--mask <sel>` or a config
mask with a `reason`; video is already frozen; a looping carousel: stop it with a
`before` hook on both sides, or mask it), and rerun until clean. Against production instead:
open each difference, then `--accept "differs before the change"`. § Masks, accepts and
thresholds.
differs varies per load: mask it (a `varies` line prints the mask; `--mask-media` for
iframes, `--mask <sel>` or a config mask with a `reason`; video is already frozen; a
looping carousel: stop it with a `before` hook on both sides, or mask it), and rerun
until clean. Against production instead: open each difference, then
`--accept "differs before the change"`. § Masks, accepts and thresholds.
3. **Change, run all routes at default widths, read each row in this order**: `ERROR` →
`failed` (a missing stylesheet or font explains the whole row: fix, rerun) → `text` →
`h`/`w`, `band`, `aligned`, `line` → `dom` (`sel prop l→r` is a computed value: find the
Expand Down
8 changes: 5 additions & 3 deletions skills/renderdiff/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ on stderr: `✗ 2 routes differ (10 shots).` (`below 97.00%` with `--threshold`)
| ` dom …` | Up to three elements behind the changes, two properties each. `dom @1440 …`: from the first width of the row. |
| ` crops …` | At most three crop PNGs per shot (bands first, tallest first, then largest regions), relative to `results.json`. |
| ` @w ERROR …` | Unmeasured. Grouped across widths sharing a message. See Errors. |
| `varies /a @1440 Npx sel` | A differing shot's right side, reloaded in a fresh context, differed from its first load there. Painted out on both sides like a mask, left out of the score (clean if nothing else differs), never accepted. Then ` --mask '…'` and ` masks: [{ …, reason: "varies per load" }]`: confirm it with a base-vs-base baseline before you use either. Off with `--no-recheck` and under `--cache-right`. |
| `renderdiff: D of R routes differ (S of T shots), E errors, worst …` | `S` counts unaccepted shots with any differing pixel; `worst` leaves accepted shots out. With `--threshold`: `, K below 97.00%`. |

**Row tokens**, in order
Expand Down Expand Up @@ -174,8 +175,8 @@ computed: 2 findings; dom identical on 2 of 3 route(s), differs /pricing (1), so
- Accepted entries go to `renderdiff.accepted.json` next to the config (or cwd), one per band
or region, scoped by the run's routes and widths. A match ignores `y` and needs the same
kind, side, box, pixel hash (4 bits a channel) and named elements, so anything else drawn
there still surfaces. Never accepted: a shot with unstable pixels, a width delta, or a height
delta without bands; `--accept` exits 1 on those. A new change can make an accepted one
there still surfaces. Never accepted: a shot with unstable pixels, `varies`, a width delta,
or a height delta without bands; `--accept` exits 1 on those. A new change can make an accepted one
re-read as different (repeated rows aligning differently): look, then accept again.
- **Accept where you check.** The pixel hash isn't portable: entries accepted on macOS mostly
come back stale on a Linux CI runner. For CI, accept in CI.
Expand Down Expand Up @@ -293,7 +294,8 @@ For scripts and drilling into one route; the loop doesn't need it. One result pe

- **Each result:** `url`, `left`, `right`, `selector` (`{ left, right }` or null), `hook`,
`width`, `status` (`compared` or `error` with `error`); `score`, `alignedScore`,
`diffPixels`, `totalPixels`, `unstablePixels`, `heightDelta`, `widthDelta`; `regions`
`diffPixels`, `totalPixels`, `unstablePixels`, `varies` and `variesPixels` (absent unless a
recheck found some; regions with `elements`), `heightDelta`, `widthDelta`; `regions`
(`x,y,w,h,pixels`, left-page px, `line` `{ y, h, side }`, `accepted` reason); `bands` (`side`,
`y`, `h`, or null when unaligned); each with `elements` (`selector`, `side`, each side's box,
`changed` `{ prop: [left, right] }`, `text`, `rightSelector`, `reparented`; absent when not
Expand Down
12 changes: 7 additions & 5 deletions src/accept.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,13 @@ const acceptable = (r: ComparedResult) => !unacceptable(r);
export const unacceptable = (r: ComparedResult) =>
r.unstablePixels
? "unstable"
: r.widthDelta
? "width change"
: r.bands === null && r.heightDelta
? "unaligned height"
: null;
: r.variesPixels
? "varies per load"
: r.widthDelta
? "width change"
: r.bands === null && r.heightDelta
? "unaligned height"
: null;

export function readAccepted(file: string): Accepted[] {
if (!fs.existsSync(file)) return [];
Expand Down
6 changes: 6 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ interface Args extends CliOverrides {
accept?: string;
rerunFailed: boolean;
cacheRight: boolean;
recheck: boolean;
}

/** `Number(raw)`, but reject anything that isn't a finite number with a flag-named error. */
Expand All @@ -59,6 +60,7 @@ function parseArgs(argv: string[]): Args {
open: false,
rerunFailed: false,
cacheRight: false,
recheck: true,
help: false,
version: false,
routes: [],
Expand Down Expand Up @@ -91,6 +93,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 === "--no-recheck") a.recheck = false;
else if (v === "--computed") a.computed = true;
else if (v === "--mask-media") a.maskMedia = true;
else if (v === "--no-freeze-video") a.freezeVideo = false;
Expand Down Expand Up @@ -224,6 +227,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.
--no-recheck Don't reload a differing shot's right side to find content that
varies per load. Off anyway under --cache-right.
--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.
Expand Down Expand Up @@ -389,6 +394,7 @@ try {
accept: args.accept ?? null,
rerun: args.rerunFailed,
cacheRight: args.cacheRight,
recheck: args.recheck,
acceptedFile: path.join(configPath ? path.dirname(configPath) : process.cwd(), ACCEPTED_FILE),
}),
);
Expand Down
6 changes: 6 additions & 0 deletions src/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ export interface ComparedResult extends BaseResult {
widthDelta: number;
/** Pixels that changed between shots of the same load, painted out on both sides. */
unstablePixels: number;
/** Regions where a second, fresh load of the right side differed from the first. Absent when none did or it wasn't rechecked. */
varies?: Region[];
/** Pixels painted out for them on both sides, like unstable ones, and left out of the score. */
variesPixels?: number;
/** Connected diff patches, largest first. */
regions: Region[];
/** Rows only one side has; null when the rows were too different to align. */
Expand Down Expand Up @@ -356,6 +360,7 @@ const head = (r: ComparedResult) => `
${r.heightDelta ? `<span class="delta">height ${signed(r.heightDelta)}px</span>` : ""}
${r.widthDelta ? `<span class="delta">width ${signed(r.widthDelta)}px</span>` : ""}
${r.unstablePixels ? `<span class="unstable">${r.unstablePixels.toLocaleString("en-US")} px unstable</span>` : ""}
${r.variesPixels ? `<span class="unstable">${r.variesPixels.toLocaleString("en-US")} px vary per load</span>` : ""}
${r.alignedScore !== null ? `<span class="aligned">aligned ${pct(r.alignedScore)}</span>` : ""}
${r.computed ? `<span class="w">${r.computed.dom ? `dom differs (${r.computed.dom})` : "dom identical"}</span>` : ""}
<span class="px">${r.diffPixels.toLocaleString()} / ${r.totalPixels.toLocaleString()} px differ</span>
Expand Down Expand Up @@ -580,6 +585,7 @@ export async function writeEvidence(
const notes = [
...count(errors.length, "error(s)"),
...count(open.filter((r) => r.unstablePixels).length, "shot(s) with unstable pixels"),
...count(open.filter((r) => r.varies).length, "shot(s) vary per load (painted out)"),
...count(open.filter((r) => fmtFailed(r.failed)).length, "shot(s) with failed assets"),
...count(
open.filter((r) => r.diffPixels > 0 && !fails(r, meta.threshold)).length,
Expand Down
Loading
Loading