The Vanishing Search Results — JavaScript Bug Hunt

The search box on Atlas Docs shows results for a query the user typed three keystrokes ago.

  • Language: JavaScript
  • Layer: Frontend
  • Difficulty: Easy
  • Modelled on: Typeahead search UIs
  • Visible tests: in-order responses render normally; stale response must not overwrite a newer one; the newest request always applies
  • Reward: 50 XP for a complete fix

Briefing

The search box on Atlas Docs shows results for a query the user typed three keystrokes ago. Fast responses for old queries are overwriting slow responses for new ones.

The UI pipeline and the mock search service are locked. The race-guard logic in requestTracker.js is where the bug lives.

Bug report

BUG-1188 · Priority: High · Reported by: design QA

Type "re", then quickly "react". The list flashes the correct results, then snaps BACK to the results for "re".

The tracker is supposed to give every request an increasing id, and only let the response through if it belongs to the LATEST request.

Logs

[search] issued id=1 q="re"
[search] issued id=2 q="react"
[search] applied id=2 q="react"   <- correct
[search] applied id=1 q="re"      <- stale overwrite!

The code as shipped

src/search/requestTracker.js (editable)

// Guards against out-of-order async responses.
var latestId = 0;

exports.nextRequestId = function () {
  latestId = latestId + 1;
  return latestId;
};

// Should return true only for the response belonging to the newest request.
exports.shouldApply = function (responseId) {
  return responseId <= latestId;
};

exports.reset = function () {
  latestId = 0;
};

Read-only context: src/search/searchService.js, src/search/ui.js.

Open the hunt to edit the files, run the visible tests and submit against the hidden ones. More JavaScript bug hunts.