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

Default search becomes empty object when used in search #2799

Open
OwenVey opened this issue Nov 18, 2024 · 0 comments
Open

Default search becomes empty object when used in search #2799

OwenVey opened this issue Nov 18, 2024 · 0 comments

Comments

@OwenVey
Copy link

OwenVey commented Nov 18, 2024

Which project does this relate to?

Router

Describe the bug

I am using both the stripSearchParams and retainSearchParams middlewares to strip default values from the query params as well as removing any parameters not related to that route. This works as expected as shown in the reproduction URL below but the moment I use my DefaultSearch object in a Link like so:

<Link to={Route.fullPath} search={DefaultSearch}>
  Clear Search
</Link>

the DefaultSearch object itself becomes {} which then causes problems with the middlewares.

My guess is there is a bug somewhere where the object being passed to search is being overwritten.

Your Example Website or App

https://stackblitz.com/edit/tanstack-router-fyxlu6?file=src%2Froutes%2F__root.tsx

Steps to Reproduce the Bug or Issue

  1. Open reproduction link and click the "Open Preview in new tab" button in the top right corner (so that we can see search params in URL)
  2. Notice that when switching between the "Home" and "About" tabs, the middlewares are working as expected and the DefaultSearch objects are being displayed as expected.
  3. Go to the __root.tsx file and uncomment lines 20 and 29
  4. Switch between the two tabs and notice that the DefaultSearch objects are displayed as {} and the search middlewards no longer function as expected.

Expected behavior

I expect my DefaultSearch object be unmodified and log out as originally created but I am seeing it log as an empty object when using my DefaultSearch in a <Link>'s serach.

Screenshots or Videos

Image

Platform

  • OS: Windows
  • Browser: Chrome
  • Version: 131.0.6778.70 (Official Build) (arm64)

Additional context

Mentioned in the TanStack Discord here: https://discord.com/channels/719702312431386674/1306270495016095847/1306442814875242548

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