useSearch bug: renders 'undefined' in between re-renders
Describe the bug
I see is useSearch() re-renders the component on change with the following
- new updated value
- undefined
- new updated value
On a full refresh with query param this works as expected
- new updated value
Your Example Website or App
https://stackblitz.com/edit/tanstack-router-5lbt2p?file=src%2Fmain.tsx
Steps to Reproduce the Bug or Issue
From the repro stackblitz link
- goto dashboard
- invoice tab
- click on one of the invoice
- click show notes
- check console log
Expected behavior
similar to full refresh, once the useSearch renders an updated values, it shouldn't re-render with undefined and then render again with updated value
Screenshots or Videos
No response
Platform
- OS: [e.g. macOS, Windows, Linux]
- Browser: [e.g. Chrome, Safari, Firefox]
- Version: [e.g. v0.0.1-beta.266]
Additional context
link to discord discussion
I'm having trouble with the same issue. To be more precise, useSearch is not returning undefined, it's returning the previous search value. In the example above, if you click on "close notes", you'll see that search first returns an empty object as expected, then returns the previous {showNotes: true}, and then again empty object. I have a case where I'm watching search and syncing local state with search, and the intermediate stale search is breaking that.
Well that’s not good. I’ll fix this
Can't replicate in latest any more, so it seems it's fixed!