Skip to content

fix: prevent stale search results from overwriting newer suggestions#111

Merged
Aditya8369 merged 1 commit into
Aditya8369:mainfrom
shivi14112007-create:fix/stale-search-results-race-condition
Jul 9, 2026
Merged

fix: prevent stale search results from overwriting newer suggestions#111
Aditya8369 merged 1 commit into
Aditya8369:mainfrom
shivi14112007-create:fix/stale-search-results-race-condition

Conversation

@shivi14112007-create

@shivi14112007-create shivi14112007-create commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Closes #110

handleInputChange in LocationSearch.jsx debounced 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 latestQueryRef that stamps the query associated with each debounced search as it fires. Before applying a result, the code checks whether latestQueryRef.current still 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.js to force out-of-order resolution:

  • Typed "Lon" (triggering the artificially slow request), then quickly continued typing to "London" before the first request resolved.
  • Before the fix: after ~3s, suggestions flipped back to stale "Lon" results.
  • After the fix: the late "Lon" response was correctly ignored, and suggestions stayed matched to "London".
  • Removed the temporary delay before committing this change.

@vercel

vercel Bot commented Jul 8, 2026

Copy link
Copy Markdown

@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.

@Aditya8369 Aditya8369 added the ECSoC26 Contributions considered under ECSoC'26 label Jul 9, 2026
@vercel

vercel Bot commented Jul 9, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
pollution-control-hub Ready Ready Preview, Comment Jul 9, 2026 4:53am

@Aditya8369 Aditya8369 merged commit 4f64740 into Aditya8369:main Jul 9, 2026
3 checks passed
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown

🎉 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:

  • ⭐ If you haven't already, consider giving the repo a star — it helps us grow.
  • 📢 Share your contribution on LinkedIn, Twitter, or wherever you hang out. You shipped open source!
  • 🔍 Browse other open issues if you want to keep contributing.

We really appreciate you taking the time. See you in the next PR! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ECSoC26-L1 ECSoC26 Contributions considered under ECSoC'26

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Race condition: stale search results can overwrite newer suggestions in LocationSearch

2 participants