LESSON 07 / 9·2 min readIntermediate

How do I prevent stale search results?

Try code in the playground
01 Understand02 Recall03 Prepare

Understand the concept

Stale search results occur when requests finish in a different order from the user's inputs. A request for an older search can overwrite newer results unless the component checks which request is still relevant. Debouncing reduces request frequency but does not guarantee completion order.

Important ideas

  • A slow old request can finish after a newer request.

  • Cancel old requests where possible, or ignore results that no longer match the active request.

  • Debounce typing if appropriate, but still handle response ordering.

  • Track the active request or use cleanup to ignore an old result, and handle aborts differently from genuine user-facing failures.

Step-by-step example:

  1. The user searches for rea; request A begins.
  2. The user changes the search to react; request B begins.
  3. B finishes first, so the page shows results for react.
  4. A finishes later; ignore it because it belongs to an older search.
  5. Cancel old work when supported, and still protect the state update from stale results.
PAUSE & RECALL

Can you explain it without the notes?

How do I prevent stale search results?

Use your own words. Explain an example and one limitation before checking the explanation.

Check your explanation

Stale search results occur when requests finish in a different order from the user's inputs. A request for an older search can overwrite newer results unless the component checks which request is still relevant. Debouncing reduces request frequency but does not guarantee completion order.

CONNECT IT TO YOUR INTERVIEW

Turn this concept into a clear answer.

  • Describe the timeline of two searches and show why only the latest relevant response should update state.
Practice this concept
YOUR NEXT STEP

Keep connecting the ideas.

Next lesson: How should I secure and organize a frontend?

Adapted from 06_REACT_NEXTJS.md · “How do I prevent stale search results?”. Examples are study fragments; framework behavior can depend on your version.