File tree Expand file tree Collapse file tree 10 files changed +213
-172
lines changed
packages/docusaurus-theme-search-algolia Expand file tree Collapse file tree 10 files changed +213
-172
lines changed Original file line number Diff line number Diff line change 129129 "stylelint-config-standard" : " ^29.0.0" ,
130130 "typescript" : " ~5.8.2"
131131 },
132- "resolutions" : {
133- "@docsearch/react" : " ^4.0.1"
134- },
135132 "packageManager" : " yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
136133}
Original file line number Diff line number Diff line change 3333 "copy:watch" : " node ../../admin/scripts/copyUntypedFiles.js --watch"
3434 },
3535 "dependencies" : {
36- "@docsearch/react" : " ^3.9.0" ,
36+ "@docsearch/react" : " ^3.9.0 || ^4.1.0 " ,
3737 "@docusaurus/core" : " 3.8.1" ,
3838 "@docusaurus/logger" : " 3.8.1" ,
3939 "@docusaurus/plugin-content-docs" : " 3.8.1" ,
Original file line number Diff line number Diff line change 66 */
77
88import { useCallback , useMemo , useState } from 'react' ;
9- import {
10- version as docsearchVersion ,
11- type DocSearchModalProps ,
12- type DocSearchTranslations ,
13- } from '@docsearch/react' ;
9+ import { version as docsearchVersion } from '@docsearch/react/version' ;
1410import translations from '@theme/SearchTranslations' ;
1511import { useAlgoliaContextualFacetFiltersIfEnabled } from './useAlgoliaContextualFacetFilters' ;
1612import { mergeFacetFilters } from './utils' ;
1713import type { AskAiConfig } from '@docusaurus/theme-search-algolia' ;
14+ import type {
15+ DocSearchModalProps ,
16+ DocSearchTranslations ,
17+ } from '@docsearch/react' ;
1818import type { FacetFilters } from 'algoliasearch/lite' ;
1919
2020// The minimal props the hook needs from DocSearch v4 props
Original file line number Diff line number Diff line change 1+ /**
2+ * Copyright (c) Facebook, Inc. and its affiliates.
3+ *
4+ * This source code is licensed under the MIT license found in the
5+ * LICENSE file in the root directory of this source tree.
6+ */
7+
8+ import { version as docSearchVersion } from '@docsearch/react' ;
9+
10+ // TODO Docusaurus v4: upgrade to DocSearch v4
11+ // drop v3 compat, remove this file?
12+ export const docSearchV3 : boolean = docSearchVersion . startsWith ( '3.' ) ;
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import {
1212 createOpenSearchHeadTags ,
1313 shouldCreateOpenSearchFile ,
1414} from './opensearch' ;
15+ import { docSearchV3 } from './docSearchVersion' ;
1516
1617import type { LoadContext , Plugin } from '@docusaurus/types' ;
1718import type { ThemeConfig } from '@docusaurus/theme-search-algolia' ;
@@ -65,6 +66,26 @@ export default function themeSearchAlgolia(context: LoadContext): Plugin<void> {
6566 }
6667 return { } ;
6768 } ,
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+ } ,
6889 } ;
6990}
7091
Original file line number Diff line number Diff line change 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+
813declare module '@docusaurus/theme-search-algolia' {
914 import type { DeepPartial , Overwrite } from 'utility-types' ;
1015
Original file line number Diff line number Diff line change @@ -13,7 +13,8 @@ import React, {
1313 type ReactNode ,
1414} from 'react' ;
1515import { createPortal } from 'react-dom' ;
16- import { DocSearchButton , useDocSearchKeyboardEvents } from '@docsearch/react' ;
16+ import { DocSearchButton } from '@docsearch/react/button' ;
17+ import { useDocSearchKeyboardEvents } from '@docsearch/react/useDocSearchKeyboardEvents' ;
1718import Head from '@docusaurus/Head' ;
1819import Link from '@docusaurus/Link' ;
1920import { useHistory } from '@docusaurus/router' ;
@@ -73,9 +74,7 @@ function importDocSearchModalIfNeeded() {
7374 return Promise . resolve ( ) ;
7475 }
7576 return Promise . all ( [
76- import ( '@docsearch/react/modal' ) as Promise <
77- typeof import ( '@docsearch/react' )
78- > ,
77+ import ( '@docsearch/react/modal' ) ,
7978 import ( '@docsearch/react/style' ) ,
8079 import ( './styles.css' ) ,
8180 ] ) . then ( ( [ { DocSearchModal : Modal } ] ) => {
Original file line number Diff line number Diff line change 77
88import { escapeRegexp } from '@docusaurus/utils' ;
99import { Joi } from '@docusaurus/utils-validation' ;
10- import { version as docsearchVersion } from '@docsearch/react ' ;
10+ import { docSearchV3 } from './docSearchVersion ' ;
1111import type { ThemeConfigValidationContext } from '@docusaurus/types' ;
1212import type {
1313 ThemeConfig ,
@@ -123,9 +123,10 @@ export const Schema = Joi.object<ThemeConfig>({
123123 . unknown ( ) ,
124124} ) ;
125125
126+ // TODO Docusaurus v4: remove this check when we drop DocSearch v3
126127function ensureAskAISupported ( themeConfig : ThemeConfig ) {
127128 // enforce DocsSearch v4 requirement when AskAI is configured
128- if ( themeConfig . algolia . askAi && ! docsearchVersion . startsWith ( '4.' ) ) {
129+ if ( themeConfig . algolia . askAi && docSearchV3 ) {
129130 throw new Error (
130131 'The askAi feature is only supported in DocSearch v4. ' +
131132 'Please upgrade to DocSearch v4 by installing "@docsearch/react": "^4.0.0" ' +
Original file line number Diff line number Diff line change @@ -656,7 +656,8 @@ export default async function createConfigAsync() {
656656 apiKey : 'bf7211c161e8205da2f933a02534105a' ,
657657 indexName : 'docusaurus-2' ,
658658
659- // TODO temporary, for DocSearch v3/v4 conditional Ask AI integration
659+ // TODO Docusaurus v4: remove after we drop DocSearch v3
660+ // temporary, for DocSearch v3/v4 conditional Ask AI integration
660661 // see https://github.com/facebook/docusaurus/pull/11327
661662 // eslint-disable-next-line @typescript-eslint/no-var-requires,global-require
662663 ...( require ( '@docsearch/react' ) . version . startsWith ( '4.' )
You can’t perform that action at this time.
0 commit comments