-
-
Notifications
You must be signed in to change notification settings - Fork 213
fix: Use TanStack Router default stringify for search params #1128
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
base: next
Are you sure you want to change the base?
Conversation
@gensmusic is attempting to deploy a commit to the 47ng Team on Vercel. A member of the Team first needs to authorize it. |
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Thanks, that's a better approach indeed. However, it would not work for folks who have customised their (de)serialisation layer (say, to encode all search params as base64, or using jsurl2): One way we could support this is to pass the Now this would be hard to test though, as it's a global config on the router, and the e2e tests are asserting on the default SerDe layer. For the record, the previous approach wouldn't have worked with a custom SerDe either, so there's that.. 😅 |
@franky47 I just add the support for custom stringifySearchWith |
Please ignore the latest commit for now, it's far more complicated than I thought! |
This change has been tested locally and works as expected. Parsing search paramsInside TanStack Router, However, nuqs expects Synchronizing search paramsWhen nuqs updates the search params, the If there is a custom If no custom stringifySearchWith is provided, we simply fall back to the default behavior, which is compatible with nuqs’ expectations.
|
@franky47 If you have a moment, I’d love your review on this PR. |
Thanks, I'll give it a try tonight. |
commit: |
// Use TSR's default stringify to convert search object → URLSearchParams. | ||
// This avoids issues where arrays/objects were previously flattened | ||
// into invalid values like "[object Object]". | ||
return new URLSearchParams(defaultStringifySearch(search)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked at this PR in the context of multi-parsers (#1134), but they completely stop working in TanStack Router when I apply the changes from this PR.
The problem seems to be this call to defaultStringifySearch
. For example, if search
is:
{
test: [1,2]
}
The call to defaultStringifySearch
turns that into "?test=%5B1%2C2%5D"
, which gives us searchParams
with a size of one where the value for test
is the string [1,2]
.
This wasn’t the case with the previous implementation, where searchParams
would correctly have a size of two.
Fix TanStack Router search params serialization
Summary
This PR fixes #1127 an issue in the Nuqs TanStack Router adapter where search params
containing objects or arrays were being incorrectly serialized into
[object Object]
.Changes
stringifySearchWith(JSON.stringify)
from TanStack Router.Notes
Fixes #1127.