Results briefly jump back to an older query
JavaScript incident
Latest query loses to stale search results
Cached results and slower network results both update the same list, so an older query can briefly show up again.
Failure signals
The clues you start with
Cached and network results both update the same results list
Debounce reduced traffic, but the stale flash is still there
Overview
What failed in production?
Start by making the bug legible: what the user saw, why it mattered, and what the product was doing underneath.
Symptom
A user types 'react', quickly deletes back to 're', and briefly sees old 'react' results again.
User impact
Search feels unreliable because the interface does not reflect the most recent intent.
Environment
Plain JavaScript search with a 250ms debounce, a small cache of recent queries, and one shared results list used by both cached and network results.
Evidence pack
What you can inspect before answering
Request order
The request for 'react' finishes after the request for 're', and both update the same results list.
Current cache + response handling
const cached = cache.get(query);
if (cached) {
resultsStore.items = cached.items;
renderResults(resultsStore.items);
}
const res = await fetch(`/api/search?q=${query}`);
const data = await res.json();
resultsStore.items = data.items;
renderResults(resultsStore.items);Observed behavior
A 250ms debounce reduced the number of requests, but the stale flash still appears on a slow network when you backspace quickly.