fix(presentation): classify WebKit and Vite CSS preload chunk failures (R-8.2)
isChunkLoadFailure only knew the Chromium/Firefox wording, so Safari's "Importing a module script failed." and Vite's "Unable to preload CSS for …" were treated as ordinary render defects and never reached recoverChunk. Both strings are now recognized. Vite dispatches vite:preloadError and, unless a listener calls preventDefault(), rethrows the same error into the dynamic import. That rejection reaches the route's ChunkRecoveryBoundary, so no listener in bootstrap/main.tsx was added: a listener that reloads would bypass the reload-once guard, and one that prevents the default would swallow the error. Verified: RED "recognizes the WebKit module failure and the Vite CSS preload failure" (false) and "recovers when Vite rethrows a vite:preloadError into the lazy import" (recover not called, no failure surface) failed before and pass after. check:architecture, check:types:app, check:types:test, lint, test:component pass; test:unit passes except the pre-existing removal-fixture test (needs generated artifacts/ files absent from a fresh worktree). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
ad2b733ae9
commit
900659b32c
@@ -32,7 +32,11 @@ export function isChunkLoadFailure(error: unknown): boolean {
|
||||
value.includes("chunkloaderror") ||
|
||||
value.includes("loading chunk") ||
|
||||
value.includes("dynamically imported module") ||
|
||||
value.includes("failed to fetch module script")
|
||||
value.includes("failed to fetch module script") ||
|
||||
// WebKit's wording for the same failed dynamic import.
|
||||
value.includes("importing a module script failed") ||
|
||||
// Vite rethrows a `vite:preloadError` into the import unless prevented.
|
||||
value.includes("unable to preload css")
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import { render, screen } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { lazy, Suspense } from "react";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import {
|
||||
@@ -41,6 +42,47 @@ describe("chunk recovery boundary classification", () => {
|
||||
expect(isChunkLoadFailure(new Error("ordinary render defect"))).toBe(false);
|
||||
});
|
||||
|
||||
it("recognizes the WebKit module failure and the Vite CSS preload failure", () => {
|
||||
expect(
|
||||
isChunkLoadFailure(new TypeError("Importing a module script failed.")),
|
||||
).toBe(true);
|
||||
expect(
|
||||
isChunkLoadFailure(
|
||||
new Error("Unable to preload CSS for /assets/states-3f2a.css"),
|
||||
),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("recovers when Vite rethrows a vite:preloadError into the lazy import", async () => {
|
||||
// Vite dispatches `vite:preloadError` and, unless a listener prevents it,
|
||||
// rejects the dynamic import with the same error. That rejection is what
|
||||
// reaches this boundary.
|
||||
const Page = lazy(() =>
|
||||
Promise.reject(new Error("Unable to preload CSS for /assets/states.css")),
|
||||
);
|
||||
const recover = vi.fn(async () => ({
|
||||
action: "support" as const,
|
||||
reason: "reload-already-attempted",
|
||||
}));
|
||||
render(
|
||||
<Suspense fallback={null}>
|
||||
<ChunkRecoveryBoundary chunkId="route-states" recover={recover}>
|
||||
<Page />
|
||||
</ChunkRecoveryBoundary>
|
||||
</Suspense>,
|
||||
);
|
||||
|
||||
expect(
|
||||
await screen.findByRole("heading", {
|
||||
name: "화면 자산을 복구하지 못했습니다.",
|
||||
}),
|
||||
).toBeVisible();
|
||||
expect(recover).toHaveBeenCalledWith({
|
||||
chunkId: "route-states",
|
||||
failureKind: "CHUNK_LOAD_FAILURE",
|
||||
});
|
||||
});
|
||||
|
||||
it("runs the recovery input only for a lazy chunk rejection", async () => {
|
||||
const recover = vi.fn(async () => ({
|
||||
action: "support" as const,
|
||||
|
||||
Reference in New Issue
Block a user