Skip to content

Commit f42dfa2

Browse files
slorberclaude
andauthored
break(search): upgrade Algolia DocSearch packages, require DocSearch 4.6+, drop v3 support (#11917)
* do cleanup of v3 retrocompatibility code * remove unused translation key * fix DocSearchTranslations so that it becomes exhaustive * keep DocSearch v4 labels, remove remaining v3 workarounds - restore the "Powered by" and no-results labels still used by DocSearch 4.7 - remove the v3 type workarounds in SearchBar and useAlgoliaAskAi - remove the unused placeholder key from the az/mk locales Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * remove the website DocSearch version check and its unused deps Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
1 parent 337c598 commit f42dfa2

49 files changed

Lines changed: 29 additions & 246 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎packages/docusaurus-theme-search-algolia/src/client/useAlgoliaAskAi.ts‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77

88
import {useCallback, useMemo, useState} from 'react';
9-
import {version as docsearchVersion} from '@docsearch/react/version';
109
import translations from '@theme/SearchTranslations';
1110
import {useAlgoliaContextualFacetFiltersIfEnabled} from './useAlgoliaContextualFacetFilters';
1211
import {mergeFacetFilters} from './utils';
@@ -18,7 +17,6 @@ import type {
1817
import type {FacetFilters} from 'algoliasearch/lite';
1918

2019
// The minimal props the hook needs from DocSearch v4 props
21-
// TODO Docusaurus v4: cleanup after we drop support for DocSearch v3
2220
interface DocSearchV4PropsLite {
2321
indexName: string;
2422
apiKey: string;
@@ -29,8 +27,6 @@ interface DocSearchV4PropsLite {
2927
askAi?: AskAiConfig;
3028
}
3129

32-
const isV4 = docsearchVersion.startsWith('4.');
33-
3430
type UseAskAiResult = {
3531
canHandleAskAi: boolean;
3632
isAskAiActive: boolean;
@@ -81,10 +77,9 @@ export function useAlgoliaAskAi(props: DocSearchV4PropsLite): UseAskAiResult {
8177

8278
const canHandleAskAi = Boolean(askAi);
8379

84-
const currentPlaceholder =
85-
isAskAiActive && isV4
86-
? translations.modal?.searchBox?.placeholderTextAskAi
87-
: translations.modal?.searchBox?.placeholderText || props?.placeholder;
80+
const currentPlaceholder = isAskAiActive
81+
? translations.modal?.searchBox?.placeholderTextAskAi
82+
: translations.modal?.searchBox?.placeholderText || props?.placeholder;
8883

8984
const onAskAiToggle = useCallback((askAiToggle: boolean) => {
9085
setIsAskAiActive(askAiToggle);

‎packages/docusaurus-theme-search-algolia/src/docSearchVersion.ts‎

Lines changed: 0 additions & 12 deletions
This file was deleted.

‎packages/docusaurus-theme-search-algolia/src/index.ts‎

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
createOpenSearchHeadTags,
1313
shouldCreateOpenSearchFile,
1414
} from './opensearch';
15-
import {docSearchV3} from './docSearchVersion';
1615

1716
import type {LoadContext, Plugin} from '@docusaurus/types';
1817
import type {ThemeConfig} from '@docusaurus/theme-search-algolia';
@@ -66,26 +65,6 @@ export default function themeSearchAlgolia(context: LoadContext): Plugin<void> {
6665
}
6766
return {};
6867
},
69-
70-
configureWebpack() {
71-
// TODO Docusaurus v4: remove after dropping DocSearch v3 support
72-
if (docSearchV3) {
73-
// These aliases ensure DocSearch v3 imports are compatible with
74-
// the newly added DocSearch v4 entry points
75-
// See https://github.com/algolia/docsearch/pull/2764
76-
const docSearchV3Entry = require.resolve('@docsearch/react');
77-
return {
78-
resolve: {
79-
alias: {
80-
'@docsearch/react/version': docSearchV3Entry,
81-
'@docsearch/react/useDocSearchKeyboardEvents': docSearchV3Entry,
82-
'@docsearch/react/useTheme': docSearchV3Entry,
83-
},
84-
},
85-
};
86-
}
87-
return undefined;
88-
},
8968
};
9069
}
9170

‎packages/docusaurus-theme-search-algolia/src/theme-search-algolia.d.ts‎

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
// TODO Docusaurus v4: remove after we drop support for DocSearch v3
9-
declare module '@docsearch/react/button';
10-
declare module '@docsearch/react/useDocSearchKeyboardEvents';
11-
declare module '@docsearch/react/version';
12-
138
declare module '@docusaurus/theme-search-algolia' {
149
import type {DeepPartial, Overwrite, Optional} from 'utility-types';
1510

@@ -95,15 +90,6 @@ declare module '@theme/SearchBar' {
9590
declare module '@theme/SearchTranslations' {
9691
import type {DocSearchTranslations} from '@docsearch/react';
9792

98-
const translations: DocSearchTranslations & {
99-
placeholder: string;
100-
// TODO Docusaurus v4: cleanup after we drop support for DocSearch v3
101-
modal?: {
102-
searchBox?: {
103-
placeholderText?: string;
104-
placeholderTextAskAi?: string;
105-
};
106-
};
107-
};
93+
const translations: DocSearchTranslations;
10894
export default translations;
10995
}

‎packages/docusaurus-theme-search-algolia/src/theme/SearchBar/index.tsx‎

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import type {
3131
DocSearchTransformClient,
3232
DocSearchHit,
3333
DocSearchTranslations,
34-
UseDocSearchKeyboardEventsProps,
3534
} from '@docsearch/react';
3635

3736
import type {AutocompleteState} from '@algolia/autocomplete-core';
@@ -40,24 +39,15 @@ import type {ThemeConfigAlgolia} from '@docusaurus/theme-search-algolia';
4039

4140
type DocSearchProps = Omit<
4241
DocSearchModalProps,
43-
'onClose' | 'initialScrollY'
42+
'onClose' | 'initialScrollY' | 'indexName' | 'askAi' | 'translations'
4443
> & {
44+
indexName: string;
4545
contextualSearch?: string;
4646
externalUrlRegex?: string;
4747
searchPagePath: boolean | string;
48-
askAi?: Exclude<
49-
(DocSearchModalProps & {askAi: unknown})['askAi'],
50-
string | undefined
51-
>;
52-
};
53-
54-
// extend DocSearchProps for v4 features
55-
// TODO Docusaurus v4: cleanup after we drop support for DocSearch v3
56-
interface DocSearchV4Props extends Omit<DocSearchProps, 'askAi'> {
57-
indexName: string;
5848
askAi?: ThemeConfigAlgolia['askAi'];
5949
translations?: DocSearchTranslations;
60-
}
50+
};
6151

6252
let DocSearchModal: typeof DocSearchModalType | null = null;
6353

@@ -189,9 +179,9 @@ function useSearchParameters({
189179
};
190180
}
191181

192-
function DocSearch({externalUrlRegex, ...props}: DocSearchV4Props) {
182+
function DocSearch({externalUrlRegex, ...props}: DocSearchProps) {
193183
const navigator = useNavigator({externalUrlRegex});
194-
const searchParameters = useSearchParameters({...props} as DocSearchProps);
184+
const searchParameters = useSearchParameters(props);
195185
const transformItems = useTransformItems(props);
196186
const transformSearchClient = useTransformSearchClient();
197187

@@ -249,11 +239,7 @@ function DocSearch({externalUrlRegex, ...props}: DocSearchV4Props) {
249239
searchButtonRef,
250240
isAskAiActive: isAskAiActive ?? false,
251241
onAskAiToggle: onAskAiToggle ?? (() => {}),
252-
} satisfies UseDocSearchKeyboardEventsProps & {
253-
// TODO Docusaurus v4: cleanup after we drop support for DocSearch v3
254-
isAskAiActive: boolean;
255-
onAskAiToggle: (askAiToggle: boolean) => void;
256-
} as UseDocSearchKeyboardEventsProps);
242+
});
257243

258244
return (
259245
<>
@@ -309,11 +295,11 @@ function DocSearch({externalUrlRegex, ...props}: DocSearchV4Props) {
309295
);
310296
}
311297

312-
export default function SearchBar(props: Partial<DocSearchV4Props>): ReactNode {
298+
export default function SearchBar(props: Partial<DocSearchProps>): ReactNode {
313299
const {siteConfig} = useDocusaurusContext();
314300

315-
const docSearchProps: DocSearchV4Props = {
316-
...(siteConfig.themeConfig.algolia as DocSearchV4Props),
301+
const docSearchProps: DocSearchProps = {
302+
...(siteConfig.themeConfig.algolia as DocSearchProps),
317303
// Let props override theme config
318304
// See https://github.com/meta/docusaurus/pull/11581
319305
...props,

‎packages/docusaurus-theme-search-algolia/src/theme/SearchTranslations/index.ts‎

Lines changed: 9 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -7,64 +7,16 @@
77

88
import {translate} from '@docusaurus/Translate';
99

10-
import type {DocSearchTranslations} from '@docsearch/react';
10+
import type {ButtonTranslations, ModalTranslations} from '@docsearch/react';
1111

12-
// TODO Docusaurus v4: require DocSearch v4
13-
// This needs to be cleaned after the upgrade
14-
// Docusaurus v3 was made compatible with both DocSearch v3 and v4
15-
// This implies that labels have been kept retro-compatible with v3
16-
// Once we upgrade, we should be able to rely on v4 types only
17-
// and remove v3 retro-compatibility labels that do not exist anymore in v4
18-
const translations: DocSearchTranslations & {
19-
placeholder: string;
20-
modal: {
21-
searchBox: {
22-
placeholderText: string;
23-
placeholderTextAskAi: string;
24-
placeholderTextAskAiStreaming: string;
25-
enterKeyHintAskAi: string;
26-
searchInputLabel: string;
27-
backToKeywordSearchButtonText: string;
28-
backToKeywordSearchButtonAriaLabel: string;
29-
enterKeyHint: string;
30-
clearButtonTitle: string;
31-
clearButtonAriaLabel: string;
32-
closeButtonText: string;
33-
resetButtonTitle: string;
34-
resetButtonAriaLabel: string;
35-
cancelButtonText: string;
36-
cancelButtonAriaLabel: string;
37-
closeButtonAriaLabel: string;
38-
};
39-
startScreen: {
40-
recentConversationsTitle: string;
41-
removeRecentConversationButtonTitle: string;
42-
};
43-
resultsScreen: {
44-
askAiPlaceholder: string;
45-
};
46-
askAiScreen: {
47-
disclaimerText: string;
48-
relatedSourcesText: string;
49-
thinkingText: string;
50-
copyButtonText: string;
51-
copyButtonCopiedText: string;
52-
copyButtonTitle: string;
53-
likeButtonTitle: string;
54-
dislikeButtonTitle: string;
55-
thanksForFeedbackText: string;
56-
preToolCallText: string;
57-
duringToolCallText: string;
58-
afterToolCallText: string;
59-
};
60-
footer: {
61-
submitQuestionText: string;
62-
poweredByText: string;
63-
backToSearchText: string;
64-
searchByText: string;
65-
};
66-
};
67-
} = {
12+
// We use our own type because the exported one is Partial<>
13+
// TS should ensure we have translated everything exhaustively
14+
type DocSearchTranslations = {
15+
button: ButtonTranslations;
16+
modal: ModalTranslations;
17+
};
18+
19+
const translations: DocSearchTranslations = {
6820
button: {
6921
buttonText: translate({
7022
id: 'theme.SearchBar.label',
@@ -79,28 +31,6 @@ const translations: DocSearchTranslations & {
7931
},
8032
modal: {
8133
searchBox: {
82-
resetButtonTitle: translate({
83-
id: 'theme.SearchModal.searchBox.resetButtonTitle',
84-
message: 'Clear the query',
85-
description: 'The label and ARIA label for search box reset button',
86-
}),
87-
resetButtonAriaLabel: translate({
88-
id: 'theme.SearchModal.searchBox.resetButtonTitle',
89-
message: 'Clear the query',
90-
description: 'The label and ARIA label for search box reset button',
91-
}),
92-
cancelButtonText: translate({
93-
id: 'theme.SearchModal.searchBox.cancelButtonText',
94-
message: 'Cancel',
95-
description: 'The label and ARIA label for search box cancel button',
96-
}),
97-
cancelButtonAriaLabel: translate({
98-
id: 'theme.SearchModal.searchBox.cancelButtonText',
99-
message: 'Cancel',
100-
description: 'The label and ARIA label for search box cancel button',
101-
}),
102-
103-
// v4
10434
clearButtonTitle: translate({
10535
id: 'theme.SearchModal.searchBox.resetButtonTitle',
10636
message: 'Clear the query',
@@ -333,11 +263,6 @@ const translations: DocSearchTranslations & {
333263
message: 'Powered by',
334264
description: "The 'Powered by' text for footer",
335265
}),
336-
searchByText: translate({
337-
id: 'theme.SearchModal.footer.searchByText',
338-
message: 'Powered by',
339-
description: "The 'Powered by' text for footer",
340-
}),
341266
backToSearchText: translate({
342267
id: 'theme.SearchModal.footer.backToSearchText',
343268
message: 'Back to search',
@@ -367,11 +292,6 @@ const translations: DocSearchTranslations & {
367292
}),
368293
},
369294
},
370-
placeholder: translate({
371-
id: 'theme.SearchModal.placeholder',
372-
message: 'Search docs',
373-
description: 'The placeholder of the input of the DocSearch pop-up modal',
374-
}),
375295
};
376296

377297
export default translations;

‎packages/docusaurus-theme-search-algolia/src/validateThemeConfig.ts‎

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77

88
import {Joi} from '@docusaurus/utils-validation';
9-
import {docSearchV3} from './docSearchVersion';
109
import type {ThemeConfigValidationContext} from '@docusaurus/types';
1110
import type {
1211
ThemeConfig,
@@ -129,23 +128,11 @@ const Schema = Joi.object<ThemeConfig>({
129128
.unknown(),
130129
});
131130

132-
// TODO Docusaurus v4: remove this check when we drop DocSearch v3
133-
function ensureAskAISupported(themeConfig: ThemeConfig) {
134-
// enforce DocsSearch v4 requirement when AskAI is configured
135-
if (themeConfig.algolia.askAi && docSearchV3) {
136-
throw new Error(
137-
'The askAi feature is only supported in DocSearch v4. ' +
138-
'Please upgrade to DocSearch v4 by installing "@docsearch/react": "^4.0.0" ' +
139-
'or remove the askAi configuration from your theme config.',
140-
);
141-
}
142-
}
143-
144131
export function validateThemeConfig({
145132
validate,
146133
themeConfig: themeConfigInput,
147134
}: ThemeConfigValidationContext<ThemeConfig>): ThemeConfig {
148135
const themeConfig = validate(Schema, themeConfigInput);
149-
ensureAskAISupported(themeConfig);
136+
150137
return themeConfig;
151138
}

‎packages/docusaurus-theme-translations/locales/ar/theme-search-algolia.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
"theme.SearchModal.noResultsScreen.reportMissingResultsLinkText": "Let us know.",
3030
"theme.SearchModal.noResultsScreen.reportMissingResultsText": "Believe this query should return results?",
3131
"theme.SearchModal.noResultsScreen.suggestedQueryText": "Try searching for",
32-
"theme.SearchModal.placeholder": "Search docs",
3332
"theme.SearchModal.resultsScreen.askAiPlaceholder": "Ask AI: ",
3433
"theme.SearchModal.searchBox.backToKeywordSearchButtonAriaLabel": "Back to keyword search",
3534
"theme.SearchModal.searchBox.backToKeywordSearchButtonText": "Back to keyword search",

‎packages/docusaurus-theme-translations/locales/az/theme-search-algolia.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
"theme.SearchModal.noResultsScreen.reportMissingResultsLinkText": "Bizə bildirin.",
3030
"theme.SearchModal.noResultsScreen.reportMissingResultsText": "Bu sorğunun nəticə qaytarmalı olduğunu düşünürsünüz?",
3131
"theme.SearchModal.noResultsScreen.suggestedQueryText": "Bunu axtarmağa cəhd edin:",
32-
"theme.SearchModal.placeholder": "Sənədlərdə axtar",
3332
"theme.SearchModal.resultsScreen.askAiPlaceholder": "Süni intellektdən soruş: ",
3433
"theme.SearchModal.searchBox.backToKeywordSearchButtonAriaLabel": "Açar söz axtarışına qayıt",
3534
"theme.SearchModal.searchBox.backToKeywordSearchButtonText": "Açar söz axtarışına qayıt",

‎packages/docusaurus-theme-translations/locales/base/theme-search-algolia.json‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@
5858
"theme.SearchModal.noResultsScreen.reportMissingResultsText___DESCRIPTION": "The text for reporting missing results",
5959
"theme.SearchModal.noResultsScreen.suggestedQueryText": "Try searching for",
6060
"theme.SearchModal.noResultsScreen.suggestedQueryText___DESCRIPTION": "The text for suggested query",
61-
"theme.SearchModal.placeholder": "Search docs",
62-
"theme.SearchModal.placeholder___DESCRIPTION": "The placeholder of the input of the DocSearch pop-up modal",
6361
"theme.SearchModal.resultsScreen.askAiPlaceholder": "Ask AI: ",
6462
"theme.SearchModal.resultsScreen.askAiPlaceholder___DESCRIPTION": "The placeholder text for Ask AI input",
6563
"theme.SearchModal.searchBox.backToKeywordSearchButtonAriaLabel": "Back to keyword search",

0 commit comments

Comments
 (0)