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
2 changes: 1 addition & 1 deletion docs/how-it-works.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ honestly. This is what renderdiff does to make sure of that.
- **Kills animation, transitions and caret blink**, and hides common consent banners and
dev toolbars.
- **Settles the page** — makes native lazy images eager, scrolls every viewport-height
slice a frame at a time so script lazy loaders fire, waits for every image to decode,
slice a frame at a time, to the bottom even as the page grows, so script lazy loaders fire, waits for every image to decode,
`document.fonts.ready` (at most 5s) and up to 3s for the network to go 250ms with nothing in flight
(server-sent events and beacons don't count), then re-injects the stylesheet to
catch late-injected chrome. Stylesheets that failed or answered ≥ 400 (blocked URLs
Expand Down
7 changes: 5 additions & 2 deletions src/capture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,11 @@ export async function capture(
// The fake clock drives rAF too, so add wall time for a real paint per slice.
const frame = () => new Promise((r) => requestAnimationFrame(() => setTimeout(r, 32)));
Array.from(document.images).forEach((img) => (img.loading = "eager"));
const h = Math.min(document.documentElement.scrollHeight, maxHeight);
for (let y = 0; y < h; y += window.innerHeight) {
for (
let y = 0;
y < Math.min(document.documentElement.scrollHeight, maxHeight);
y += window.innerHeight
) {
window.scrollTo(0, y);
await frame();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/pages/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Three groups:
alignment (`taller`, `nav`, and `shifted`, which has no band), the text diff (`nav`) and the
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`, `consent`,
- **Guard rails** — `blank`, `tall`, `animated`, `lazy`, `lazy-deep`, `lazy-js`, `lazy-grow`, `consent`,
`drifting`, `tracker`, `clock`, `ticker`, `unsettled`, `sprite`, `short`, `tall-region`, `reorder`, `stripe`, `frameset`, `menu`, `signed-in`, `fixed`, `inserted`, `labelled`, `broken-asset`, `media`, `long`, `video`.
One per defence in `src/capture.ts` / `src/config.ts`.

Expand Down
51 changes: 51 additions & 0 deletions tests/fixtures/pages/lazy-grow/left.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Layout parity</title>
<link rel="stylesheet" href="/shared/base.css">
<style>
/* GUARD RAIL for pages that grow while scrolled. This side appends a section when the
bottom comes into view, and its images load only if the capture scrolls on into it. */
.spacer { height: 1800px; margin: 0 0 32px; background: var(--fill); border: 1px solid var(--line); }
.spacer.more { height: 2400px; }
.gallery { display: flex; flex-direction: column; gap: var(--gap); }
</style>
</head>
<body>
<div class="page">
<h1>Growing page guard rail</h1>
<p class="lede">A section appended when the bottom scrolls into view, with four images more than four thousand pixels down, loaded by an IntersectionObserver on this side and directly on the other.</p>

<div class="spacer"></div>
<div id="more"></div>
<div id="end"></div>
<script>
const io = new IntersectionObserver((entries) => {
for (const e of entries) {
if (!e.isIntersecting) continue;
io.unobserve(e.target);
if (e.target.id !== "end") {
e.target.src = e.target.dataset.src;
continue;
}
document.getElementById("more").innerHTML = `<div class="spacer more"></div>
<div class="gallery">
<img class="shot" data-src="/shared/img/slate.svg" alt="slate">
<img class="shot" data-src="/shared/img/azure.svg" alt="azure">
<img class="shot" data-src="/shared/img/moss.svg" alt="moss">
<img class="shot" data-src="/shared/img/slate.svg" alt="slate">
</div>`;
document.querySelectorAll("img[data-src]").forEach((img) => io.observe(img));
}
});
io.observe(document.getElementById("end"));
</script>

<section class="notes">
<h2>Notes</h2>
<p>Parity here means the capture followed the page down as it grew and every image it added was fetched and decoded before the shot.</p>
</section>
</div>
</body>
</html>
34 changes: 34 additions & 0 deletions tests/fixtures/pages/lazy-grow/right.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Layout parity</title>
<link rel="stylesheet" href="/shared/base.css">
<style>
.spacer { height: 1800px; margin: 0 0 32px; background: var(--fill); border: 1px solid var(--line); }
.spacer.more { height: 2400px; }
.gallery { display: flex; flex-direction: column; gap: var(--gap); }
</style>
</head>
<body>
<div class="page">
<h1>Growing page guard rail</h1>
<p class="lede">A section appended when the bottom scrolls into view, with four images more than four thousand pixels down, loaded by an IntersectionObserver on this side and directly on the other.</p>

<div class="spacer"></div>
<div id="more"><div class="spacer more"></div>
<div class="gallery">
<img class="shot" src="/shared/img/slate.svg" alt="slate">
<img class="shot" src="/shared/img/azure.svg" alt="azure">
<img class="shot" src="/shared/img/moss.svg" alt="moss">
<img class="shot" src="/shared/img/slate.svg" alt="slate">
</div></div>
<div id="end"></div>

<section class="notes">
<h2>Notes</h2>
<p>Parity here means the capture followed the page down as it grew and every image it added was fetched and decoded before the shot.</p>
</section>
</div>
</body>
</html>
1 change: 1 addition & 0 deletions tests/helpers/corpus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const GUARDRAILS = [
"lazy",
"lazy-deep",
"lazy-js",
"lazy-grow",
"consent",
"drifting",
"tracker",
Expand Down
2 changes: 1 addition & 1 deletion tests/visual/guardrails.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ describe("motion", () => {
});

describe("lazy images", () => {
for (const route of ["/lazy-deep", "/lazy-js"]) {
for (const route of ["/lazy-deep", "/lazy-js", "/lazy-grow"]) {
test(`${route}: images more than 4,000px below the fold load before the shot`, async () => {
const run = await capture([route], { widths: [1440, 375] });
assert.equal(run.code, 0, context(run));
Expand Down
Loading