commit d6c8ccb435d172cf1b6faa05bb07dcf4b9f2c0df
parent 2273cc6bdec611b4aa61eaf0234e9f9d6dff79d9
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Wed, 18 Nov 2026 01:50:45 -0500
e2e: streaming.spec pins the shell-first order, the skeleton boxes and the refresh
For the dashboard, /jobs, /settings, /storage and /channels: the heading
arrives while every section is still held back; each skeleton's box is
the box of the section that replaces it, to 4 px; a refresh (AutoRefresh)
with every section held back brings no skeleton back; the console stays
clean (no hydration mismatch from the promise props). And a channel
that does not exist still answers 404.
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat:
1 file changed, 184 insertions(+), 0 deletions(-)
diff --git a/editor/e2e/streaming.spec.ts b/editor/e2e/streaming.spec.ts
@@ -0,0 +1,184 @@
+import { test, expect, type Page } from "@playwright/test";
+import { resetData, writeSettings } from "./helpers";
+
+// THE PAGES THAT STREAM. The dashboard, /jobs, /settings, /storage and
+// /channels send their shell — the sidebar, the heading, the controls — at
+// once, and each slow section when its read is done, behind a <Suspense>
+// boundary whose fallback is a skeleton the size of what is coming.
+//
+// Against this fixture every read is over in milliseconds, so the test server
+// honours a cookie (app/lib/streamDelay.ts, inert outside a test server) that
+// holds every streamed section back. With it a spec can see the three things
+// worth pinning:
+//
+// 1. THE SHELL COMES FIRST: the heading is in the document before any
+// section is.
+// 2. NOTHING MOVES WHEN A SECTION ARRIVES: each skeleton's box is the box of
+// the section that replaces it, to a few px.
+// 3. A REFRESH NEVER BRINGS A SKELETON BACK: router.refresh() (the global
+// AutoRefresh) is a transition, so a section already on screen stays
+// until its new render is ready.
+//
+// And the one thing streaming must not cost: a page that calls notFound()
+// still answers 404. Only these static routes carry a boundary; none of them
+// can be "not found". (navigation.spec.ts explains what a loading.tsx did to
+// that, and why there is none.)
+
+const DELAY_MS = 1500;
+const TOLERANCE_PX = 4;
+
+type Streamed = {
+ path: string;
+ heading: string;
+ // data-stream-skeleton / data-stream-filled names, in document order.
+ sections: string[];
+};
+
+const PAGES: Streamed[] = [
+ {
+ path: "/",
+ heading: "Dashboard",
+ sections: ["dashboard-pipeline", "dashboard-needs-work", "dashboard-channels"],
+ },
+ { path: "/jobs", heading: "Jobs", sections: ["jobs-list"] },
+ { path: "/settings", heading: "Settings", sections: ["settings-x", "settings-archives"] },
+ { path: "/storage", heading: "Storage", sections: ["storage-locations"] },
+ { path: "/channels", heading: "Channels", sections: ["channels-freshness", "channels-rack"] },
+];
+
+async function holdSections(page: Page, baseURL: string) {
+ await page.context().addCookies([
+ { name: "e2e-stream-delay", value: String(DELAY_MS), url: baseURL },
+ ]);
+}
+
+// What a browser console must not say on a streamed page: a hydration
+// mismatch, a suspended-outside-a-boundary error, an uncaught exception.
+function watchConsole(page: Page): string[] {
+ const problems: string[] = [];
+ page.on("console", (m) => {
+ if (m.type() === "error") problems.push(m.text());
+ });
+ page.on("pageerror", (e) => problems.push(String(e)));
+ return problems;
+}
+
+test.describe("streamed pages", () => {
+ test.beforeEach(async () => {
+ await resetData("channel-with-counts");
+ });
+
+ for (const p of PAGES) {
+ test(`${p.path}: the shell is sent before its sections`, async ({ baseURL }) => {
+ const started = Date.now();
+ const res = await fetch(baseURL + p.path, {
+ headers: {
+ "Accept-Encoding": "identity",
+ Cookie: `e2e-stream-delay=${DELAY_MS}`,
+ },
+ });
+ expect(res.status).toBe(200);
+ const reader = res.body!.getReader();
+ const decoder = new TextDecoder();
+ let html = "";
+ let shellAt = -1;
+ let shell = "";
+ for (;;) {
+ const { done, value } = await reader.read();
+ if (done) break;
+ html += decoder.decode(value, { stream: true });
+ if (shellAt < 0 && html.includes("</h1>")) {
+ shellAt = Date.now() - started;
+ shell = html;
+ }
+ }
+ const total = Date.now() - started;
+ // The heading arrived while the sections were still held back…
+ expect(shellAt, "the heading never arrived").toBeGreaterThanOrEqual(0);
+ expect(shellAt, `shell at ${shellAt}ms`).toBeLessThan(DELAY_MS);
+ expect(total).toBeGreaterThanOrEqual(DELAY_MS);
+ // …with every skeleton in place and no section filled yet…
+ for (const name of p.sections) {
+ expect(shell, name).toContain(`data-stream-skeleton="${name}"`);
+ expect(shell, name).not.toContain(`data-stream-filled="${name}"`);
+ // …and each section did stream in after it.
+ expect(html, name).toContain(`data-stream-filled="${name}"`);
+ }
+ });
+
+ test(`${p.path}: each skeleton holds the box of the section that replaces it`, async ({
+ page,
+ baseURL,
+ }) => {
+ const problems = watchConsole(page);
+ await holdSections(page, baseURL!);
+ await page.goto(p.path, { waitUntil: "commit" });
+ await expect(
+ page.getByRole("heading", { name: p.heading, level: 1 }),
+ ).toBeAttached();
+ const before: Record<string, { x: number; y: number; width: number; height: number }> = {};
+ for (const name of p.sections) {
+ const skeleton = page.locator(`[data-stream-skeleton="${name}"]`);
+ await expect(skeleton, name).toBeVisible();
+ before[name] = (await skeleton.boundingBox())!;
+ }
+ for (const name of p.sections) {
+ const filled = page.locator(`[data-stream-filled="${name}"]`);
+ await expect(filled, name).toBeVisible({ timeout: 15_000 });
+ }
+ await expect(page.locator("[data-stream-skeleton]")).toHaveCount(0);
+ for (const name of p.sections) {
+ const after = (await page.locator(`[data-stream-filled="${name}"]`).boundingBox())!;
+ const b = before[name];
+ const say = `${name}: skeleton ${JSON.stringify(b)} filled ${JSON.stringify(after)}`;
+ expect.soft(Math.abs(after.y - b.y), say).toBeLessThanOrEqual(TOLERANCE_PX);
+ expect.soft(Math.abs(after.height - b.height), say).toBeLessThanOrEqual(TOLERANCE_PX);
+ expect.soft(Math.abs(after.x - b.x), say).toBeLessThanOrEqual(TOLERANCE_PX);
+ expect.soft(Math.abs(after.width - b.width), say).toBeLessThanOrEqual(TOLERANCE_PX);
+ }
+ expect(problems, problems.join("\n")).toEqual([]);
+ });
+
+ test(`${p.path}: a refresh never brings a skeleton back`, async ({ page, baseURL }) => {
+ await writeSettings({ autoRefreshIntervalSeconds: 1, adminTitle: "Before Title" });
+ const problems = watchConsole(page);
+ await holdSections(page, baseURL!);
+ await page.goto(p.path);
+ for (const name of p.sections) {
+ await expect(page.locator(`[data-stream-filled="${name}"]`), name).toBeVisible({
+ timeout: 15_000,
+ });
+ }
+ await expect(page.locator("[data-stream-skeleton]")).toHaveCount(0);
+ // Count every skeleton that enters the document from here on.
+ await page.evaluate(() => {
+ const w = window as unknown as { __skeletons: number };
+ w.__skeletons = 0;
+ new MutationObserver(() => {
+ w.__skeletons += document.querySelectorAll("[data-stream-skeleton]").length;
+ }).observe(document.body, { childList: true, subtree: true });
+ });
+ // A change the passive refresher brings in: the sidebar's title is the
+ // root layout's, so seeing the new one means a whole refresh landed —
+ // with every section held back DELAY_MS on the way.
+ await writeSettings({ autoRefreshIntervalSeconds: 1, adminTitle: "After Title" });
+ await expect(page.locator("aside").getByText("After Title")).toBeVisible({
+ timeout: 20_000,
+ });
+ for (const name of p.sections) {
+ await expect(page.locator(`[data-stream-filled="${name}"]`), name).toBeVisible();
+ }
+ expect(
+ await page.evaluate(() => (window as unknown as { __skeletons: number }).__skeletons),
+ ).toBe(0);
+ expect(problems, problems.join("\n")).toEqual([]);
+ });
+ }
+
+ // The regression guard beside navigation.spec.ts's: a boundary on the static
+ // routes must not turn another route's notFound() into a 200.
+ test("a channel that does not exist still answers 404", async ({ request }) => {
+ const res = await request.get("/channels/this-channel-does-not-exist");
+ expect(res.status()).toBe(404);
+ });
+});