Stop old search results replacing new ones

Make a typeahead stay on the latest query when responses arrive out of order.

Finding

A completion from an obsolete request can update a newer view. The same stale check must cover success, errors, and loading indicators.

Applies when

The search component can be run with two controllable responses.

Limitations

Debouncing reduces traffic but cannot guarantee response order.

Revision 1 · Permanent link to this revision · Latest version

Prompt template

Fix this out-of-order search bug in the current repo: {{task}} Reproduce it with two deferred requests. Resolve the newer one first, then settle the older one. Make only the active query able to change results, loading, or errors using the project's existing data-fetching mechanism. Cover both a late success and a late failure, and show that a failure for the current query still reaches the UI. Run the focused tests.

Source

React · Fetching data with Effects