Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: search params comparison #1965

Merged
merged 3 commits into from
Feb 15, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions contributors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,4 @@
- zainfathoni
- jssisodiya
- guerra08
- jca41
32 changes: 32 additions & 0 deletions packages/remix-react/__tests__/transition-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,20 @@ describe("normal navigation", () => {
expect(t.getState().loaderData.foo).toBe("2");
});

it("does not reload all routes when search does not change", async () => {
let t = setup();
let A = t.navigate.get("/foo?q=1");
await A.loader.resolve("1");
expect(t.rootLoaderMock.calls.length).toBe(1);
expect(t.getState().loaderData.foo).toBe("1");

let B = t.navigate.get("/foo/bar?q=1");
await B.loader.resolve("2");
expect(t.rootLoaderMock.calls.length).toBe(1);

expect(t.getState().loaderData.foobar).toBe("2");
});

it("reloads only routes with changed params", async () => {
let t = setup();

Expand Down Expand Up @@ -314,6 +328,15 @@ describe("no route match", () => {
"module": "",
"path": "/foo",
},
Object {
"action": [MockFunction],
"element": Object {},
"hasLoader": true,
"id": "foobar",
"loader": [MockFunction],
"module": "",
"path": "/foo/bar",
},
Object {
"action": [MockFunction],
"element": Object {},
Expand Down Expand Up @@ -1892,6 +1915,15 @@ let setup = ({ url } = { url: "/" }) => {
element: {},
module: ""
},
{
path: "/foo/bar",
id: "foobar",
hasLoader: true,
loader: createLoader(),
action: createAction(),
element: {},
module: ""
},
{
path: "/bar",
id: "bar",
Expand Down
2 changes: 1 addition & 1 deletion packages/remix-react/transition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1395,7 +1395,7 @@ function filterMatchesToLoad(
// clicked the same link, resubmitted a GET form
createHref(url) === createHref(state.location) ||
// search affects all loaders
url.searchParams.toString() !== state.location.search
url.searchParams.toString() !== state.location.search.substring(1)
) {
return matches.filter(filterByRouteProps);
}
Expand Down