Skip to content
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

stringifySearchWith does not call stringify method on strings #3254

Open
levrik opened this issue Jan 27, 2025 · 0 comments
Open

stringifySearchWith does not call stringify method on strings #3254

levrik opened this issue Jan 27, 2025 · 0 comments

Comments

@levrik
Copy link
Contributor

levrik commented Jan 27, 2025

Which project does this relate to?

Router

Describe the bug

When using stringifySearchWith as stringifySearch option on the router instance with just the first argument supplied, strings do not get passed to the stringify method if not given a 2nd undocumented (https://tanstack.com/router/latest/docs/framework/react/guide/custom-search-param-serialization) parse method. By default JSON.parse is getting passed in there which results in strings only containing numbers to be encoded as "123" instead of just 123. A few weeks ago I supplied a custom stringifySearchWith to simply support encoding Set instances as well. This changed the behavior of how strings are encoded which in the end led to numeric string params to be ignored completely as I had a Zod validator defined with .string().optional().catch(undefined). Removing the .catch(undefined) revealed that it was receiving a number instead of a string.

Your Example Website or App

https://stackblitz.com/edit/github-qmrnwt4n?file=src%2Fmain.tsx

Steps to Reproduce the Bug or Issue

  1. Click "Add numeric search param"
  2. It crashes
  3. Remove stringifySearch from router and reload
  4. Click "Add numeric search param" again
  5. It works as expected

Expected behavior

Difficult to say. I saw that this 2nd parse argument was introduced in #654 but I don't really understand the background. At least this 2nd parameter should get documented or if not given, stringify should still be called?

Screenshots or Videos

TanStack.Router.Stringify.Search.mp4

Platform

  • OS: macOS
  • Browser: Edge
  • Version: 1.95.3

Additional context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant