Skip to content

Commit

Permalink
chore(algolia): upgrade algoliasearch to v5 (#10672)
Browse files Browse the repository at this point in the history
Co-authored-by: sebastien <[email protected]>
  • Loading branch information
millotp and slorber authored Dec 26, 2024
1 parent 37184e5 commit 4a1ec52
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 184 deletions.
6 changes: 3 additions & 3 deletions packages/docusaurus-theme-search-algolia/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@
"copy:watch": "node ../../admin/scripts/copyUntypedFiles.js --watch"
},
"dependencies": {
"@docsearch/react": "^3.5.2",
"@docsearch/react": "^3.8.1",
"@docusaurus/core": "3.6.3",
"@docusaurus/logger": "3.6.3",
"@docusaurus/plugin-content-docs": "3.6.3",
"@docusaurus/theme-common": "3.6.3",
"@docusaurus/theme-translations": "3.6.3",
"@docusaurus/utils": "3.6.3",
"@docusaurus/utils-validation": "3.6.3",
"algoliasearch": "^4.18.0",
"algoliasearch-helper": "^3.13.3",
"algoliasearch": "^5.17.1",
"algoliasearch-helper": "^3.22.6",
"clsx": "^2.0.0",
"eta": "^2.2.0",
"fs-extra": "^11.1.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,16 @@ import {
import Translate from '@docusaurus/Translate';
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
import translations from '@theme/SearchTranslations';

import type {AutocompleteState} from '@algolia/autocomplete-core';
import type {
InternalDocSearchHit,
DocSearchModal as DocSearchModalType,
DocSearchModalProps,
} from '@docsearch/react';
import type {
InternalDocSearchHit,
StoredDocSearchHit,
} from '@docsearch/react/dist/esm/types';
import type {SearchClient} from 'algoliasearch/lite';
DocSearchTransformClient,
} from '@docsearch/react';

import type {AutocompleteState} from '@algolia/autocomplete-core';
import type {FacetFilters} from 'algoliasearch/lite';

type DocSearchProps = Omit<
DocSearchModalProps,
Expand Down Expand Up @@ -80,16 +79,10 @@ function ResultsFooter({state, onClose}: ResultsFooterProps) {
);
}

type FacetFilters = Required<
Required<DocSearchProps>['searchParameters']
>['facetFilters'];

function mergeFacetFilters(f1: FacetFilters, f2: FacetFilters): FacetFilters {
const normalize = (
f: FacetFilters,
): readonly string[] | readonly (string | readonly string[])[] =>
const normalize = (f: FacetFilters): FacetFilters =>
typeof f === 'string' ? [f] : f;
return [...normalize(f1), ...normalize(f2)] as FacetFilters;
return [...normalize(f1), ...normalize(f2)];
}

function DocSearch({
Expand Down Expand Up @@ -159,6 +152,7 @@ function DocSearch({
const closeModal = useCallback(() => {
setIsOpen(false);
searchButtonRef.current?.focus();
setInitialQuery(undefined);
}, []);

const handleInput = useCallback(
Expand Down Expand Up @@ -210,7 +204,7 @@ function DocSearch({
);

const transformSearchClient = useCallback(
(searchClient: SearchClient) => {
(searchClient: DocSearchTransformClient) => {
searchClient.addAlgoliaAgent(
'docusaurus',
siteMetadata.docusaurusVersion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import React, {
import clsx from 'clsx';

import algoliaSearchHelper from 'algoliasearch-helper';
import algoliaSearch from 'algoliasearch/lite';
import {liteClient} from 'algoliasearch/lite';

import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
import Head from '@docusaurus/Head';
Expand Down Expand Up @@ -225,7 +225,7 @@ function SearchPageContent(): ReactNode {
? ['language', 'docusaurus_tag']
: [];

const algoliaClient = algoliaSearch(appId, apiKey);
const algoliaClient = liteClient(appId, apiKey);
const algoliaHelper = algoliaSearchHelper(algoliaClient, indexName, {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore: why errors happens after upgrading to TS 5.5 ?
Expand Down
Loading

0 comments on commit 4a1ec52

Please sign in to comment.