Skip to content

Commit 117228b

Browse files
authored
fix(results): unescaped lvl0 (#1001)
* fix(results): unescaped lvl0 * upgrade bundlesize
1 parent 2c0962e commit 117228b

5 files changed

Lines changed: 19 additions & 5 deletions

File tree

bundlesize.config.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
},
77
{
88
"path": "packages/docsearch-react/dist/umd/index.js",
9-
"maxSize": "18.2 kB"
9+
"maxSize": "18.3 kB"
1010
},
1111
{
1212
"path": "packages/docsearch-js/dist/umd/index.js",
13-
"maxSize": "25.8 kB"
13+
"maxSize": "25.9 kB"
1414
}
1515
]
1616
}

packages/docsearch-react/src/DocSearchModal.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
import { useSearchClient } from './useSearchClient';
2121
import { useTouchEvents } from './useTouchEvents';
2222
import { useTrapFocus } from './useTrapFocus';
23-
import { groupBy, identity, noop } from './utils';
23+
import { groupBy, identity, noop, removeHighlightTags } from './utils';
2424

2525
export interface DocSearchModalProps extends DocSearchProps {
2626
initialScrollY: number;
@@ -224,7 +224,9 @@ export function DocSearchModal({
224224
.then((results) => {
225225
const hits = results[0].hits;
226226
const nbHits: number = results[0].nbHits;
227-
const sources = groupBy(hits, (hit) => hit.hierarchy.lvl0);
227+
const sources = groupBy(hits, (hit) =>
228+
removeHighlightTags(hit.hierarchy.lvl0)
229+
);
228230

229231
// We store the `lvl0`s to display them as search suggestions
230232
// in the “no results“ screen.

packages/docsearch-react/src/ResultsScreen.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { SelectIcon, SourceIcon } from './icons';
44
import { Results } from './Results';
55
import { ScreenStateProps } from './ScreenState';
66
import { InternalDocSearchHit } from './types';
7+
import { removeHighlightTags } from './utils';
78

89
type ResultsScreenProps = ScreenStateProps<InternalDocSearchHit>;
910

@@ -15,7 +16,9 @@ export function ResultsScreen(props: ResultsScreenProps) {
1516
return null;
1617
}
1718

18-
const title = collection.items[0].hierarchy.lvl0;
19+
const title = removeHighlightTags(
20+
collection.items[0]._highlightResult.hierarchy.lvl0.value
21+
);
1922

2023
return (
2124
<Results
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from './groupBy';
22
export * from './identity';
33
export * from './noop';
4+
export * from './removeHighlightTags';
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const regexHighlightTags = /(<mark>|<\/mark>)/g;
2+
const regexHasHighlightTags = RegExp(regexHighlightTags.source);
3+
4+
export function removeHighlightTags(value: string): string {
5+
return value && regexHasHighlightTags.test(value)
6+
? value.replace(regexHighlightTags, '')
7+
: value;
8+
}

0 commit comments

Comments
 (0)