fix: prevent stale search results from overwriting newer suggestions#111
Merged
Aditya8369 merged 1 commit intoJul 9, 2026
Conversation
|
@shivi14112007-create is attempting to deploy a commit to the Aditya Mahajan's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
🎉 Your PR just got merged, @shivi14112007-create — thank you for contributing to Pollution Control Hub! Your work is now part of the project. Here's what to do next:
We really appreciate you taking the time. See you in the next PR! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #110
handleInputChangeinLocationSearch.jsxdebounced when a search fired, but had no mechanism to discard a result if a newer search had started before the older one resolved. Out-of-order network responses could cause stale suggestions to overwrite fresher ones.Change:
Added a
latestQueryRefthat stamps the query associated with each debounced search as it fires. Before applying a result, the code checks whetherlatestQueryRef.currentstill matches the query that request was for — if a newer search has started since, the stale result is silently dropped instead of applied.Testing:
Since the repo has no test framework set up yet (raised separately as its own issue), I verified manually by temporarily injecting an artificial 3s delay on a specific query in
geocodingService.jsto force out-of-order resolution: