Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

react-instantsearch doesn't support algolia v5 #6426

Open
1 task done
TheOrcDev opened this issue Nov 8, 2024 · 3 comments
Open
1 task done

react-instantsearch doesn't support algolia v5 #6426

TheOrcDev opened this issue Nov 8, 2024 · 3 comments
Labels
Library: React InstantSearch ≥ 7 Issues in any of the react-instantsearch@7 packages (formerly named react-instantsearch-hooks)

Comments

@TheOrcDev
Copy link

🐛 Current behavior

I upgraded JavaScript API Client to version 5.13.0 successfully, but it is not compatible with InstantSearch component from react-instantsearch anymore.

This is the code:

import { searchClient as algoliaSearch } from "@algolia/client-search";

import { Configure, InstantSearch } from "react-instantsearch";

...

 <InstantSearch
      searchClient={searchClient} <------- here is the problem
      indexName={indexName}
      initialUiState={initialUiState ?? undefined}
    >
      <Configure
        aroundRadius={"all"}
        hitsPerPage={80}
        facetingAfterDistinct={true}
      />
      {children}
</InstantSearch>

The error is type related saying is not assignable to type 'SearchClient'

Is react-instantsearch going to be updated soon to support algolia v5?

🔍 Steps to reproduce

  1. Install latest algolia
  2. Install latest react-instantsearch
  3. Try to use it

Live reproduction

https://www.algolia.com/doc/libraries/javascript/v5/upgrade

💭 Expected behavior

InstantSearch component shouldn't give any errors.

Package version

algoliasearch 5.13.0, react-instantsearch 7.13.7

Operating system

Mac OS 15.0.1

Browser

Chrome

Code of Conduct

  • I agree to follow this project's Code of Conduct
@TheOrcDev TheOrcDev added the triage Issues to be categorized by the team label Nov 8, 2024
@dhayab
Copy link
Member

dhayab commented Nov 8, 2024

Hi, InstantSearch is typed to expect the API client coming from algoliasearch or algoliasearch/lite, not from the package you used. You should be able to switch to one of those imports with no impact on your codebase:

import { liteClient as algoliasearch } from 'algoliasearch/lite';
// or
import { algoliasearch } from 'algoliasearch';

@dhayab dhayab added Library: React InstantSearch ≥ 7 Issues in any of the react-instantsearch@7 packages (formerly named react-instantsearch-hooks) and removed triage Issues to be categorized by the team labels Nov 8, 2024
@TheOrcDev
Copy link
Author

Hi, InstantSearch is typed to expect the API client coming from algoliasearch or algoliasearch/lite, not from the package you used. You should be able to switch to one of those imports with no impact on your codebase:

import { liteClient as algoliasearch } from 'algoliasearch/lite';
// or
import { algoliasearch } from 'algoliasearch';

Thanks for answering so quickly! Tried that one already. Seems like it's working, but in both cases InstantSearch is still giving type errors. I'll copy you the entire thing here.

Type '{ transporter: Transporter; appId: string; clearCache(): Promise<void>; readonly _ua: string; addAlgoliaAgent(segment: string, version?: string | undefined): void; ... 5 more ...; search<T>(searchMethodParams: SearchMethodParams | LegacySearchMethodProps, requestOptions?: RequestOptions | undefined): Promise<...>; }' is not assignable to type 'SearchClient'.
  Types of property 'search' are incompatible.
    Type '<T>(searchMethodParams: SearchMethodParams | LegacySearchMethodProps, requestOptions?: RequestOptions | undefined) => Promise<...>' is not assignable to type '<T>(requests: { indexName: string; params: SearchOptions; }[]) => Promise<MultipleQueriesResponse<T>>'.
      Types of parameters 'searchMethodParams' and 'requests' are incompatible.
        Type '{ indexName: string; params: SearchOptions; }[]' is not assignable to type 'SearchMethodParams | LegacySearchMethodProps'.
          Type '{ indexName: string; params: SearchOptions; }[]' is not assignable to type 'LegacySearchMethodProps'.
            Type '{ indexName: string; params: SearchOptions; }' is not assignable to type 'LegacySearchQuery'.
              Type '{ indexName: string; params: SearchOptions; }' is not assignable to type 'LegacySearchForHits'.
                Type '{ indexName: string; params: SearchOptions; }' is not assignable to type 'LegacySearchParams'.
                  Types of property 'params' are incompatible.
                    Type 'SearchOptions' is not assignable to type 'SearchParamsObject'.
                      Type 'SearchOptions' is not assignable to type 'BaseSearchParamsWithoutQuery'.
                        Types of property 'facetFilters' are incompatible.
                          Type 'string | readonly string[] | readonly (string | readonly string[])[] | undefined' is not assignable to type 'FacetFilters | undefined'.
                            Type 'readonly string[]' is not assignable to type 'FacetFilters | undefined'.
                              The type 'readonly string[]' is 'readonly' and cannot be assigned to the mutable type 'FacetFilters[]'.ts(2322)
InstantSearch.d.ts(42, 5): The expected type comes from property 'searchClient' which is declared here on type 'IntrinsicAttributes & UseInstantSearchApiProps<UiState, UiState> & { children?: ReactNode; }'

@dhayab
Copy link
Member

dhayab commented Nov 8, 2024

There could be a version conflict in your package dependencies.

Could you ideally reproduce this behavior using the following sandbox as a starting point: https://codesandbox.io/p/sandbox/gh-6426-rhlwdn?

You can also check that if you have declared multiple algoliasearch related packages, that they target the same version (but you only need algoliasearch).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Library: React InstantSearch ≥ 7 Issues in any of the react-instantsearch@7 packages (formerly named react-instantsearch-hooks)
Projects
None yet
Development

No branches or pull requests

2 participants