Skip to content

Commit

Permalink
Strip search params from FOW path parameter (#12899)
Browse files Browse the repository at this point in the history
  • Loading branch information
brophdawg11 authored Jan 29, 2025
1 parent ea5a265 commit 1656374
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/honest-socks-fail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/router": patch
---

Strip search parameters from `patchRoutesOnNavigation` `path` param for fetcher calls
71 changes: 71 additions & 0 deletions packages/router/__tests__/lazy-discovery-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2435,5 +2435,76 @@ describe("Lazy Route Discovery (Fog of War)", () => {
expect(router.getFetcher(key).state).toBe("idle");
expect(router.getFetcher(key).data).toBe("C ACTION");
});

it("does not include search params in the `path` (fetcher.load)", async () => {
let capturedPath;

router = createRouter({
history: createMemoryHistory(),
routes: [
{
path: "/",
},
{
id: "parent",
path: "parent",
},
],
async patchRoutesOnNavigation({ path, patch }) {
capturedPath = path;
patch("parent", [
{
id: "child",
path: "child",
loader: () => "CHILD",
},
]);
},
});

let key = "key";
router.fetch(key, "0", "/parent/child?a=b");
await tick();
expect(router.getFetcher(key).state).toBe("idle");
expect(router.getFetcher(key).data).toBe("CHILD");
expect(capturedPath).toBe("/parent/child");
});

it("does not include search params in the `path` (fetcher.submit)", async () => {
let capturedPath;

router = createRouter({
history: createMemoryHistory(),
routes: [
{
path: "/",
},
{
id: "parent",
path: "parent",
},
],
async patchRoutesOnNavigation({ path, patch }) {
capturedPath = path;
patch("parent", [
{
id: "child",
path: "child",
action: () => "CHILD",
},
]);
},
});

let key = "key";
router.fetch(key, "0", "/parent/child?a=b", {
formMethod: "post",
formData: createFormData({}),
});
await tick();
expect(router.getFetcher(key).state).toBe("idle");
expect(router.getFetcher(key).data).toBe("CHILD");
expect(capturedPath).toBe("/parent/child");
});
});
});
4 changes: 2 additions & 2 deletions packages/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2264,7 +2264,7 @@ export function createRouter(init: RouterInit): Router {
if (isFogOfWar) {
let discoverResult = await discoverRoutes(
requestMatches,
path,
new URL(fetchRequest.url).pathname,
fetchRequest.signal
);

Expand Down Expand Up @@ -2556,7 +2556,7 @@ export function createRouter(init: RouterInit): Router {
if (isFogOfWar) {
let discoverResult = await discoverRoutes(
matches,
path,
new URL(fetchRequest.url).pathname,
fetchRequest.signal
);

Expand Down

0 comments on commit 1656374

Please sign in to comment.