Skip to content
Closed
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
5 changes: 4 additions & 1 deletion pm-stack/aggregator/src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,10 @@ setTimeout(function () {
if (!skel) return;
var p = document.createElement("p");
p.className = "frag-failed";
p.innerHTML = "the live view did not arrive &mdash; <a href="" + location.pathname + "?full=1">load the full page</a>";
var a = document.createElement("a");
a.href = location.pathname + "?full=1";
a.textContent = "load the full page";
p.append("the live view did not arrive \u2014 ", a);
skel.replaceWith(p);
});
}, ${FRAG_WATCHDOG_MS});
Expand Down
33 changes: 33 additions & 0 deletions pm-stack/aggregator/test/frag-watchdog-1503.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { describe, expect, test } from "bun:test";
import { fixtureSource } from "../src/sources/fixtures.ts";
import {
FRAG_WATCHDOG_MS,
FRAG_WATCHDOG_SCRIPT,
renderAttentionShell,
renderBoardShell,
renderOverviewShell,
Expand Down Expand Up @@ -54,4 +55,36 @@ describe("shell fragment watchdog (#1503)", () => {
expect(html).toContain("frag-failed");
expect(html.indexOf('class="today-health-strip"')).toBeLessThan(html.indexOf('class="skel"'));
});

// #11410: the shells only asserted on strings, so a quoting bug that
// made the script unparseable shipped unnoticed. Parse and run it.
test("watchdog script parses and swaps a stalled skeleton for the notice", () => {
const body = FRAG_WATCHDOG_SCRIPT.replace(/^<script>/, "").replace(/<\/script>$/, "");
let fired: (() => void) | undefined;
let delay = 0;
const created: Array<Record<string, unknown>> = [];
let replacement: Record<string, unknown> | undefined;
const skel = { replaceWith: (node: Record<string, unknown>) => (replacement = node) };
const doc = {
querySelectorAll: () => [{ querySelector: () => skel }, { querySelector: () => null }],
createElement: (tag: string) => {
const node: Record<string, unknown> = { tag, children: [] as unknown[] };
node.append = (...parts: unknown[]) => (node.children as unknown[]).push(...parts);
created.push(node);
return node;
},
};
const run = new Function("document", "location", "setTimeout", body);
run(doc, { pathname: "/board" }, (fn: () => void, ms: number) => {
fired = fn;
delay = ms;
});
expect(delay).toBe(FRAG_WATCHDOG_MS);
fired?.();
expect(replacement?.className).toBe("frag-failed");
const link = created.find((node) => node.tag === "a");
expect(link?.href).toBe("/board?full=1");
expect(link?.textContent).toBe("load the full page");
expect(replacement?.children).toEqual(["the live view did not arrive \u2014 ", link]);
});
});