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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

<Configure /> types wrong or conflict with documentation #5989

Open
1 task done
stwilz opened this issue Jan 6, 2024 · 11 comments
Open
1 task done

<Configure /> types wrong or conflict with documentation #5989

stwilz opened this issue Jan 6, 2024 · 11 comments
Labels
triage Issues to be categorized by the team

Comments

@stwilz
Copy link

stwilz commented Jan 6, 2024

馃悰 Current behavior

In the documentation here,
https://www.algolia.com/doc/api-reference/widgets/configure/react/#widget-param-searchparameters

it outlines that you should be able to define a filter on the Configure component like so,

<Configure
  analytics={false}
  filters="free_shipping:true"
  hitsPerPage={40}
/>

Which does work as expected but when implemented in Typescript the following type error appears,
'filters' does not exist in type 'PlainSearchParameters'.

Are we potentially not implementing this correctly, could it be and issue with using react-instantsearch-nextjs or is there a problem with the libraries types?

Thanks!

馃攳 Steps to reproduce

  1. Create Next 14 boilerplate with typescript
  2. Install react-instantsearch & react-instantsearch-nextjs
  3. Implement Intant Search and Configure

Live reproduction

...

馃挱 Expected behavior

This is a development issue. No live preview required.

Package version

7.5.0

Operating system

No response

Browser

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@stwilz stwilz added the triage Issues to be categorized by the team label Jan 6, 2024
@Haroenv
Copy link
Contributor

Haroenv commented Jan 7, 2024

I believe you haven't installed algoliasearch, can you check that? There should be a warning in the install message too

@stwilz
Copy link
Author

stwilz commented Jan 7, 2024

Can confirm we have been using algoliasearch 4.22.0

'use client';

import { Configure, ConfigureProps, Hits } from 'react-instantsearch';

import algoliasearch from 'algoliasearch';
import { InstantSearchNext } from 'react-instantsearch-nextjs';

const searchIndex = new String(
  process.env.NEXT_PUBLIC_ALGOLIA_INDEX_NAME
).toString();

export const client = algoliasearch(
  process.env.NEXT_PUBLIC_ALGOLIA_APP_ID!,
  process.env.NEXT_PUBLIC_ALGOLIA_API_KEY!
);

export function AlgoliaFacetSearch({
  primaryFacet = '',
  query = '',
  tags = [],
}) {
  const configureProps = {
    filters: `type:"${primaryFacet}"`,
    facets: ['*'],
    query: query,
    tagRefinements: tags,
    facetingAfterDistinct: true,
    hitsPerPage: 40,
  } as ConfigureProps;

  return (
    <InstantSearchNext
      indexName={searchIndex}
      searchClient={client}
      future={{
        preserveSharedStateOnUnmount: true,
      }}
    >
      <Hits />
      <Configure {...configureProps} />
    </InstantSearchNext>
  );
}

@Haroenv
Copy link
Contributor

Haroenv commented Jan 8, 2024

Hey, I copied your code standalone, and everything seems to be working? Is there any package that could be stuck at an older version? Even transitive ones like algoliasearch-helper for example.

Here's my reproduction that has no typescript error: https://codesandbox.io/p/devbox/configure-works-nrlt73

@stwilz
Copy link
Author

stwilz commented Jan 10, 2024

Our code works because we cast configureProps as ConfigureProps. codesandbox doesn't seem to be displaying type errors. I'll create a local copy, run in VSCode and get back to you.

@flevi29
Copy link

flevi29 commented Feb 13, 2024

Going from "instantsearch.js": "4.64.1" to "instantsearch.js": "4.64.3" does break types somehow.

The following starts erring, telling me hitsPerPage doesn't exist as an option.

connectConfigure(() => {})({
      searchParameters: { hitsPerPage: this.#hitsPerPage },
    })

@Haroenv
Copy link
Contributor

Haroenv commented Feb 13, 2024

I don't think any change happened in those versions @flevi29, are you sure that was the only change?

@flevi29
Copy link

flevi29 commented Feb 13, 2024

All I know is that I reverted my update only on instantsearch.js from .3 to .1 and then it worked. But now that I'm trying to reproduce it, it no longer happens, for whatever reason.

I know that it was printing something like hitsPerPage doesn't exist on PlainSearchParameters & object, where PlainSearchParameters extends SearchOptions and SearchOptions might come from something weird and hacky that I don't know what to think about PickForClient with tons of @ts-ignores. Doing stuff like this might very well cause unexpected and erratic behavior.

@Haroenv
Copy link
Contributor

Haroenv commented Feb 13, 2024

Sure, PickForClient is there to support many use cases for different versions of algoliasearch and ensuring that the parameters are maintained in a single place only. There however haven't been any changes to this code in a long time (definitely not between the last three patches of InstantSearch.js), so maybe it's a typescript compiler cache thing where it was evaluating just when you were reinstalling and thus there was no algoliasearch? If you can reproduce consistently we'll fix it of course

@Ra0R
Copy link

Ra0R commented May 10, 2024

I was having the same issue. I think it might not be related to any changes within the library.
Initially I was not having the issue locally, but when building on the build server the error would arise.

Differences could potentially be, node version, yarn version or typescript version? (I was using an older version of node locally and the error was not arising).

@Haroenv
Copy link
Contributor

Haroenv commented May 13, 2024

Did you resolve the problem on the build server in the end @Ra0R ?

@Ra0R
Copy link

Ra0R commented May 15, 2024

@Haroenv I did not, I used the workaround by casting it to the correct type.

I am not sure what causes the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage Issues to be categorized by the team
Projects
None yet
Development

No branches or pull requests

4 participants