Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
---
"react-router": patch
---

Strip search parameters from `patchRoutesOnNavigation` `path` param for fetcher calls
87 changes: 87 additions & 0 deletions packages/react-router/__tests__/router/lazy-discovery-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2333,5 +2333,92 @@ describe("Lazy Route Discovery (Fog of War)", () => {
expect(router.getFetcher(key).state).toBe("idle");
expect(fetcherData.get(key)).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";

let data;
router.subscribe((state) => {
if (state.fetchers.has("key")) {
data = state.fetchers.get("key")!.data;
}
});

router.fetch(key, "0", "/parent/child?a=b");
await tick();
expect(router.getFetcher(key).state).toBe("idle");
expect(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";

let data;
router.subscribe((state) => {
if (state.fetchers.has("key")) {
data = state.fetchers.get("key")!.data;
}
});

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