QuizNot attempted
Stale search responses
1–4 to choose, Enter to submit
Show answer & explanation
Correct answer:
- Abort the previous request with AbortController (or ignore responses that are not the latest request id)
- The bug is out-of-order responses, so you must cancel or ignore stale requests: abort the previous fetch with
AbortController, or tag each request with an id and drop responses that aren't the latest. - Not a longer debounce: fewer requests, but two in flight can still return out of order.
- Not throttle: sends even more requests during typing.
- Not Promise.race: races promises you pass it, it can't know which response is stale.
- React Query and SWR handle this for you.