From f90f805a246cac47a3ce111ecdaa3e30c0179655 Mon Sep 17 00:00:00 2001 From: Daniel Lautzenheiser Date: Wed, 8 Nov 2023 15:34:05 -0500 Subject: [PATCH] docs: fix search regex escaping --- .../docs/src/components/layout/search/SearchModal.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/docs/src/components/layout/search/SearchModal.tsx b/packages/docs/src/components/layout/search/SearchModal.tsx index e227731b..32620ced 100644 --- a/packages/docs/src/components/layout/search/SearchModal.tsx +++ b/packages/docs/src/components/layout/search/SearchModal.tsx @@ -104,11 +104,11 @@ const SearchModal: FC = ({ open, onClose, searchablePages }) = setSearch(event.target.value); }, []); - const searchResults = useSearchScores(search, searchablePages); + const escapedSearch = useMemo(() => escapeRegExp(search), [search]); + + const searchResults = useSearchScores(escapedSearch, searchablePages); const renderedResults = useMemo(() => { - const escapedSearch = escapeRegExp(search); - return searchResults?.length > 0 ? ( [...Array(SEARCH_RESULTS_TO_SHOW)].map((_, index) => { if (searchResults.length <= index) { @@ -203,7 +203,7 @@ const SearchModal: FC = ({ open, onClose, searchablePages }) = ); - }, [handleClose, search, searchResults, theme.palette.primary.main]); + }, [escapedSearch, handleClose, searchResults, theme.palette.primary.main]); return (