-
-
Notifications
You must be signed in to change notification settings - Fork 637
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
Search parameters get overridden on page load #2290
Comments
Just to clarify, I tested to see if this bug can be reproduced on Tanstack Router and it cannot be reproduced. This issue only occurs with Tanstack Start. |
working example for router: https://stackblitz.com/edit/tanstack-router-f9yax9?file=src%2Froutes%2Findex.tsx&preset=node |
I also found this bug yesterday and experienced the search params simply being deleted completely on page load/reload. The errors described here happen both when using the dev server and when using the production build ( Just go to I've also found that when using a import { createFileRoute, Link } from '@tanstack/react-router';
import { z } from 'zod';
export const Route = createFileRoute('/')({
component: HomeComponent,
validateSearch: z.object({
addBy: z.number().optional(),
}),
});
function HomeComponent() {
const search = Route.useSearch();
const { addBy = 0 } = search;
return (
<div className="p-2">
<h3>Welcome Home!</h3>
<pre>{JSON.stringify(search, null, 2)}</pre>
<Link
to={Route.to}
activeOptions={{
includeSearch: true,
}}
from="/"
// the `?` is required here because prev is not always defined for some reason, which also seems to me like a bug
search={(prev) => ({ addBy: (prev.addBy ?? 1) + 1 })}
preload="intent"
>
Increase addBy ({addBy})
</Link>
</div>
);
} tanstack.start.search.bugs.movThere also seems to be a Typescript bug when using the
|
Which project does this relate to?
Start
Describe the bug
When I navigate to
/
, it is expected that I get redirected to/?step=a
- this works as expected.However, when I navigate to
/?step=b
, I get redirected to/
, and then subsequently get redirected to/?step=a
.No errors get thrown when I navigate to to
/?step=b
, which leads me to assume that the search parameters were properly validated by the Zod schema undervalidateSearch
.It is expected that when I navigate to
/?step=b
, that I would stay on/?step=b
without being redirected to/
and subsequently/?step=a
.This bug occurs irrespective of this redirect logic being placed in:
beforeLoad
,loader
, orcomponent
with auseEffect
overRoute.useSearch({ select: ({step}) => step })
Your Example Website or App
https://stackblitz.com/edit/tanstack-router-txrzyl?file=app%2Froutes%2Findex.tsx
Steps to Reproduce the Bug or Issue
Open Preview in new tab
and pressConnect to project
- notice that you get automatically redirected from/
to/?step=a
./?step=b
.Expected behavior
That I stay on
/?step=b
as it conforms to the Zod schema provided undervalidateSearch
.Screenshots or Videos
No response
Platform
Additional context
No response
The text was updated successfully, but these errors were encountered: