Skip to content

Conversation

@dhayab
Copy link
Member

@dhayab dhayab commented Oct 29, 2025

Summary

This PR adds two top-level parameters to autocomplete:

  • getSearchPageURL to provide an URL to navigate to when autocomplete is not part of the search page
  • onSelect to provide a global onSelect, making the per-index one optional, and defaulted to a method that handles redirection to the search page if necessary

The order is the following:

  1. if the index / suggestion index provides getURL() → navigate to url
  2. if autocomplete is not part of the search page and getSearchPageURL() exists → navigate to url
  3. refine using getQuery()

FX-3538

@codesandbox-ci
Copy link

codesandbox-ci bot commented Oct 29, 2025

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit cf22472:

Sandbox Source
example-instantsearch-getting-started Configuration
example-react-instantsearch-getting-started Configuration
example-react-instantsearch-next-app-dir-example Configuration
example-react-instantsearch-next-routing-example Configuration
example-vue-instantsearch-getting-started Configuration

@dhayab dhayab marked this pull request as ready for review October 29, 2025 15:19
@dhayab
Copy link
Member Author

dhayab commented Oct 29, 2025

I'll update the API reference, and will add tests after #6772 is merged.

Copy link
Contributor

@shaejaz shaejaz left a comment

Choose a reason for hiding this comment

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

lgtm, couple of minor comments.

Comment on lines +186 to +187
const indexUiState =
instantSearchInstance.getUiState()[targetIndex!.getIndexId()];
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a possibility this can cause an indexing error?

Copy link
Member Author

Choose a reason for hiding this comment

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

targetIndex is at least the mainIndex (the parent of the isolated index of an autocomplete), so it should not cause an error. It just is typed as potentially undefined because the renderState needs to be declared before we have access to instantSearchInstance.

Comment on lines +133 to +138
const isSearchPage = useMemo(
() =>
typeof indexRenderState.hits !== 'undefined' ||
typeof indexRenderState.infiniteHits !== 'undefined',
[indexRenderState]
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it not possible to also get this info from the targetIndex in react?

Copy link
Member Author

Choose a reason for hiding this comment

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

For now this is defined in the JS widget, and retrieving the index instance in React is not as easy (useIndexContext() is not publicly exported for instance).

Could be worth having it returned by the connector in a future update though.

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.

3 participants