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
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ only the reference has (`band -24`) are missing at y=196. With those rows cut ou
matches exactly (`aligned 100.00%`). The missing rows are the "Pricing" nav link, which
exists only on the reference (`-`). Open `renderdiff-out/about.1440.c1.png` to see it.

**Without `--threshold`, a diff still exits 0**, so read the summary.
**Any difference exits 1.** `--threshold <0..1>` relaxes that to scores below it
(`--threshold 0` never fails on a difference). Read the summary either way.

### For coding agents

Expand Down Expand Up @@ -96,12 +97,14 @@ renderdiff <left-origin> <right-origin> <route…> [options]
| `--left <url>` | Left origin, instead of the first positional one. Giving both is an error. |
| `--right <url>` | Right origin, instead of the second positional one. |
| `--width <n>` | Viewport width; repeatable. Replaces the defaults. |
| `--threshold <0..1>` | Exit non-zero if any comparison scores below this. |
| `--threshold <0..1>` | Exit 1 only if a comparison scores below this, instead of on any difference. `0` never fails on one. |
| `--out <dir>` | Output directory, wiped at the start of a run. Default `./renderdiff-out`. A directory holding files renderdiff didn't write is refused. |
| `--concurrency <n>` | Parallel workers. Default half the CPU cores, between 2 and 8. Lower it when one side is someone's live site. |
| `--config <path>` | Config file. Default: `renderdiff.config.{ts,mts,js,mjs}` in cwd. |
| `--selector <sel>` | Compare the one element this Playwright selector matches, on both sides, instead of the whole page. Applies to every route, over the config's per-route `selector`. |
| `--left-selector <sel>`, `--right-selector <sel>` | That side's selector, over `--selector`. One without the other side (or `--selector`) is an error. |
| `--mask <sel>` | Paint this Playwright selector over on both sides, on every route; repeatable. Added to the config's masks and listed in the report as coverage given up. |
| `--mask-media` | Mask every `iframe`, `video` and `.vjs-text-track-display` (video.js text tracks) on every route, as config `maskMedia: true` does. |
| `--storage-state <file>` | Start both sides with this Playwright storage state (cookies, localStorage), e.g. signed in. Relative to cwd. Over the config's `storageState`. |
| `--left-storage-state <file>`, `--right-storage-state <file>` | That side's storage state, over `--storage-state`. One side alone is fine. |
| `--accept <reason>` | Record this run's differences as accepted, with a reason. See **Accepted differences and reruns**. |
Expand All @@ -121,8 +124,8 @@ range rather than on a boundary, so a layout switch never flaps between runs.

| Exit | Meaning |
| --- | --- |
| `0` | No route errored and none scored below `--threshold`. Without one, a diff still exits 0. |
| `1` | A route scored below `--threshold`. Wins over `3` when both happen. |
| `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. |
| `2` | Bad arguments, bad config, or an origin that isn't responding. |
| `3` | A route errored, so it went unmeasured, or the run crashed (e.g. no Chromium). |

Expand All @@ -149,7 +152,7 @@ screenshots and text) out of git too. Details: [docs/scoping.md](https://github.
## Config file

Flags cover a one-off run. A `renderdiff.config.{ts,mts,js,mjs}` in the working directory
covers a repo you diff repeatedly, and expresses what flags can't: **masks** for content
covers a repo you diff repeatedly, and expresses what flags can't: **per-route masks** for content
that legitimately drifts, extra selectors to hide, extra URLs to block, `before` hooks.

```ts
Expand Down Expand Up @@ -213,7 +216,7 @@ renderdiff http://localhost:3000 https://example.com / /about --rerun-failed

`--accept "<reason>"` writes every difference the run saw to `renderdiff.accepted.json` (next
to the config, or in cwd); commit it. Later, a shot whose every difference matches an entry is
listed on an `accepted:` line and counts neither as differing nor toward `--threshold`;
listed on an `accepted:` line and counts neither as differing nor toward the exit code;
anything new on the same page still shows. `--rerun-failed` reruns only what the last run in
`--out` didn't find clean or accepted and merges it back; it exits 2 if the run differs from
the previous one. Matching rules, what can still hide, and stale entries:
Expand Down Expand Up @@ -287,6 +290,7 @@ Everything lands in the out dir (`./renderdiff-out` by default):
"compared": 1, "errors": 1, "mean": 0.9714,
"worst": { "url": "/about", "width": 1440, "score": 0.9714 },
"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
}
Expand Down
6 changes: 3 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ inputs:
description: Viewport widths separated by spaces or commas. Default renderdiff's five.
default: ""
threshold:
description: Fail when any comparison scores below this (0..1). Without it only errors fail the job.
description: Fail only when a comparison scores below this (0..1). Without it any difference fails the job; 0 never fails on one.
default: ""
concurrency:
description: Parallel workers, which is also the most loads production sees at once.
Expand All @@ -45,7 +45,7 @@ inputs:

outputs:
exit-code:
description: renderdiff's exit code. 0 pass, 1 below threshold, 2 bad input or origin down, 3 a route errored.
description: renderdiff's exit code. 0 pass, 1 a difference (or below threshold), 2 bad input or origin down, 3 a route errored.
value: ${{ steps.run.outputs.exit-code }}
results:
description: Path to results.json.
Expand Down Expand Up @@ -143,7 +143,7 @@ runs:

case $code in
0) verdict="✅ No visual change" ;;
1) verdict="❌ Below threshold" ;;
1) verdict="❌ Visual change" ;;
2) verdict="⚠️ Bad input or an origin is down" ;;
*) verdict="⚠️ A route errored or the run crashed" ;;
esac
Expand Down
2 changes: 1 addition & 1 deletion docs/accepted.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ the reason. Scope it the way you scope any run: pass only the routes and `--widt
Commit the file; it is one entry per line, so its diff reads as what was accepted.

A shot whose every difference matches an accepted one is `accepted`: it is listed on an
`accepted:` line like `clean:`, doesn't count as differing or toward `--threshold`, and has
`accepted:` line like `clean:`, doesn't count as differing or toward the exit code, and has
`"accepted": true` in `results.json` and a badge in the report. Anything else on the page
still shows: a row with some changes accepted says `1 accepted`, and its `dom` line skips
them. A shot with unstable pixels is never accepted, since part of it went unmeasured.
Expand Down
8 changes: 4 additions & 4 deletions docs/github-action.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ exits non-zero.
| `routes` | Separated by spaces or newlines; pairs (`/pricing::/plans`) work. Optional when the config lists routes. |
| `config` | Config file path. Default: `renderdiff.config.{ts,mts,js,mjs}` in the workspace. |
| `widths` | Spaces or commas. Default renderdiff's five. |
| `threshold` | Fail below this score. Without it, only errors (exit 2 or 3) fail the job. |
| `threshold` | Fail only below this score. Without it, any difference fails the job (exit 1); `"0"` never fails on one. |
| `concurrency` | Parallel workers, which is also the most page loads production sees at once. Default 2 on a hosted runner. |
| `storage-state` | Contents of a Playwright storage-state JSON, from a secret. Written to a 0600 file in the runner's temp dir and deleted when renderdiff exits. |
| `accept` | Record this run's differences as accepted, with this reason. See below. |
Expand All @@ -37,7 +37,7 @@ To run the action twice in one job, give each run its own `out` and `artifact-na
matrix, put the matrix value in `artifact-name`. The action sets up Node 24, which later
steps in the job then use.

Outputs: `exit-code` (0 pass, 1 below threshold, 2 bad input or an origin down, 3 a route
Outputs: `exit-code` (0 pass, 1 a difference or below `threshold`, 2 bad input or an origin down, 3 a route
errored) and `results` (the path to `results.json`).

A Vercel preview behind Deployment Protection answers the runner with its login page: a
Expand Down Expand Up @@ -92,7 +92,8 @@ The action waits for `left` to answer, so the server can still be starting.

### Dependency upgrades from Renovate or Dependabot

A dependency bump should change nothing, so fail on any difference:
A dependency bump should change nothing. That's the default without `threshold`: any
difference fails.

```yaml
if: github.actor == 'renovate[bot]' || github.actor == 'dependabot[bot]'
Expand All @@ -101,7 +102,6 @@ A dependency bump should change nothing, so fail on any difference:
with:
left: http://localhost:3000
right: https://example.com
threshold: "1"
```

## Accepted differences: accept in CI
Expand Down
4 changes: 2 additions & 2 deletions docs/how-it-works.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ honestly. This is what renderdiff does to make sure of that.
wrapped (Chrome repeats the top of the page; recent headless Chromium does not), so taller
pages, and element shots taller than that, are captured as tiles through CDP and stitched
back together. Masks are painted onto the final image from each element's bounding box,
so they apply the same way on both paths. Past 40,000px it errors — that's a broken
layout, not a page.
so they apply the same way on both paths. Past 57.6 million pixels (40,000px tall at
1440px wide, about 150,000px at 375px) it errors — that's a broken layout, not a page.

Every run's report ends with a "What was neutralized" section listing the actual block
patterns, mask reasons and pinned settings in effect, so the report can't drift from the
Expand Down
1 change: 1 addition & 0 deletions renderdiff.config.example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export default {
//
// Each needs exactly one of `selector` (a Playwright selector) or `locate`. Without
// `urlPath` it applies to every route; on a pair it matches either side's path.
// `maskMedia: true` (or --mask-media) adds one for iframes, video and video.js text tracks.
masks: [
{
// Baked in at build time from a nightly job, so a local tree and a production
Expand Down
33 changes: 19 additions & 14 deletions skills/renderdiff/SKILL.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: renderdiff
description: Visual-parity check for website migrations. Use when a framework migration, CSS or design-system refactor, template rewrite, CMS move or dependency/build upgrade should not change how pages look, to prove it by screenshot-diffing a local build against production (or any reference) across viewport widths. Also for "did I break the layout", visual regression checks, pixel diffs of two URLs, or running the renderdiff CLI.
description: Visual-parity check for website migrations. Use when a framework migration, CSS or design-system refactor, template rewrite, CMS move or dependency/build upgrade should not change how pages look, to prove it by screenshot-diffing your change against a local build of the base (or production, or any reference) across viewport widths. Also for "did I break the layout", visual regression checks, pixel diffs of two URLs, or running the renderdiff CLI.
allowed-tools: Bash(npx renderdiff:*), Bash(npx renderdiff@latest:*), Bash(renderdiff:*), Read
---

Expand All @@ -13,20 +13,25 @@ npx renderdiff@latest http://localhost:3000 https://example.com /about --width 1
Left (first origin) = your change; right (second) = the reference. `+` means only/more in
your change, `-` only/more in the reference. First run: `npx playwright install chromium`.
Flags: `--help`. Moved page: `/old::/new`. One component: `--selector`. Click-gated state:
a config `before` hook. Signed in: `--storage-state auth.json`. When each is
a config `before` hook. Signed in: `--storage-state auth.json`. Per-load noise: `--mask <sel>`, `--mask-media`. When each is
legitimate: [reference.md](reference.md).

## Loop

1. **Baseline first.** Before changing code, run the unmodified build against the reference
with `--accept "differs before the migration"`: what already differs is recorded, not
yours. Accept only what you looked at, never to get green.
2. Both origins up, with the same content and data. `--dry-run` shows the URL pairs.
Upgrading a dependency or build? The cleanest reference is the pre-upgrade commit in a
`git worktree` on another port: same data, fonts and CDN, so every diff is yours. Serve
a production build: dev overlays and debug bars exist only on your side (Next's and
Astro's are hidden; others go in `hideSelectors`). Routes: one per template or layout,
from the sitemap or router; skip search results, pagination and admin.
1. **Reference: the base, built locally.** When the base can be built, it is the default
reference: the base commit in a `git worktree`, a production build of it on another
port as right, your change as left, both up with the same content. Same data, fonts and CDN, so every diff is yours.
Production as right is a secondary check afterwards: it adds deploy drift, one-sided
third-party content and CSP errors. Serve production builds on both sides: dev overlays
exist only on one side (Next's and Astro's are hidden; others go in `hideSelectors`).
Routes: one per template or layout, from the sitemap or router; skip search results,
pagination and admin. `--dry-run` shows the URL pairs.
2. **Baseline first.** Before changing code, run the base against the reference. Against
the base build that is base vs base, so whatever differs varies per load: mask it
(`--mask-media` for iframes, video and video.js text tracks; `--mask <sel>` or a config
mask with a `reason` for the rest), then rerun until the baseline is clean. Against
production, `--accept "differs before the change"` what is stable drift. Mask or accept
only what you looked at, never to get green.
3. One route, one width. A row: score, `h±N`/`w±N` height/width delta,
`band`, `aligned`, `N reg`, `unstable Npx` (moving pixels, unmeasured), `text`.
4. `failed` first: a stylesheet or font one side didn't load explains the whole row; fix
Expand All @@ -45,8 +50,8 @@ legitimate: [reference.md](reference.md).
`--cache-right`. For a multi-width row, open the widest and narrowest crop.
`accepted:` routes are known; a row saying `1 accepted` still has something new.

Exit: 0 nothing below `--threshold` (**without it, a diff still exits 0**) · 1 below
threshold · 2 bad args/config/origin down · 3 a route errored (unmeasured) or crash.
Exit: 0 no differing pixels, or all accepted (unstable pixels or a failed asset alone still
exit 0: read their rows) · 1 a difference (with `--threshold`: below it), even on `--accept` for one it can't accept (unstable pixels, width change, unaligned height change) · 2 bad args/config/origin down · 3 a route errored (unmeasured) or crash. 1 wins over 3.
All clean? Confirm both sides actually rendered.

**Before you mask, lower the threshold, drop a route or skip widths,** read
Expand All @@ -56,7 +61,7 @@ reference.md's Rationalizations.

1. **Numbers**: the `renderdiff:` line and each differing row.
2. **What you saw**: per route and width, element and property ("/pricing @1440: `.cta` margin-left 24px→16px").
3. **Not verified**: errors, skipped widths, masks, unopened regions, unlisted routes, baseline drift.
3. **Not verified**: errors, skipped widths, masks, unopened regions, unlisted routes, baseline drift and its reference (base build or production).
4. **Call**: parity, regression, or expected change, and why.

A score without looking is not a verdict: 99.6% can be a missing nav link.
Loading
Loading