Skip to content

Commit 6ef6505

Browse files
authored
fix: Missing result title would trigger an error (#2852)
1 parent 104f7d1 commit 6ef6505

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

packages/docsearch-react/src/Results.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export type ResultsTranslations = Partial<{
1313
}>;
1414
interface ResultsProps<TItem extends BaseItem>
1515
extends AutocompleteApi<TItem, React.FormEvent, React.MouseEvent, React.KeyboardEvent> {
16-
title: string;
16+
title?: string | null;
1717
translations?: ResultsTranslations;
1818
collection: AutocompleteState<TItem>['collections'][0];
1919
renderIcon: (props: { item: TItem; index: number }) => React.ReactNode;
@@ -25,7 +25,12 @@ interface ResultsProps<TItem extends BaseItem>
2525

2626
export function Results<TItem extends StoredDocSearchHit>(props: ResultsProps<TItem>): JSX.Element | null {
2727
// The collection title, decoded to handle encoded HTML entities
28+
// If there is not a title, return null to not render anything
2829
const decodedTitle = React.useMemo(() => {
30+
if (!props.title) {
31+
return null;
32+
}
33+
2934
return props.title
3035
.replace(/&amp;/g, '&')
3136
.replace(/&lt;/g, '<')

0 commit comments

Comments
 (0)