From 900659b32cee2e2d41b7a08a85491267753a57c3 Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Thu, 24 Sep 2026 12:03:03 +0900 Subject: [PATCH] fix(presentation): classify WebKit and Vite CSS preload chunk failures (R-8.2) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../boundaries/chunk-recovery-boundary.tsx | 6 ++- .../chunk-recovery-boundary.test.tsx | 42 +++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/presentation/boundaries/chunk-recovery-boundary.tsx b/src/presentation/boundaries/chunk-recovery-boundary.tsx index a797f694..5f9cb8e2 100644 --- a/src/presentation/boundaries/chunk-recovery-boundary.tsx +++ b/src/presentation/boundaries/chunk-recovery-boundary.tsx @@ -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") ); } diff --git a/tests/component/chunk-recovery-boundary.test.tsx b/tests/component/chunk-recovery-boundary.test.tsx index 25d480a4..8c62e875 100644 --- a/tests/component/chunk-recovery-boundary.test.tsx +++ b/tests/component/chunk-recovery-boundary.test.tsx @@ -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( + + + + + , + ); + + 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,