You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The search middleware changes the search object. This can cause unexpected behavior when the search object is the same across multiple runs of a Link component.
This does not affect the use case where the search options are provided directly in the Link in React and Solid.
Add retainSearchParams(["exampleRetainedSearchParam"]) to a parent root (for example, __root.tsx)
Create a search object in a route (for example, index.tsx) and keep the reference. It can be a global variable, or a variable that lives in the lifecycle of the component.
constsearchRef=useRef({id: "1"asconst});
Add that to a link
<Linkto="/post"search={searchRef.current}>
Change the search parameters to include "exampleRetainedSearchParam". Update it multiple times.
Log the search reference. The bug is that it now has exampleRetainedSearchParam with the value added to it on its first run.
This can break the page in some cases when that search param was not expected, and it breaks retainSearchParams itself.
See the example repo above for a full example.
Expected behavior
It should not mutate the search parameters object provided to the router.
Screenshots or Videos
Screen.Recording.2026-01-04.at.17.22.45.mov
Platform
Router / Start Version: 1.132.0
Additional context
I think having the same reference would be rare for React and Solid, where the props can get a different object each time, but other adapters with different prop behaviors might break with this.
Which project does this relate to?
Router Core, search middlewares: https://github.com/TanStack/router/blob/main/packages/router-core/src/searchMiddleware.ts
Describe the bug
The search middleware changes the search object. This can cause unexpected behavior when the search object is the same across multiple runs of a Link component.
This does not affect the use case where the search options are provided directly in the Link in React and Solid.
Your Example Website or App
https://github.com/benjavicente/router-mutable-search-repo
Steps to Reproduce the Bug or Issue
retainSearchParams(["exampleRetainedSearchParam"])to a parent root (for example,__root.tsx)index.tsx) and keep the reference. It can be a global variable, or a variable that lives in the lifecycle of the component."exampleRetainedSearchParam". Update it multiple times.exampleRetainedSearchParamwith the value added to it on its first run.This can break the page in some cases when that search param was not expected, and it breaks
retainSearchParamsitself.See the example repo above for a full example.
Expected behavior
It should not mutate the search parameters object provided to the router.
Screenshots or Videos
Screen.Recording.2026-01-04.at.17.22.45.mov
Platform
Additional context
I think having the same reference would be rare for React and Solid, where the props can get a different object each time, but other adapters with different prop behaviors might break with this.