-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Ignore old requests in useSearch hook
Previously, search-as-you-type could result in a scenario where the results displayed didn't match the user's search. This occurred because of a bug in the `pending.current` logic that delayed subsequent searches and called `fetchMore()` after the pending query completed. The issue is that `fetchMore()` runs in the closure of the previous search, so it actually just repeated the old search instead of performing a new search with new variables. This PR addresses this issue by removing the `pending.current` check, firing all requests when they come in. When requests complete, they are ignored if they are not the most-recently triggered. Urql doesn't support AbortController, so we can't cancel the in-progress requests. If necessary, we can increase the debounce delay to reduce load. The infinite scroll controller tends to trigger multiple duplicate requests, so these are also being filtered out before sending using similar logic.
- Loading branch information
Showing
1 changed file
with
78 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters