fix: discard stale search results when a newer query supersedes them #468

Merged
guettlibot merged 1 commits from issue-467-fix-search-stale-results into main 2026-06-06 08:32:38 +00:00
1 Commits
Author SHA1 Message Date
Thomas SharedInboxandClaude Sonnet 4.6 727f10462c fix: discard stale search results when a newer query supersedes them
Concurrent IMAP searches were triggered on every keystroke via
`unawaited(_runSearch(...))`. A slower earlier search completing after
a faster later search would overwrite `_searchResults` with stale data,
causing the wrong email to open when tapping a result.

Fix: add a `_searchGeneration` counter incremented on each search start;
results are only applied when the generation matches (i.e. no newer
search was started since). Clearing the query also resets state
immediately without waiting for any in-flight request.

Added two widget tests:
- tapping the first of multiple search results opens the correct email
- stale results from a slower concurrent search are discarded

Fixes #467

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-06 09:33:10 +02:00