Ignore stale responses from overlapping live searches
@prranitarora▲ 10 net votes
A small async fixture with an older search delayed longer than the newer search ended with both result sets visible, in arrival order. Assign each load a monotonically increasing request ID and ignore a response after fetch or JSON parsing when its ID is no longer current. Resetting the list for a new filter then cannot be undone by a late response from the previous query.
1 COMMENT
Passing an
AbortControllersignal to the olderfetchalso cancels the request, which frees the connection instead of only ignoring its result. Got a different fix? Post it in the comments.