Skip to content

Commit 1656374

Browse files
authored
Strip search params from FOW path parameter (#12899)
1 parent ea5a265 commit 1656374

File tree

3 files changed

+78
-2
lines changed

3 files changed

+78
-2
lines changed

.changeset/honest-socks-fail.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@remix-run/router": patch
3+
---
4+
5+
Strip search parameters from `patchRoutesOnNavigation` `path` param for fetcher calls

packages/router/__tests__/lazy-discovery-test.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2435,5 +2435,76 @@ describe("Lazy Route Discovery (Fog of War)", () => {
24352435
expect(router.getFetcher(key).state).toBe("idle");
24362436
expect(router.getFetcher(key).data).toBe("C ACTION");
24372437
});
2438+
2439+
it("does not include search params in the `path` (fetcher.load)", async () => {
2440+
let capturedPath;
2441+
2442+
router = createRouter({
2443+
history: createMemoryHistory(),
2444+
routes: [
2445+
{
2446+
path: "/",
2447+
},
2448+
{
2449+
id: "parent",
2450+
path: "parent",
2451+
},
2452+
],
2453+
async patchRoutesOnNavigation({ path, patch }) {
2454+
capturedPath = path;
2455+
patch("parent", [
2456+
{
2457+
id: "child",
2458+
path: "child",
2459+
loader: () => "CHILD",
2460+
},
2461+
]);
2462+
},
2463+
});
2464+
2465+
let key = "key";
2466+
router.fetch(key, "0", "/parent/child?a=b");
2467+
await tick();
2468+
expect(router.getFetcher(key).state).toBe("idle");
2469+
expect(router.getFetcher(key).data).toBe("CHILD");
2470+
expect(capturedPath).toBe("/parent/child");
2471+
});
2472+
2473+
it("does not include search params in the `path` (fetcher.submit)", async () => {
2474+
let capturedPath;
2475+
2476+
router = createRouter({
2477+
history: createMemoryHistory(),
2478+
routes: [
2479+
{
2480+
path: "/",
2481+
},
2482+
{
2483+
id: "parent",
2484+
path: "parent",
2485+
},
2486+
],
2487+
async patchRoutesOnNavigation({ path, patch }) {
2488+
capturedPath = path;
2489+
patch("parent", [
2490+
{
2491+
id: "child",
2492+
path: "child",
2493+
action: () => "CHILD",
2494+
},
2495+
]);
2496+
},
2497+
});
2498+
2499+
let key = "key";
2500+
router.fetch(key, "0", "/parent/child?a=b", {
2501+
formMethod: "post",
2502+
formData: createFormData({}),
2503+
});
2504+
await tick();
2505+
expect(router.getFetcher(key).state).toBe("idle");
2506+
expect(router.getFetcher(key).data).toBe("CHILD");
2507+
expect(capturedPath).toBe("/parent/child");
2508+
});
24382509
});
24392510
});

packages/router/router.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2264,7 +2264,7 @@ export function createRouter(init: RouterInit): Router {
22642264
if (isFogOfWar) {
22652265
let discoverResult = await discoverRoutes(
22662266
requestMatches,
2267-
path,
2267+
new URL(fetchRequest.url).pathname,
22682268
fetchRequest.signal
22692269
);
22702270

@@ -2556,7 +2556,7 @@ export function createRouter(init: RouterInit): Router {
25562556
if (isFogOfWar) {
25572557
let discoverResult = await discoverRoutes(
25582558
matches,
2559-
path,
2559+
new URL(fetchRequest.url).pathname,
25602560
fetchRequest.signal
25612561
);
25622562

0 commit comments

Comments
 (0)