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
11 changes: 7 additions & 4 deletions docs/output.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ renderdiff: 2 of 3 routes differ (6 of 15 shots), 0 errors, worst 97.41% /about@
A row covers the widths that agree on height and width delta, bands (side and height),
aligned score and text; the score and region count are then shown as ranges, and `unstable`
as the largest. Under a row, `failed` lists stylesheets and font faces a side failed to load
(fix those first), `dom` names up to three elements behind the changes, two properties each
(`@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
(fix those first), `fonts` the web font faces only one side loaded, `dom` names up to three
elements behind the changes, two properties each (`@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. A shot whose only difference varied
between two loads of the right side is clean, but listed under `varies`. `--progress` gets
Expand All @@ -51,14 +51,15 @@ the per-shot output when piped, `--no-progress` the summary on a terminal.
| ` --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. |
| `fonts -"Inter 600" +"Roboto"` | `@font-face` or `FontFace` faces only one side requested (`-`: only the reference, `+`: only your change), as family, weight, style and stretch, `normal` left out. One still loading when read counts as requested. Web fonts only: a system font a side fell back to isn't listed. Usually the same on every route, so see `findings`. |
| `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. |
| `dom +sel` / `-sel` | Element only on the left / only on the right. `+sel::before` / `-sel::after`: a pseudo-element only that side generates. |
| `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). |
| `(re-parented)` | After a `dom` entry: paired across a structure change, so its properties may not be the cause. |
| `1 accepted` | That many of the shot's changes are accepted; the rest are new. |
| `findings: N repeated on 2+ routes` | After the routes: the same `dom` entry, text line or element-less band delta (`band -24px`) on two or more routes, once per line with `×N routes` and where (`/a@1440,375`, then `+N routes`), most widespread first, accepted ones aside. Top 20; `summary.findings` in results.json has them all. One cause behind many rows: fix it once. A selector names an element per page, so the same path may be a different element on another route: check one crop. |
| `findings: N repeated on 2+ routes` | After the routes: the same `dom` entry, text line, `fonts` face or element-less band delta (`band -24px`) on two or more routes, once per line with `×N routes` and where (`/a@1440,375`, then `+N routes`), most widespread first, accepted ones aside. Top 20; `summary.findings` in results.json has them all. One cause behind many rows: fix it once. A selector names an element per page, so the same path may be a different element on another route: check one crop. |
| `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. See [below](#computed-styles---computed). |
| `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. |
Expand Down Expand Up @@ -95,6 +96,7 @@ because an unmeasured route is not a verified one.
| Line | `line -1px@y812` | `line -1px@y812` | `regions[i].line: { y: 812, h: 1, side: "right" }` |
| Unstable | `(unstable 1,204px)` | `unstable 1,204px` | `unstablePixels: 1204` |
| Failed assets | `failed left: font Inter 700` | `failed left: font Inter 700` | `failed: { left: ["font Inter 700"], right: [] }` |
| Font faces | `fonts -"Inter 600"` | `fonts -"Inter 600"` | `fonts: { added: [], removed: ["Inter 600"] }` |

Under each score, `--progress` output and the report card say where to look:

Expand Down Expand Up @@ -345,6 +347,7 @@ pulls a route), scores rounded down to four decimals (so a shot that differs nev
"text": { "added": [], "removed": ["Pricing"] }, // added: left only; removed: right only
"accepted": false, // every band and region matched renderdiff.accepted.json
"failed": { "left": [], "right": [] }, // stylesheets and font faces that didn't load: "font Inter 700", "stylesheet https://…"
"fonts": { "added": [], "removed": ["Inter 600"] }, // web font faces one side loaded; absent when equal
"masked": ["rotating quote (data-renderdiff-mask)"], // absent unless a side marked elements data-renderdiff-mask
"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" },
Expand Down
2 changes: 1 addition & 1 deletion skills/renderdiff/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Pixels decide the score and the exit code in every mode.
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` →
`failed` (a missing stylesheet or font explains the whole row: fix, rerun) → `fonts` → `text` →
`h`/`w`, `band`, `aligned`, `line` → `dom` (`sel prop l→r` is a computed value: find the
*rule*) → `findings:` (one cause on many routes: fix it once) → `computed:` → `Read` the
`crops` for what `dom` doesn't explain (multi-width row: widest and narrowest). Every
Expand Down
3 changes: 3 additions & 0 deletions skills/renderdiff/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ accepted: /blog
/about clean @1152,896,704
@1440 97.41% h-24 band -24@y196 aligned 100.00% text -"Pricing"
failed right: font Inter 700
fonts -"Inter 600"
dom -nav > a[href="/pricing"] "Pricing"
crops about.1440.c1.png
@375 ERROR HTTP 404 at http://localhost:3001/about
Expand All @@ -66,6 +67,7 @@ on stderr: `✗ 2 routes differ (10 shots).` (`below 97.00%` with `--threshold`)
| `/a clean @… accepted @…` | A route with something to read; the widths that are clean or accepted. |
| ` @1440,896 <row>` | Widths agreeing on height and width delta, bands (side and height), aligned score and text; score and region count become ranges, `unstable` the largest. |
| ` failed left: …` | Stylesheets (`stylesheet <url>`) and font faces (`font Inter 700`) that side didn't load (404, CORS, a CDN refusing localhost). Fix first: a fallback font reflows every line. |
| ` fonts -"Inter 600" +"X"` | Web font faces (`@font-face`, `FontFace`) only one side requested: `-` the reference, `+` your change. System fallbacks aren't listed. Not a reason a shot isn't clean; pixels decide. |
| ` 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. |
Expand Down Expand Up @@ -341,6 +343,7 @@ For scripts and drilling into one route; the loop doesn't need it. One result pe
`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
looked at, `[]` when nothing was named); `text` `{ added, removed }`; `failed` `{ left, right }`;
`fonts` `{ added, removed }` (web font faces one side loaded, absent when equal);
`masked` (reasons of `data-renderdiff-mask` elements, absent when none); `images`; `crops`
(`kind`, each side's box with `h` 0 at an insertion point, `layout`, `scale`, `clipped`);
`accepted`; `rightReplayedFrom`; with `--computed`, `computed` (`dom`, 0 = identical;
Expand Down
25 changes: 19 additions & 6 deletions src/capture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export interface Shot {
origin: { x: number; y: number };
/** Stylesheets and font faces that failed to load, e.g. `font Inter 700 italic`, `stylesheet https://…`. */
failed: string[];
/** Web font faces requested (loaded or still loading), e.g. `Inter 600 italic`. Sorted. */
fonts: string[];
/** Reasons of the page's `data-renderdiff-mask` elements, e.g. `rotating quote (data-renderdiff-mask)`. */
marked: string[];
}
Expand Down Expand Up @@ -316,16 +318,25 @@ export async function capture(
const fonts = await page.evaluate(async () => {
await Promise.race([document.fonts.ready, new Promise((r) => setTimeout(r, 5_000))]);
const failed: string[] = [];
const loaded: string[] = [];
document.fonts.forEach((f) => {
if (f.status !== "error") return;
const variant = [f.weight, f.style].filter((v) => v !== "normal" && v !== "400");
failed.push(["font", f.family, ...variant].join(" "));
const weight =
({ normal: "400", bold: "700" } as Record<string, string>)[f.weight] ?? f.weight;
const variant = [weight, f.style, f.stretch].filter(
(v) => !["normal", "400", "100%"].includes(v),
);
// `new FontFace("My Face")` reports `"My Face"`; the same @font-face reports `My Face`.
const name = [f.family.replace(/^"(.*)"$/, "$1"), ...variant].join(" ");
if (f.status === "error") failed.push(`font ${name}`);
// A face still loading at the timeout was requested; reading it as missing would be flaky.
else if (f.status !== "unloaded") loaded.push(name);
});
return failed;
return { failed, loaded };
});
await networkIdle(page, 250, 3_000);
if (cfg.freezeVideo) await page.evaluate(freezeVideo);
const failed = [...new Set([...network.get(page)!.failed, ...fonts])];
const failed = [...new Set([...network.get(page)!.failed, ...fonts.failed])];
const loadedFonts = [...new Set(fonts.loaded)].sort();
await page.addStyleTag({ content: cfg.neutralizeCss }); // anything injected late
if (cfg.lottieFrame !== undefined) await page.evaluate(freezeLottie, cfg.lottieFrame);
await hook("beforeShot");
Expand Down Expand Up @@ -452,7 +463,8 @@ export async function capture(
for (let n = 2; ; n++) {
await page.waitForTimeout(50);
const png = await shoot();
if (png.equals(prev)) return { png, unstable: null, blank, text, origin, failed, marked };
if (png.equals(prev))
return { png, unstable: null, blank, text, origin, failed, fonts: loadedFonts, marked };
if (n === tries)
return {
png,
Expand All @@ -462,6 +474,7 @@ export async function capture(
text,
origin,
failed,
fonts: loadedFonts,
marked,
};
prev = png;
Expand Down
5 changes: 4 additions & 1 deletion src/format.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Line } from "./compare.ts";
import type { Line, TextDiff } from "./compare.ts";
import type { ElementDiff } from "./locate.ts";

/** Number formatting shared by the console summary (`run.ts`) and the HTML report. */
Expand All @@ -11,6 +11,9 @@ export const fmtFailed = (f: { left: string[]; right: string[] } | undefined) =>
(["left", "right"] as const)
.flatMap((s) => (f?.[s].length ? [`${s}: ${f[s].join(", ")}`] : []))
.join("; ");
/** `+"Inter 600" -"Roboto"`: + for faces only the left loaded, - for faces only the right did. */
export const fmtFonts = (f: TextDiff) =>
[...f.added.map((t) => `+"${t}"`), ...f.removed.map((t) => `-"${t}"`)].join(" ");
export const fmtRegion = (r: { x: number; y: number; w: number; h: number }) =>
`${r.w}×${r.h} at (${r.x},${r.y})`;
/** Signed like the height delta: + when left has the extra rows, − when right does. */
Expand Down
9 changes: 9 additions & 0 deletions src/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
fmtBand,
fmtElements,
fmtFailed,
fmtFonts,
fmtLine,
fmtRegion,
pct,
Expand Down Expand Up @@ -72,6 +73,8 @@ export interface ComparedResult extends BaseResult {
accepted: boolean;
/** Stylesheets and font faces that failed to load per side, e.g. `font Inter 700`. */
failed: { left: string[]; right: string[] };
/** Web font faces only one side loaded; `added` is on left only. Absent when both loaded the same. */
fonts?: TextDiff;
/** With `--cache-right`: when the recording the right side was replayed from was made, ISO. */
rightReplayedFrom?: string;
/** With `--computed`: the computed-style diff; null when the snapshot failed, with `computedError` saying why. */
Expand Down Expand Up @@ -186,6 +189,11 @@ export function pixelFindings(results: RouteResult[]): PixelFinding[] {
}
for (const t of r.text.added) tokens.set(`+"${t}"`, undefined);
for (const t of r.text.removed) tokens.set(`-"${t}"`, undefined);
// Clean shots are walked too, and a font difference that painted nothing isn't a finding.
if (r.diffPixels && r.fonts) {
for (const t of r.fonts.added) tokens.set(`fonts +"${t}"`, undefined);
for (const t of r.fonts.removed) tokens.set(`fonts -"${t}"`, undefined);
}
for (const [finding, selector] of tokens) {
const f = out.get(finding) ?? { finding, ...(selector ? { selector } : {}), at: [] };
out.set(finding, f);
Expand Down Expand Up @@ -384,6 +392,7 @@ function findings(r: ComparedResult, crop = cropLink): string {
const items: string[] = [];
const failed = fmtFailed(r.failed);
if (failed) items.push(`<p class="failed">failed to load: ${esc(failed)}</p>`);
if (r.fonts) items.push(`<p class="failed">fonts ${esc(fmtFonts(r.fonts))}</p>`);
if (r.regions.length) {
items.push(
`<p>${r.regions.length} region(s)</p><ul class="regions">${r.regions
Expand Down
21 changes: 20 additions & 1 deletion src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,16 @@ import {
type ResolvedConfig,
type Route,
} from "./config.ts";
import { fmtBand, fmtElements, fmtFailed, fmtLine, fmtRegion, pct, signed } from "./format.ts";
import {
fmtBand,
fmtElements,
fmtFailed,
fmtFonts,
fmtLine,
fmtRegion,
pct,
signed,
} from "./format.ts";
import {
fails,
fmtPixelFindings,
Expand Down Expand Up @@ -488,6 +497,10 @@ export async function run({

if (!rightShot.failed.length) recorded.push(shotId(route, width));
const marked = [...new Set([...leftShot.marked, ...rightShot.marked])];
const fonts = {
added: leftShot.fonts.filter((f) => !rightShot.fonts.includes(f)),
removed: rightShot.fonts.filter((f) => !leftShot.fonts.includes(f)),
};
results.push({
...entry,
status: "compared",
Expand All @@ -499,6 +512,7 @@ export async function run({
accepted: false,
failed: { left: leftShot.failed, right: rightShot.failed },
...(marked.length ? { masked: marked } : {}),
...(fonts.added.length || fonts.removed.length ? { fonts } : {}),
...computed,
...(replayedAt ? { rightReplayedFrom: new Date(replayedAt).toISOString() } : {}),
});
Expand Down Expand Up @@ -1016,6 +1030,11 @@ export function compact(
right: [...new Set(g.flatMap((r) => r.failed?.right ?? []))],
});
if (failed) out.push(` failed ${failed}`);
const fonts = fmtFonts({
added: [...new Set(g.flatMap((r) => r.fonts?.added ?? []))],
removed: [...new Set(g.flatMap((r) => r.fonts?.removed ?? []))],
});
if (fonts) out.push(` fonts ${fonts}`);
const dom = elementsOf(g[0]!);
if (dom.length)
out.push(` dom ${g.length > 1 ? `@${g[0]!.width} ` : ""}${fmtElements(dom)}`);
Expand Down
7 changes: 5 additions & 2 deletions tests/fixtures/pages/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Three groups:
elements each change names (`margin`, `color`, `nav`), and a lost `::before` line and a
re-parented pairing (`divider`).
- **Guard rails** — `blank`, `tall`, `animated`, `lazy`, `lazy-deep`, `lazy-js`, `lazy-grow`, `consent`,
`drifting`, `tracker`, `clock`, `ticker`, `unsettled`, `unsettled-once`, `sprite`, `short`, `tall-region`, `reorder`, `stripe`, `frameset`, `menu`, `scroll-spy`, `signed-in`, `fixed`, `inserted`, `labelled`, `broken-asset`, `media`, `long`, `video`, `video-seek`, `lottie`, `hang`, `origin`, `cooperate`, `mask-geometry`, `bistable`.
`drifting`, `tracker`, `clock`, `ticker`, `unsettled`, `unsettled-once`, `sprite`, `short`, `tall-region`, `reorder`, `stripe`, `frameset`, `menu`, `scroll-spy`, `signed-in`, `fixed`, `inserted`, `labelled`, `broken-asset`, `fonts`, `media`, `long`, `video`, `video-seek`, `lottie`, `hang`, `origin`, `cooperate`, `mask-geometry`, `bistable`.
One per defence in `src/capture.ts` / `src/config.ts`.

## Authoring rules
Expand All @@ -35,7 +35,10 @@ Breaking any of these produces a flaky suite, and the flake looks like a renderd
side is an integer, whereas `place-items: center` rounds. Give both mechanisms an even
box in an even container and they agree.
3. **No webfonts.** `shared/base.css` sets a local monospace stack. A webfont means a
network fetch and a possible FOUT, which differs between two loads seconds apart.
network fetch and a possible FOUT, which differs between two loads seconds apart. The
exception is `shared/blank.ttf`, a glyph-less face used by `fonts`: text falls back to
the local stack on both sides. It was generated with fontTools (`.notdef` only, empty
cmap), so there is no licence to carry.
4. **No external assets.** Images come from `/shared/img/` on the fixture origin. Nothing
leaves localhost, so the suite works offline and in CI.
5. **Identical text on both sides.** Only the inline `<style>` and the class names differ.
Expand Down
28 changes: 28 additions & 0 deletions tests/fixtures/pages/fonts/left.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Font faces</title>
<link rel="stylesheet" href="/shared/base.css">
<style>
/* GUARD RAIL for font faces. Both sides load the glyph-less Blank face; only the right also
declares a 600 face for the heading, so the right loads one face the left doesn't. The
block differs so the route has a row to carry it. */
@font-face { font-family: "Blank"; src: url("/shared/blank.ttf"); }
body { font-family: "Blank", ui-monospace, SFMono-Regular, Menlo, monospace; }
h1 { font-weight: 600; }
.box { width: 208px; height: 160px; background: #c62828; }
</style>
</head>
<body>
<div class="page">
<h1>Font faces</h1>
<p class="lede">This pair is deliberately different. The block below is red on the left and blue on the right, and only the right declares a bold face for the heading.</p>
<div class="box"></div>
<section class="notes">
<h2>Notes</h2>
<p>A face one side loads and the other doesn't is easy to miss in the pixels. Naming it tells the reader where to look first.</p>
</section>
</div>
</body>
</html>
Loading
Loading