← Back to incidents

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.

Intermediate14 min

Failure signals

The clues you start with

01

Results briefly jump back to an older query

02

Cached and network results both update the same results list

03

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.

Guided simulator

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

Log

Request order

The request for 'react' finishes after the request for 're', and both update the same results list.

Snippet

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);
Note

Observed behavior

A 250ms debounce reduced the number of requests, but the stale flash still appears on a slow network when you backspace quickly.

Overview