fix: fire onSearchComplete before onSelect when auto-selecting#870
Merged
Conversation
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>
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 #852.
Summary
When a search returns a single suggestion whose value exactly matches the current query and
triggerSelectOnValidInputis true (the default),suggest()callsselect(0)which firesonSelect. Previously, all three response paths (function lookup, cached/local, ajax) firedonSearchCompleteaftersuggest(), so consumers received the events in the wrong order —onSelectbeforeonSearchComplete— making any cleanup logic inonSearchCompleteclobber state set duringonSelect(the original report).The fix moves
onSearchCompleteahead ofsuggest()(and ahead ofprocessResponse()on the ajax path, which containssuggest()) so the events fire in the natural order: search-complete, then any resulting select.Test plan
Autocomplete event ordering > fires onSearchComplete before onSelect when a single match auto-selects— fails onmaster, passes with the fix.npm test— 34 / 34).npm run lint && npm run format:check && npm run typecheck && npm run buildall green.🤖 Generated with Claude Code