From 11eb0dc0e03b7481dcb7104a7e015d0bc312226b Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Thu, 24 Sep 2026 13:29:29 +0900 Subject: [PATCH] fix(presentation): platform routes ignore unknown query parameters (Q-6.8-13a) D-16. The platform `none` codec strips unknown keys instead of rejecting them, so `/?utm_source=x` or an OAuth callback parameter no longer renders "invalid address". The canonical redirect keeps the query of a route whose search codec is `none`, so the URL itself is not rewritten. router.test.tsx used `/examples/ui?unexpected=1` as its invalid-address case, which encoded the old behavior; it now uses the reference list with `?limit=invalid`. New router case (RED before the change) checks the page renders and the URL keeps `?utm_source=mail`; lane gates pass. Co-Authored-By: Claude Opus 5.5 --- src/presentation/routes/app-router.tsx | 8 +++++- .../routes/platform-route-codecs.ts | 4 ++- tests/component/router.test.tsx | 28 +++++++++++++++++-- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/presentation/routes/app-router.tsx b/src/presentation/routes/app-router.tsx index f0960f8d..f29122e6 100644 --- a/src/presentation/routes/app-router.tsx +++ b/src/presentation/routes/app-router.tsx @@ -21,6 +21,7 @@ import { getRoute, ROUTE_FEATURE_OWNER, ROUTE_REGISTRY, + ROUTE_RUNTIME_CONTRACT, } from "../../features/installed-feature-contracts.ts"; import { PLATFORM_ROUTE_REGISTRY, @@ -191,10 +192,15 @@ function CanonicalRouteRedirect({ useEffect(() => { if (input.routeId === "NOT_FOUND") return; const source = `${location.pathname}${location.search}`; - const target = buildRouteUrl(input.routeId, { + const canonical = buildRouteUrl(input.routeId, { params: input.params, search: input.search, }); + // D-16: a route that ignores its query leaves the query in the URL. + const target = + ROUTE_RUNTIME_CONTRACT[input.routeId].searchCodec === "none" + ? `${canonical}${location.search}` + : canonical; if (source === target) { guard.current.reset(); } else if (guard.current.allow(source, target)) { diff --git a/src/presentation/routes/platform-route-codecs.ts b/src/presentation/routes/platform-route-codecs.ts index 830f2e6f..103b3302 100644 --- a/src/presentation/routes/platform-route-codecs.ts +++ b/src/presentation/routes/platform-route-codecs.ts @@ -1,6 +1,8 @@ import { z } from "zod"; export const PLATFORM_ROUTE_CODECS = { - none: z.object({}).strict(), + // D-16: a route without input ignores unknown keys (`?utm_source=`, OAuth + // callback parameters) instead of calling the address invalid. + none: z.object({}), NotFoundSplat: z.object({ "*": z.string().optional() }).strict(), } as const; diff --git a/tests/component/router.test.tsx b/tests/component/router.test.tsx index 161343fa..2e36b123 100644 --- a/tests/component/router.test.tsx +++ b/tests/component/router.test.tsx @@ -148,9 +148,9 @@ describe("generic application router", () => { }, { surface: "invalid-route", - url: "/examples/ui?unexpected=1", - routeId: "EXAMPLES_UI", - title: "UI 구성요소 · Frontend Skeleton", + url: "/examples/reference-resources?limit=invalid", + routeId: "REFERENCE_RESOURCE_LIST", + title: "Reference resources · Frontend Skeleton", disableFeature: false, }, { @@ -200,6 +200,28 @@ describe("generic application router", () => { }, ); + it("ignores unknown query parameters on a platform route and keeps the URL", async () => { + // D-16: `/?utm_source=x` or an OAuth callback parameter is not an invalid + // address. The `none` codec drops it from the parsed input only. + window.history.pushState({}, "", "/examples/ui?utm_source=mail#top"); + const { container } = renderRouter(); + + expect( + await screen.findByRole( + "heading", + { name: "UI 구성요소", level: 1 }, + { timeout: 5000 }, + ), + ).toBeVisible(); + expect(container.querySelector('[data-surface="invalid-route"]')).toBeNull(); + await waitFor(() => + expect(document.title).toBe("UI 구성요소 · Frontend Skeleton"), + ); + expect(`${window.location.pathname}${window.location.search}`).toBe( + "/examples/ui?utm_source=mail", + ); + }); + it("focuses the route heading again when the lazy chunk is already cached", async () => { // §9.7. The first visit resolves the route module asynchronously, so the // router lifecycle and the page header commit separately. A later visit