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

chore(algolia): upgrade algoliasearch to v5 #10672

Merged
merged 8 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
slorber marked this conversation as resolved.
Show resolved Hide resolved
}, []);

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
Loading