Learning center

Search shows results for an earlier query: prove the responses arrived out of order

When a search box shows results for an earlier query, the page probably displayed the last response to arrive instead of the one for the latest query. The Network panel's waterfall shows whether the responses crossed, and their payloads show which one the page displayed.

Two causes that show the same screen#

Cause A: responses arrived out of orderCause B: the server answered the latest query wrongly
WaterfallAn earlier query's request finishes after the latest query's requestAny order: crossed responses do no harm when the page ignores stale ones
The results on screenMatch an earlier request's responseMatch the latest request's response
The latest request's responseCorrect results for the latest queryResults that do not match its query
Typing speedAppears when typing quickly, rarely when typing slowlyAppears however the query is entered
Where the fix goesThe page: ignore or cancel stale responsesThe search service

The deciding observation is which response the displayed results came from, together with whether the latest response was correct. Crossed finish times in the waterfall make Cause A possible; they do not establish it, because the same crossing appears in a page that ignores stale responses while the server answers the latest query wrongly.

Reproduced in Chromium#

A local search page fetched /search?q=… on every keystroke and wrote each response into the results list. The test server answered ap after 900 milliseconds and app after 50 milliseconds, imitating a slow and a fast query. Typing app produced:

GET /search?q=a      started 0 ms     finished ~10 ms
GET /search?q=ap     started ~100 ms  finished ~1000 ms
GET /search?q=app    started ~200 ms  finished ~250 ms

input: app
shown: ap-1, ap-2

The times are approximate: they follow from the 100-millisecond typing delay and the server's configured delays. The app response arrived first and was displayed, then the slower ap response arrived and replaced it. The box says app; the list shows ap-1, ap-2, which is the ap response's payload. The app response held the correct results for app, which rules out Cause B.

Record the ordering#

  1. Open the Network panel and filter for the search endpoint.
  2. Type the query at the speed that produces the bug.
  3. Look at the Waterfall column. Hover a bar to see when the request was queued, started and finished. Network timing phases
  4. Select each request and read its Payload for the query and Response for the results.

A screenshot of the waterfall with the request URLs visible shows the crossing, but not which response the page displayed. Add the query and the first result of each response in text, and the results on screen, so the receiver can match them.

If you cannot reproduce by typing, use the Network panel's throttling to slow every request. Slower requests widen the window in which responses can cross. Network throttling

Worked example: a customer lookup that shows the wrong account#

This example is fictional. A support agent types a customer's email address into a lookup box and sometimes opens the wrong account. The box shows dana@example.test; the account card belongs to dan@example.test.

The waterfall showed one lookup per character. The request for dan took 1.2 seconds because it matched many accounts; the agent finished typing the rest of the address within a second, and the request for the full address took 80 milliseconds. The dan response finished last. Its response listed dan@example.test first, and the page opened that account. The full address's response listed dana@example.test, so the server had answered the latest query correctly.

The report said: the lookup sends one request per keystroke and renders whichever response arrives last. A slow prefix query can finish after the full address and replace its result. In this recording, dan finished about 0.3 seconds after dana@example.test. That meant an agent could act on the wrong customer's account.

The usual fixes#

The page can cancel the previous request when a new one starts, using an AbortController, or can tag each request and ignore any response that is not for the current query. Debouncing the input reduces the number of requests but does not prevent a slow one from finishing last. AbortController · AbortSignal

When cancellation is in place, the Network panel shows the superseded requests as (canceled), which is expected. See requests with no status.

What to put in the report#

  • The query in the box and the query the results belong to.
  • The start and finish times of each request, or a waterfall screenshot with URLs.
  • The response the displayed results match.
  • The latest request's response, to show whether it was correct.
  • How fast you typed, and whether throttling was on.

Questions#

Is this only a search box problem?

No. Any view that refreshes from requests started by user input can show it: filters, tabs that load data, pagination, and autosave status. The test is the same: compare start order with finish order, then match what is on screen to a response.

The server is fast. Can this still happen?

Yes. Caches, network conditions and query cost vary per request. A single slow response is enough, which is why the bug often appears only for some users or some queries.

Can a service worker or cache cause it?

A cache can make the later request finish faster than the earlier one, which creates the same crossing. When the screen still matches the earlier response, the fix belongs in the page.

Return to the method for browser bug reports for the other symptoms in this collection.

One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. Eligibility and fair-use terms.

Start free with GitHub

Related reading