T
TanStack8mo ago
flat-fuchsia

Is it normal that the search params are stripped when they don't pass the validation?

Quick question : is it normal that tanstack/router removes the search params when they don't pass the validation? I thought I was going crazy but this actually reproduces quite easily on the stackblitz examples. For instance with this:
validateSearch: z.object({
foo: z.number(),
}),
validateSearch: z.object({
foo: z.number(),
}),
when I navigate to the route with ?foo=abc it displays the error component with
[
{
"code": "invalid_type",
"expected": "number",
"received": "undefined",
"path": [
"foo"
],
"message": "Required"
}
]
[
{
"code": "invalid_type",
"expected": "number",
"received": "undefined",
"path": [
"foo"
],
"message": "Required"
}
]
We can log more stuff and we see that they initially fail with a type error, but then the validation runs again without the search params and fails with a "required" error. Repro: just navigate to the /about route https://stackblitz.com/edit/tanstack-router-io5722nf?file=src%2Froutes%2Fabout.tsx,src%2Froutes%2F__root.tsx&preset=node I had previously opened an issue where I thought this stripping behavior was due being combined with a throw redirect() (https://github.com/TanStack/router/issues/3120) but it looks like it just happens whenever the validation fails at all. From the user's perspective, this is probably not much of an issue, they'd get some fallback behavior either way. But from a dev's pov, it means what we'll see on Sentry (or other ways of seeing the error) is that the search params were fully missing, when in reality they were there but wrong, which could make debugging quite confusing.
2 Replies
useful-bronze
useful-bronze8mo ago
probably a bug
flat-fuchsia
flat-fuchsiaOP8mo ago
Thanks, I'll file an issue

Did you find this page helpful?