Skip to content

Commit

Permalink
refactor: Lazy load algolia docsearch (#1202)
Browse files Browse the repository at this point in the history
* refactor: Lazy load algolia docsearch

* refactor: Add suspense boundary around lazy algolia search
  • Loading branch information
rschristian authored Dec 7, 2024
1 parent 287ce5c commit be51af2
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/components/header/search.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { lazy, ErrorBoundary } from 'preact-iso';
import style from './style.module.css';
import config from '../../config.json';
import { DocSearch } from '@docsearch/react';

const DocSearch = lazy(() => import('@docsearch/react').then(m => m.DocSearch));

// Might be a problem with the Algolia data, but it seemingly
// appends `#app` to all URLs without a hash fragment.
Expand All @@ -16,12 +18,14 @@ const transformItems = (items) =>
export default function Search() {
return (
<div class={style.search}>
<DocSearch
apiKey={config.docsearch.apiKey}
indexName={config.docsearch.indexName}
appId={config.docsearch.appId}
transformItems={transformItems}
/>
<ErrorBoundary>
<DocSearch
apiKey={config.docsearch.apiKey}
indexName={config.docsearch.indexName}
appId={config.docsearch.appId}
transformItems={transformItems}
/>
</ErrorBoundary>
</div>
);
}

0 comments on commit be51af2

Please sign in to comment.