The lazy-route recovery cannot help when the browser aborts a module of the static import graph: nothing of the app runs, the root stays empty, and the only trace is a console error. A Web E2E run hit this right after a page reload, when four modules of the shell failed with net::ERR_NETWORK_CHANGED and the shell never rendered. An inline script in the HTML entry now listens for the error event of the module script and reloads the page once, guarded by a session flag that the entry module clears after a successful boot. The existing preload recovery stays in place; it only covers Vite's chunk preloads of production builds. A new E2E spec aborts one module request during boot and one lazy route request, and expects the sign-in page to render in both cases. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MRtGG9ARfqqhma3t85Ro2u
39 lines
1.3 KiB
TypeScript
39 lines
1.3 KiB
TypeScript
import type { Page } from "@playwright/test";
|
|
import { expect, test } from "@playwright/test";
|
|
|
|
/** Abort the first request for a module once, then let every later request through. */
|
|
async function abortFirstRequest(page: Page, pattern: string) {
|
|
const counter = { aborted: 0 };
|
|
await page.route(pattern, async (route) => {
|
|
if (counter.aborted === 0) {
|
|
counter.aborted += 1;
|
|
await route.abort("failed");
|
|
return;
|
|
}
|
|
await route.continue();
|
|
});
|
|
return counter;
|
|
}
|
|
|
|
test("the app reloads itself once when a module request aborts while booting", async ({ page }) => {
|
|
const counter = await abortFirstRequest(page, "**/src/App.tsx");
|
|
|
|
await page.goto("/sign-in", { waitUntil: "commit" });
|
|
|
|
await expect(page.getByRole("heading", { name: "Sign in to EvOo" })).toBeVisible();
|
|
expect(counter.aborted).toBe(1);
|
|
expect(await page.evaluate(() => sessionStorage.getItem("rakazo:boot-reload"))).toBeNull();
|
|
});
|
|
|
|
test("a lazy route recovers when its module request aborts", async ({ page }) => {
|
|
const counter = await abortFirstRequest(page, "**/src/pages/Auth.tsx");
|
|
|
|
await page.goto("/sign-in");
|
|
|
|
await expect(page.getByRole("heading", { name: "Sign in to EvOo" })).toBeVisible();
|
|
expect(counter.aborted).toBe(1);
|
|
expect(
|
|
await page.evaluate(() => sessionStorage.getItem("rakazo:module-reload:pages/Auth")),
|
|
).toBeNull();
|
|
});
|