diff --git a/src/presentation/boundaries/chunk-recovery-boundary.tsx b/src/presentation/boundaries/chunk-recovery-boundary.tsx index 1ae0bea7..a797f694 100644 --- a/src/presentation/boundaries/chunk-recovery-boundary.tsx +++ b/src/presentation/boundaries/chunk-recovery-boundary.tsx @@ -3,6 +3,7 @@ import { type ErrorInfo, type ReactNode, } from "react"; +import { Button } from "../design-system/index.ts"; import { useLocale } from "../i18n/index.ts"; type RecoveryResult = @@ -110,6 +111,10 @@ function ChunkRecoverySurface({ {message("chunk.failure.title")} {message("chunk.failure.description")} + {/* The automatic reload-once already declined; this one is the user's. */} + window.location.reload()}> + {message("action.reloadOnce")} + ); } diff --git a/src/presentation/routes/app-router.tsx b/src/presentation/routes/app-router.tsx index 7bb878ea..c22429d4 100644 --- a/src/presentation/routes/app-router.tsx +++ b/src/presentation/routes/app-router.tsx @@ -318,7 +318,10 @@ function RegisteredRoute({ }> + {/* React Router reuses this instance across sibling routes; the key + keeps one route's failed chunk from latching onto the next. */} diff --git a/tests/component/chunk-recovery-boundary.test.tsx b/tests/component/chunk-recovery-boundary.test.tsx index 68885686..25d480a4 100644 --- a/tests/component/chunk-recovery-boundary.test.tsx +++ b/tests/component/chunk-recovery-boundary.test.tsx @@ -1,6 +1,7 @@ // @vitest-environment jsdom import { render, screen } from "@testing-library/react"; +import userEvent from "@testing-library/user-event"; import { describe, expect, it, vi } from "vitest"; import { @@ -8,6 +9,19 @@ import { isChunkLoadFailure, } from "../../src/presentation/boundaries/chunk-recovery-boundary.tsx"; import { FeatureBoundary } from "../../src/presentation/boundaries/render-error-boundary.tsx"; +import { ApplicationProvider } from "../../src/presentation/providers/application-provider.tsx"; +import { AppRouter } from "../../src/presentation/routes/app-router.tsx"; +import { createTestApplication } from "../helpers/create-test-application.ts"; + +// The states page stands in for a route chunk the network could not deliver: +// a rejected lazy module throws its rejection on every render, as this does. +vi.mock("../../src/presentation/examples/state-gallery-page.tsx", () => ({ + default: function UnreachableChunk(): never { + throw new TypeError( + "Failed to fetch dynamically imported module: /assets/states.js", + ); + }, +})); function ChunkDefect(): never { throw new TypeError("Failed to fetch dynamically imported module"); @@ -65,4 +79,54 @@ describe("chunk recovery boundary classification", () => { ); expect(recover).not.toHaveBeenCalled(); }); + + it("offers a user-started reload on the failure surface", async () => { + render( + ({ + action: "support" as const, + reason: "reload-already-attempted", + })} + > + + , + ); + + expect( + await screen.findByRole("button", { name: "한 번 새로고침" }), + ).toBeVisible(); + }); + + it("clears a failed route chunk when the user moves to a sibling route", async () => { + // React Router reuses the rendered-route instance between sibling routes, + // so a failure latched in one route's boundary would otherwise follow the + // user to every other page until a full reload. + const user = userEvent.setup(); + window.history.pushState({}, "", "/examples/states"); + render( + + + , + ); + + expect( + await screen.findByRole("heading", { + name: "화면 자산을 복구하지 못했습니다.", + }), + ).toBeVisible(); + + await user.click(screen.getAllByRole("link", { name: "UI 구성요소" })[0]!); + + expect( + await screen.findByRole( + "heading", + { name: "UI 구성요소", level: 1 }, + { timeout: 5000 }, + ), + ).toBeVisible(); + expect( + screen.queryByRole("heading", { name: "화면 자산을 복구하지 못했습니다." }), + ).toBeNull(); + }); });
{message("chunk.failure.description")}