Skip to content

Commit 3bf4bf6

Browse files
committed
test(cloudflare-basic): rework PPR fixtures and pins to the live-at-capture contract
Mirrors the test-app pin rework: /ppr-shell/no-hole and /settled pin eternal-MISS (boundary-less readers, capture refuses, axis 1 fresh); /ppr-shell/bake-slow pins the LIVE advancing label (no pin-first). Fixture updates to the new-contract shape, preserving each test's intent: /ppr-shell/inline-action gains loading() (the page hole the bound action streams through — the bake lane can no longer produce its shell; MISS/HIT/partial-replay all green); cache-lab wraps the pulse reader in its own Suspense (products still bake via the handler, pulse holes live — all four cache-lab tests green). Full production suite: 419 passed; the 2 remaining failures are pre-existing on main (verified by base runs: default-prefetch-none offscreen-intersection fails 3/3 on main; location-state history-restore flakes ~50% on main with a hidden-boundary restore window) — tracked separately, not part of this branch.
1 parent 90785d2 commit 3bf4bf6

3 files changed

Lines changed: 107 additions & 84 deletions

File tree

‎tests/cloudflare-basic/e2e/ppr-shell.test.ts‎

Lines changed: 80 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -666,77 +666,88 @@ function describePprShell(mode: "dev" | "build") {
666666
);
667667
});
668668

669-
// --- Negative contract: a loader WITHOUT loading() is not a hole. ---
670-
671-
// /ppr-shell/no-hole has a loader but NO route-level loading(): the BAKE
672-
// lane (docs/design/loader-container-bake.md). The loader executes during
673-
// capture; its settled container (the outer label) bakes into the prelude;
674-
// the nested pendingData promise postpones at the consumer's own inner
675-
// Suspense — a hole. On every HIT the snapshot's loader family overlays
676-
// the recorded container onto the fresh run (outer label PINNED at its
677-
// capture-time seq) while the nested promise stays live (inner seq
678-
// advances per request). Runs on the real KV-backed CFCacheStore under
679-
// workerd, so the loader-family snapshot round-trips the KV envelope.
680-
test("no loading() (bake lane): HITs with the container baked+pinned and the nested promise live", async ({
669+
// --- Negative contract: no boundary above the reader = no shell. ---
670+
671+
// /ppr-shell/no-hole — CONTRACT CHANGE (streaming useLoader): route
672+
// loaders are LIVE at capture unconditionally; the bake lane for
673+
// value-slot loaders is gone. This route's outer read has NO boundary
674+
// above it, so the masked loader root-postpones the capture and the
675+
// <body> sanity gate refuses the shell: ppr on a boundary-less route
676+
// degrades to runtime rendering (once-per-key eternal-MISS warning).
677+
// Axis 1 streams everything FRESH per request. Baking route data is
678+
// expressed via cache()/"use cache", never by omitting loading(). Runs
679+
// on the real KV-backed CFCacheStore under workerd.
680+
test("no loading() and no boundary above the reader: capture refuses, stays MISS, axis 1 streams fresh", async ({
681681
request,
682682
}) => {
683683
const url = f.url("/ppr-shell/no-hole?probe=nohole");
684-
await warmToHit(request, url);
685-
686-
const { html } = await measureFirstChunk(url);
687-
const { prelude, resumed } = splitPrelude(html);
688684

689-
expect(prelude).toMatch(/Streamed outer \d+/);
690-
expect(prelude).toContain("Loading inner...");
691-
expect(prelude).not.toMatch(/Streamed inner \d+/);
692-
expect(resumed).toMatch(/Streamed inner \d+/);
693-
694-
const second = await measureFirstChunk(url);
695685
const outerSeq = (h: string) =>
696686
Number(h.match(/Streamed outer (\d+)/)?.[1]);
697687
const innerSeq = (h: string) =>
698688
Number(h.match(/Streamed inner (\d+)/)?.[1]);
699-
expect(outerSeq(second.html)).toBe(outerSeq(html));
700-
expect(innerSeq(second.html)).toBeGreaterThan(innerSeq(html)!);
689+
690+
let firstHtml = "";
691+
for (let i = 0; i < 3; i++) {
692+
const res = await request.get(url, { headers: HTML_HEADERS });
693+
expect(res.status()).toBe(200);
694+
expect(
695+
res.headers()["x-rango-shell"],
696+
`request #${i} must stay MISS (no boundary above the reader)`,
697+
).toBe("MISS");
698+
const html = await res.text();
699+
expect(html).toMatch(/Streamed outer \d+/);
700+
expect(html).toContain("Loading inner...");
701+
expect(html).toMatch(/Streamed inner \d+/);
702+
if (i === 0) firstHtml = html;
703+
if (i < 2) await new Promise((r) => setTimeout(r, 350));
704+
}
705+
706+
// Liveness: nothing pinned anywhere — both values advance per request.
707+
const last = await request.get(url, { headers: HTML_HEADERS });
708+
const lastHtml = await last.text();
709+
expect(outerSeq(lastHtml)).toBeGreaterThan(outerSeq(firstHtml)!);
710+
expect(innerSeq(lastHtml)).toBeGreaterThan(innerSeq(firstHtml)!);
701711
});
702712

703-
// /ppr-shell/settled: nested-promise SHAPE is the liveness declaration.
704-
// A bake-lane loader's nested promise that is ALREADY RESOLVED at
705-
// container return previously won the capture window and its VALUE was
706-
// snapshot-pinned — every HIT then served the capture-time value to every
707-
// visitor (found live: a storefront basket, with the capturing session's
708-
// identifiers, frozen into the shared shell and served to anonymous
709-
// requests). Nested thenables are now MASKED at capture regardless of
710-
// settle timing: the consumer's own Suspense postpones (its fallback bakes
711-
// as the hole) and every HIT streams the FRESH value. The consumer still
712-
// receives a real promise, so the original #438 regression stays
713-
// impossible. Runs on the real KV-backed CFCacheStore under workerd, so
714-
// the hole-marker record round-trips the KV envelope.
715-
test("bake lane, nested promise settled inside the window: holes anyway — outer pins, nested value stays FRESH per request", async ({
713+
// /ppr-shell/settled — CONTRACT CHANGE (streaming useLoader): the bake
714+
// lane for value-slot loaders is gone, so settle timing can no longer pin
715+
// ANY value — the whole loader is masked at capture, and this route's
716+
// outer read has no boundary above it, so the capture refuses and the
717+
// route stays MISS. The cross-session bake leak this fixture guarded
718+
// against (a storefront basket frozen into the shared shell) is now
719+
// impossible by construction — nothing from a value-slot loader can
720+
// enter a shell. Axis 1 serves everything fresh; hydration stays clean
721+
// and use(data.fast) still receives a real promise (#438). Runs on the
722+
// real KV-backed CFCacheStore under workerd.
723+
test("nested promise settled inside the window: stays MISS, everything fresh per request, hydration clean", async ({
716724
request,
717725
page,
718726
}) => {
719727
const url = f.url("/ppr-shell/settled?probe=settled");
720-
await warmToHit(request, url);
721728

722-
const { html } = await measureFirstChunk(url);
723729
const outerSeq = (h: string) =>
724730
Number(h.match(/Settled outer (\d+)/)?.[1]);
725731
const fastSeq = (h: string) => Number(h.match(/Settled fast (\d+)/)?.[1]);
726-
// Parity: the outer (non-promise) container material is snapshot-pinned.
732+
733+
const first = await request.get(url, { headers: HTML_HEADERS });
734+
expect(first.headers()["x-rango-shell"]).toBe("MISS");
735+
const html = await first.text();
727736
expect(outerSeq(html)).toBeGreaterThan(0);
728-
// The frozen prelude holds the consumer's Suspense fallback, never a
729-
// pinned nested value — the nested promise holes by declaration.
730-
const { prelude } = splitPrelude(html);
731-
expect(prelude).toContain("fast pending...");
732-
expect(prelude).not.toMatch(/Settled fast \d+/);
733-
// Liveness: the nested value is a FRESH execution's and advances per HIT.
734-
expect(fastSeq(html)).toBeGreaterThan(outerSeq(html)!);
735-
const second = await measureFirstChunk(url);
736-
expect(outerSeq(second.html)).toBe(outerSeq(html));
737-
expect(fastSeq(second.html)).toBeGreaterThan(fastSeq(html)!);
737+
expect(html).toMatch(/Settled fast \d+/);
738738

739-
// Browser: the HIT hydrates cleanly — use(data.fast) still receives a
739+
await new Promise((r) => setTimeout(r, 350));
740+
const second = await request.get(url, { headers: HTML_HEADERS });
741+
expect(
742+
second.headers()["x-rango-shell"],
743+
"no boundary above the reader — capture must keep refusing",
744+
).toBe("MISS");
745+
const secondHtml = await second.text();
746+
// Liveness: nothing pinned — both values advance per request.
747+
expect(outerSeq(secondHtml)).toBeGreaterThan(outerSeq(html)!);
748+
expect(fastSeq(secondHtml)).toBeGreaterThan(fastSeq(html)!);
749+
750+
// Browser: axis 1 hydrates cleanly — use(data.fast) still receives a
740751
// real promise (the fresh one), so #438 cannot recur.
741752
using __ = guardHydrationErrors(page);
742753
await page.goto(url);
@@ -846,52 +857,39 @@ function describePprShell(mode: "dev" | "build") {
846857
expect(prelude).toContain("Bare home static content");
847858
});
848859

849-
// /ppr-shell/bake-slow: the PIN-FIRST optimization (loader-cache.ts
850-
// `if (!recorded.holes)`) on the real KV-backed CFCacheStore under workerd.
851-
// The layout registers a 600ms bake-lane loader (no loading() on the
852-
// layout) returning a plain HOLE-FREE container. Its container bakes into
853-
// the snapshot's loader family hole-free, so on a HIT the payload resolves
854-
// the loaderData from the PIN immediately instead of gating on the fresh
855-
// 600ms run (which still executes ungated for side effects). The child keeps
856-
// a fast ~30ms price hole behind loading() so a real shell captures. Two
857-
// guarantees in one: the served label is pinned (frozen across HITs, not the
858-
// advancing fresh seq) AND the pin makes the full HIT response beat the
859-
// 600ms fresh run.
860-
test("pin-first bake lane: a HIT serves the pinned 600ms container fast and frozen across HITs", async ({
860+
// /ppr-shell/bake-slow — CONTRACT CHANGE (streaming useLoader): the
861+
// pin-first bake optimization is gone with the bake lane itself. The
862+
// layout's 600ms loader is masked at capture like every value-slot
863+
// loader; its reader sits inside the child route's loading() boundary,
864+
// so the shell still captures (chrome baked, the route area one live
865+
// hole) and every HIT re-runs the loader FRESH — the label ADVANCES
866+
// across HITs instead of freezing. The full HIT body now gates on the
867+
// real 600ms run; a route wanting the old fast+frozen behavior expresses
868+
// it with cache()/"use cache". Runs on the real KV-backed CFCacheStore
869+
// under workerd.
870+
test("slow layout loader under the child's loading(): HITs with the label LIVE per request (no pin)", async ({
861871
request,
862872
}) => {
863873
const url = f.url("/ppr-shell/bake-slow?probe=bakeslow");
864874
await warmToHit(request, url);
865875

866-
// request.get buffers the WHOLE body, so elapsed covers stream
867-
// completion. Without pin-first the payload gates on the fresh 600ms bake
868-
// run (elapsed >= 600ms); pinned, the recorded container resolves
869-
// immediately and only the ~30ms live hole remains — the 400ms bound
870-
// leaves a 200ms+ margin for CI noise either side.
871-
const start = Date.now();
872876
const res = await request.get(url, { headers: HTML_HEADERS });
873-
const elapsed = Date.now() - start;
874877
expect(res.status()).toBe(200);
875878
expect(res.headers()["x-rango-shell"]).toBe("HIT");
876879
const html = await res.text();
877880

878-
// The pinned bake label rides the HIT body beside the live hole content.
879-
const captured = /bake-\d+/.exec(html)?.[0];
880-
expect(captured, "the pinned bake label rides the HIT body").toBeTruthy();
881+
// The fresh bake label rides the HIT body beside the live hole content.
882+
const captured = /bake-(\d+)/.exec(html);
883+
expect(captured, "the bake label rides the HIT body").toBeTruthy();
881884
expect(html).toContain("Live price:");
882885

883-
expect(
884-
elapsed,
885-
`HIT full-response ${elapsed}ms must beat the 600ms fresh bake run`,
886-
).toBeLessThan(400);
887-
888-
// Frozen: a second HIT serves the SAME captured label (the pin, not the
889-
// fresh seq that keeps advancing in the background) while the price hole
890-
// stays live.
886+
// LIVE: a second HIT serves an ADVANCED label — the loader re-ran
887+
// fresh; nothing from a value-slot loader is pinned into the shell.
891888
const second = await request.get(url, { headers: HTML_HEADERS });
892889
expect(second.headers()["x-rango-shell"]).toBe("HIT");
893890
const secondHtml = await second.text();
894-
expect(/bake-\d+/.exec(secondHtml)?.[0]).toBe(captured);
891+
const secondLabel = /bake-(\d+)/.exec(secondHtml);
892+
expect(Number(secondLabel![1])).toBeGreaterThan(Number(captured![1]));
895893
expect(secondHtml).toContain("Live price:");
896894
});
897895

‎tests/cloudflare-basic/src/pages/cache-lab.tsx‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Suspense } from "react";
12
import { Meta } from "@rangojs/router";
23
import type { HandlerContext } from "@rangojs/router";
34
import { Link } from "@rangojs/router/client";
@@ -89,7 +90,18 @@ export async function CacheLabPage(ctx: HandlerContext) {
8990
</div>
9091
<div className="cache-lab-live-row">
9192
<span>Nested promise PPR hole</span>
92-
<CacheLabLivePulse loader={CacheLabPulseLoader} />
93+
{/* CONTRACT CHANGE (streaming useLoader): value-slot loaders are
94+
live at capture unconditionally — the pulse reader needs its own
95+
boundary for the capture to postpone here (the old bake lane
96+
executed the loader and holed only the nested promise). The
97+
shell still bakes the handler-rendered products around it. */}
98+
<Suspense
99+
fallback={
100+
<span data-testid="cache-lab-pulse-fallback">pulse pending…</span>
101+
}
102+
>
103+
<CacheLabLivePulse loader={CacheLabPulseLoader} />
104+
</Suspense>
93105
</div>
94106
<CacheLabProductGrid
95107
products={[

‎tests/cloudflare-basic/src/urls.tsx‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,20 @@ export const urlpatterns = urls(
827827
name: "pprShellInlineAction",
828828
ppr: { ttl: 300, swr: 120 },
829829
},
830-
() => [loader(PprInlineActionHoleLoader)],
830+
() => [
831+
loader(PprInlineActionHoleLoader),
832+
// CONTRACT CHANGE (streaming useLoader): value-slot loaders are
833+
// live at capture unconditionally — the old bake lane (no
834+
// loading(); the loader executed at capture and its container
835+
// baked around the nested hole) can no longer produce this
836+
// fixture's shell. The route-level loading() is now the page
837+
// hole the bound action streams through.
838+
loading(
839+
<div data-testid="ppr-inline-action-fallback">
840+
Loading inline action…
841+
</div>,
842+
),
843+
],
831844
),
832845
// Prerender + ppr composition (docs/design/shell-fast-path.md):
833846
// build-time segments are the frozen prelude; the slot-owned loader

0 commit comments

Comments
 (0)