Should parameter from search in navigate be passed by validateSearch? Bug?
#1489
Unanswered
carlosmfreitas2409
asked this question in
Q&A
Replies: 2 comments
|
Anything? |
0 replies
|
Why not just treat your https://stackblitz.com/edit/tanstack-router-rskfb7?file=src%2Froutes%2Findex.tsx We expect you to choose your search If you ABSOLUTELY have to use commas, then you could move this logic over to the |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Currently, the "property"
prevof search (navigate({ search: (prev) => prev })) goes through route search validation, but should it? Or should I not have the option of getting both the formatted and the raw one?Let's assume the following use case:
I need to send a query param where the data is an array, however, in order for the URL not to be crowded with percent encoding, I send it with commas and in the validate, I convert it to array (image 1), allowing me to have access to the array inside the
useSearch.And then in
navigateI need to send the raw data (image 2). However, in addition to break at this point becauseprevhas the output type, if I return the data fromprev, it will return the data already formatted, which will break the validation, since I expect a string in the input and not an array (image 3).Stackblitz: https://stackblitz.com/edit/tanstack-router-1h3gf5?file=src%2Froutes%2Findex.tsx
It's even strange. You can see that in the
handleSelectStatusesI'm passing statuses as a string (separated by comma) - that is, it will pass through the validator after the search is executed. And it's not giving any TS errors (which is correct).But if you look at the
handleSelectGroupByfunction, you'll see that it's giving a TS error, becauseprev.statusesis astring[], butsearchfn return needs to receive only astring. So, it is incorrect forprevto pass through the validator first (since I wouldn't be able to pass its data to the return).I found this old issue #799, which says the opposite of what I'm asking. So, apparently, it was like that in the past. And so I don't know if this is a bug or not, as I haven't seen any reason good or a comprehensive example of why it should go through validation.
Or have both options, depending on whether I pass
SearchSchemaInput.Thanks!
All reactions