Skip to content

Commit

Permalink
docs: fix search regex escaping
Browse files Browse the repository at this point in the history
  • Loading branch information
KaneFreeman committed Nov 8, 2023
1 parent 27b6112 commit f90f805
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/docs/src/components/layout/search/SearchModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ const SearchModal: FC<SearchModalProps> = ({ open, onClose, searchablePages }) =
setSearch(event.target.value);
}, []);

const searchResults = useSearchScores(search, searchablePages);
const escapedSearch = useMemo(() => escapeRegExp(search), [search]);

const renderedResults = useMemo(() => {
const escapedSearch = escapeRegExp(search);
const searchResults = useSearchScores(escapedSearch, searchablePages);

const renderedResults = useMemo(() => {
return searchResults?.length > 0 ? (
[...Array<unknown>(SEARCH_RESULTS_TO_SHOW)].map((_, index) => {
if (searchResults.length <= index) {
Expand Down Expand Up @@ -203,7 +203,7 @@ const SearchModal: FC<SearchModalProps> = ({ open, onClose, searchablePages }) =
</StyledSuggestionSection>
</StyledSuggestions>
);
}, [handleClose, search, searchResults, theme.palette.primary.main]);
}, [escapedSearch, handleClose, searchResults, theme.palette.primary.main]);

return (
<StyledDialog open={open} onClose={handleClose} fullScreen={fullScreen} fullWidth>
Expand Down

0 comments on commit f90f805

Please sign in to comment.