The Real Fullstack

The Stale Search Results

The user typed “kafka”. The page shows results for “kaf”. Nobody typed “kaf” last.

Ingénieur8 minSimulateur de chronologieDéfi de code
angularrxjstypescriptreacthttp

Ce défi n'est pas encore traduit en Français. Vous lisez la version anglaise.

Mission:Reproduce the race between overlapping requests, then pick a strategy that always shows results for the latest query, quickly, without hammering the API.Contexte · Objectifs d'apprentissage ▾

Larkspur's event search sends a request on every keystroke. The backend is usually fast, but some short queries are expensive and slow. Users report that results sometimes “jump back” to an older search after a moment.

Mission: Reproduce the race between overlapping requests, then pick a strategy that always shows results for the latest query, quickly, without hammering the API.

Objectifs d'apprentissage

  • Explain why responses can arrive out of order.
  • Compare mergeMap, concatMap, exhaustMap and switchMap.
  • Cancel stale requests and debounce input.
SimulationSimulé

Lancez la simulation pour voir la sortie.

Lancer la simulation
readonly results = toSignal(  this.query.valueChanges.pipe(    mergeMap((q) => this.api.search(q)),   // every response is rendered, in arrival order  ), { initialValue: [] });

Simplification

Four keystrokes with fixed latencies. Real latencies vary, which makes the race intermittent and hard to reproduce. Modèle pédagogique — les chiffres illustrent un comportement, ce ne sont pas des benchmarks.

Concepts

Utile avant celui-ci

Défis liés

Références