Race Conditions & Request Ordering
Suppose a user searches for rea, then quickly changes the query to react. If the first request finishes after the second, a naive implementation can display stale results.
Cancellation is one solution. Another is assigning each request an identity and accepting a response only if it still matches the latest request. Data-fetching libraries often handle these concerns for you.
The broader principle is that asynchronous work can finish in a different order from the order in which it started. UI state must respect the logical ordering expected by the user.
Async Race
Key Takeaways
Completion order is not start order.
Cancel or ignore obsolete async work.
Treat request identity as part of correctness, not just performance.