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 <noreply@anthropic.com>
This commit is contained in:
DongHyeonka
2026-09-24 13:44:38 +09:00
co-authored by Claude Opus 5.5
parent 22d4e8a29d
commit 11eb0dc0e0
3 changed files with 35 additions and 5 deletions
+7 -1
View File
@@ -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)) {
@@ -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;
+25 -3
View File
@@ -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