Skip to content

setSearchParams should not navigate if the state is unchanged #13619

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions contributors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@
- valerii15298
- ValiantCat
- vdusart
- vezaynk
- VictorElHajj
- vijaypushkin
- vikingviolinist
Expand All @@ -389,3 +390,4 @@
- yuleicul
- zeromask1337
- zheng-chuang

7 changes: 6 additions & 1 deletion packages/react-router/lib/dom/lib.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1427,8 +1427,12 @@ export function useSearchParams(
const newSearchParams = createSearchParams(
typeof nextInit === "function" ? nextInit(searchParams) : nextInit
);

const unchanged = newSearchParams === searchParams || newSearchParams.toString() === searchParams.toString()
if (unchanged) return Promise.resolve();
hasSetSearchParamsRef.current = true;
navigate("?" + newSearchParams, navigateOptions);

return navigate("?" + newSearchParams, navigateOptions);
},
[navigate, searchParams]
);
Expand Down Expand Up @@ -2270,3 +2274,4 @@ export function useViewTransitionState(
}

//#endregion