Skip to content

fix: fire onSearchComplete before onSelect when auto-selecting#870

Merged
tkirda merged 1 commit into
masterfrom
fix/onsearchcomplete-ordering
May 20, 2026
Merged

fix: fire onSearchComplete before onSelect when auto-selecting#870
tkirda merged 1 commit into
masterfrom
fix/onsearchcomplete-ordering

Conversation

@tkirda
Copy link
Copy Markdown
Member

@tkirda tkirda commented May 20, 2026

Closes #852.

Summary

When a search returns a single suggestion whose value exactly matches the current query and triggerSelectOnValidInput is true (the default), suggest() calls select(0) which fires onSelect. Previously, all three response paths (function lookup, cached/local, ajax) fired onSearchComplete after suggest(), so consumers received the events in the wrong order — onSelect before onSearchComplete — making any cleanup logic in onSearchComplete clobber state set during onSelect (the original report).

The fix moves onSearchComplete ahead of suggest() (and ahead of processResponse() on the ajax path, which contains suggest()) so the events fire in the natural order: search-complete, then any resulting select.

Test plan

  • New spec Autocomplete event ordering > fires onSearchComplete before onSelect when a single match auto-selects — fails on master, passes with the fix.
  • Full suite green locally (npm test — 34 / 34).
  • npm run lint && npm run format:check && npm run typecheck && npm run build all green.

🤖 Generated with Claude Code

When a search returns a single suggestion whose value exactly matches
the current query and `triggerSelectOnValidInput` is true (the default),
`suggest()` calls `select(0)` which fires `onSelect`. Previously, the
three response paths (function lookup, cached/local, ajax) all fired
`onSearchComplete` after `suggest()`, so consumers received the events
in the wrong order — onSelect before onSearchComplete — making any
cleanup logic in onSearchComplete clobber state set during onSelect.

Move `onSearchComplete` ahead of `suggest()` (and `processResponse()`
on the ajax path, which contains `suggest()`) so the events fire in
the natural order: search-complete, then any resulting select.

Closes #852.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@tkirda tkirda merged commit eace506 into master May 20, 2026
1 check passed
@tkirda tkirda deleted the fix/onsearchcomplete-ordering branch May 20, 2026 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

onSearchComplete triggers after onSelect when only one match exists

2 participants