Numeric search parameters wrongly parsed and wrapped with quotes
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
The problem is that Router interprets Strings that look like a Number as Numbers at some point.
This behavior introduces 2 major issues:
- Numeric strings wrapped with double quotes — they shouldn't.
- If the numbers (that I expect to read as strings in my schema) are too large — they are modified.
So when I will pass &numericString=723421968459640832 to URL it will be transformed twice:
723421968459640832became723421968459640800(since it's too big for Number)- And it will be wrapped with
""and became&numericString="723421968459640800"
And the code is here — https://github.com/isnifer/tanstack-issue-537/blob/master/src/routes/issue.tsx
And yes I see your response here https://github.com/TanStack/router/discussions/989#discussioncomment-8125891 to transform big numbers to add double quotes, but c'mon, it should not be double quotes for numeric strings at all.
UPD: I've added a second page with the same Zod schema where I need to parse z.coerce.string() value from params – and it just works. No double quotes, no transformation URL => number => string. And added example with EXPECTED issue of casting from string to number (z.coerce.number()) to show the difference.
Your Example Website or App
https://tsr-issue-537.netlify.app
Steps to Reproduce the Bug or Issue
- Go to site
- Click to link on top
- Watch to search parameters in URL
- Read steps on that page
Expected behavior
As a user, I expected — numeric parameters even expected as strings would NOT be wrapped with double quotes and would NOT parsed after page transition. Since HUGE numbers will change their values to unpredictable like 723421968459640832 became 723421968459640800 in the provided example.
Screenshots or Videos
I recorded an example and made it slow to 0.25x, you can see how the Router transforms the URL.
You can find out on the 00:08 how it makes these 2 changes.
https://github.com/user-attachments/assets/55d990ae-a286-4ee4-aa57-34f90668d843
Platform
- Router / Start Version: 1.132.0
- OS: macOS
- Browser: Chrome
- Browser Version: 144.0.7559.4 beta (arm64)
- Bundler: vite
- Bundler Version: ^7.1.7
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
Use the linked reproduction in src/routes/issue.tsx and compare the URL before and after the page transition. Trace Router’s search-parameter parsing and serialization path; done means numeric-looking values remain exact strings without added quotes or precision loss, while explicitly coerced numeric values still behave as expected.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend, web-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100