Skip to content

(bug-fix): autocomplete should only refine on main search if submitted#6958

Merged
Haroenv merged 7 commits intomasterfrom
autocomplete-should-only-refine-on-main-search-if-submitted
Apr 10, 2026
Merged

(bug-fix): autocomplete should only refine on main search if submitted#6958
Haroenv merged 7 commits intomasterfrom
autocomplete-should-only-refine-on-main-search-if-submitted

Conversation

@afrencalg
Copy link
Copy Markdown
Contributor

Summary

In the React EXPERIMENTAL_Autocomplete widget, every keystroke in the search input was triggering 2 separate API calls, one on the parent index (via useSearchBox.refine) and one on the isolated autocomplete index (via useAutocomplete.refine). Since the autocomplete uses EXPERIMENTAL_isolated, these are two separate search lifecycles, resulting in duplicate searchClient.search() calls on every keystroke.

This change removes the redundant parent search call from the onChange handler so that typing only triggers 1 API call (the isolated autocomplete search). The parent index is still updated when the user submits (Enter key), selects a suggestion, or clears the input, matching the behavior of the instantsearch.js widget which already handled this correctly.

Result

Typing in the autocomplete input triggers 1 API call per keystroke instead of 2
Autocomplete suggestions still update live as you type
Parent search results update on submit/selection as expected

@codacy-production
Copy link
Copy Markdown

codacy-production bot commented Apr 9, 2026

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 15 complexity · 0 duplication

Metric Results
Complexity 15
Duplication 0

View in Codacy

TIP This summary will be updated as you push new changes. Give us feedback

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 9, 2026

More templates

algoliasearch-helper

npm i https://pkg.pr.new/algolia/instantsearch/algoliasearch-helper@6958

instantsearch-ui-components

npm i https://pkg.pr.new/algolia/instantsearch/instantsearch-ui-components@6958

instantsearch.css

npm i https://pkg.pr.new/algolia/instantsearch/instantsearch.css@6958

instantsearch.js

npm i https://pkg.pr.new/algolia/instantsearch/instantsearch.js@6958

react-instantsearch

npm i https://pkg.pr.new/algolia/instantsearch/react-instantsearch@6958

react-instantsearch-core

npm i https://pkg.pr.new/algolia/instantsearch/react-instantsearch-core@6958

react-instantsearch-nextjs

npm i https://pkg.pr.new/algolia/instantsearch/react-instantsearch-nextjs@6958

react-instantsearch-router-nextjs

npm i https://pkg.pr.new/algolia/instantsearch/react-instantsearch-router-nextjs@6958

vue-instantsearch

npm i https://pkg.pr.new/algolia/instantsearch/vue-instantsearch@6958

commit: 6e0a826

Copy link
Copy Markdown
Contributor

@Haroenv Haroenv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the fix works! Do you know why we did this originally, was it in the first merge already? we should also add tests to ensure the right searches happen. This can be in CTS normally

@Haroenv
Copy link
Copy Markdown
Contributor

Haroenv commented Apr 9, 2026

Screen.Recording.2026-04-09.at.09.34.49.mov

was this before already? if you refine and then go back to empty query it will show the refined query. Probably something to do with query || refinement that should take in account that the query can be nullish later than on init too.

EDIT: I see what happened, this was implemented in the POC but not the proper version: https://github.com/algolia/instantsearch/pull/6745/changes#r3056209902

@afrencalg
Copy link
Copy Markdown
Contributor Author

@Haroenv please check now :)

Copy link
Copy Markdown
Contributor

@Haroenv Haroenv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very good! there's another small edge case showing now, which is that refining with empty query doesn't seem to happen, is there a guard somewhere that doesn't refine if the query is falsy ''?

@Haroenv Haroenv merged commit 010e5a1 into master Apr 10, 2026
15 checks passed
@Haroenv Haroenv deleted the autocomplete-should-only-refine-on-main-search-if-submitted branch April 10, 2026 11:52
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.

2 participants