Skip to content

Commit 1d1ece8

Browse files
authored
fix: allow autocomplete value to be null without throwing (#851)
Sometimes in transient states (navigating to a new page) autocomplete can have a null value which would throw an error, this just makes sure we don't throw an error
1 parent 7c50e0c commit 1d1ece8

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

packages/app/src/SearchInputV2.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export class LuceneLanguageFormatter implements ILanguageFormatter {
2323
}
2424
}
2525

26+
const luceneLanguageFormatter = new LuceneLanguageFormatter();
2627
export default function SearchInputV2({
2728
tableConnections,
2829
placeholder = 'Search your events for anything...',
@@ -55,8 +56,8 @@ export default function SearchInputV2({
5556
const [parsedEnglishQuery, setParsedEnglishQuery] = useState<string>('');
5657

5758
const autoCompleteOptions = useAutoCompleteOptions(
58-
new LuceneLanguageFormatter(),
59-
value,
59+
luceneLanguageFormatter,
60+
value != null ? `${value}` : '', // value can be null at times
6061
{
6162
tableConnections,
6263
additionalSuggestions,

packages/app/src/hooks/useAutoCompleteOptions.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,10 @@ export function useAutoCompleteOptions(
6868
// clear search field if no key matches anymore
6969
useEffect(() => {
7070
if (!searchField) return;
71-
if (
72-
!(value as string).startsWith(formatter.formatFieldValue(searchField))
73-
) {
71+
if (!value.startsWith(formatter.formatFieldValue(searchField))) {
7472
setSearchField(null);
7573
}
76-
}, [searchField, setSearchField, value]);
74+
}, [searchField, setSearchField, value, formatter]);
7775
const searchKeys = useMemo(
7876
() =>
7977
searchField

0 commit comments

Comments
 (0)