An old search request finishes after a newer one. How do you stop it replacing the results?
After this you can answer: An old search request finishes after a newer one. How do you stop it replacing the results?
Say it in 30 seconds
Section titled “Say it in 30 seconds”The deeper answer
Section titled “The deeper answer”Typing creates several possible races: a timer for old text, an in-flight request for old filters, and a slower response arriving out of order. The hook clears the previous debounce timer on every text change, trims the settled text and uses infinite queries with a bounded page size of fifty.
Query keys isolate different inputs. This is stronger than keeping one result variable and assigning every response to it. Abort-on-unmount is enabled, but a cancellation signal cannot reverse database work already finished or guarantee that a remote server stops executing.
The hook deliberately keeps previous data while the next query loads and exposes whether the typed text differs from the debounced query. This avoids flicker, but callers must label transitions honestly and avoid treating placeholder pages as confirmed results for new filters. A useful test delays the old response, changes the input, then verifies that the new search remains selected.
Counter-questions
Section titled “Counter-questions”Does debounce guarantee correct ordering?
What if the server ignores cancellation?
Why retain old results?
Where in MiniTickets
Section titled “Where in MiniTickets”Read Search pagination, then inspect the web-app piece →.
apps/web/src/features/events/hooks/use-event-search.ts → useEventSearchRead this book online: https://book.theversehub.in/