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,