`stringifySearchWith` does not call `stringify` method on strings
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 15.1k
- Forks
- 1.9k
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 143
Description
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
- Click "Add numeric search param"
- It crashes
- Remove
stringifySearchfrom router and reload - Click "Add numeric search param" again
- It works as expected
Expected behavior
Difficult to say. I saw that this 2nd parse argument was introduced in https://github.com/TanStack/router/issues/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
https://github.com/user-attachments/assets/ad46d899-d078-4ee2-96be-2a4c1e7d8c24
Platform
- OS: macOS
- Browser: Edge
- Version: 1.95.3
Additional context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with src/main.tsx in the linked StackBlitz and inspect the router's stringifySearchWith/stringifySearch configuration, then compare it with the default router behavior. Confirm the intended handling of numeric strings and whether the missing parse argument should be documented or change the serialization behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- frontend, search, web-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100