Skip to content

Commit

Permalink
feat: preload search index when page is idle (#1811)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan authored Feb 5, 2025
1 parent 9dfc23d commit 77c24ec
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/theme-default/src/components/Search/SearchPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,17 @@ export function SearchPanel({ focused, setFocused }: SearchPanelProps) {
}
}, [focused]);

// Preload the search index when the page is idle
useEffect(() => {
if ('requestIdleCallback' in window) {
window.requestIdleCallback(() => {
if (!pageSearcherRef.current) {
initPageSearcher();
}
});
}
}, []);

useEffect(() => {
const { currentLang, currentVersion } = pageSearcherConfigRef.current ?? {};
const isLangChanged = lang !== currentLang;
Expand Down

0 comments on commit 77c24ec

Please sign in to comment.