diff --git a/.changeset/bright-moons-open.md b/.changeset/bright-moons-open.md new file mode 100644 index 0000000000..2668dfb2e6 --- /dev/null +++ b/.changeset/bright-moons-open.md @@ -0,0 +1,6 @@ +--- +'@backstage/plugin-search-react': patch +'@backstage/plugin-search': patch +--- + +Fixes the search component not registering the first search on navigate to the search page. diff --git a/.patches/pr-32973.txt b/.patches/pr-32973.txt new file mode 100644 index 0000000000..6d83c5d66d --- /dev/null +++ b/.patches/pr-32973.txt @@ -0,0 +1 @@ +Fixes the search component to register the first search that happens on initial navigation to the search page. \ No newline at end of file diff --git a/plugins/search-react/src/context/SearchContext.tsx b/plugins/search-react/src/context/SearchContext.tsx index dc129c6327..0d18b888e5 100644 --- a/plugins/search-react/src/context/SearchContext.tsx +++ b/plugins/search-react/src/context/SearchContext.tsx @@ -138,14 +138,13 @@ const useSearchContextValue = ( const result = useAsync(async (): Promise => { if (isFirstEmptyMount.current) { + isFirstEmptyMount.current = false; if (!term && !types.length && !Object.keys(filters).length) { return { results: [], numberOfResults: 0, }; } - - isFirstEmptyMount.current = false; } // Here we cancel the previous request before making a new one diff --git a/plugins/search/src/components/SearchPage/SearchPage.tsx b/plugins/search/src/components/SearchPage/SearchPage.tsx index 8428fb6bb5..92b327207f 100644 --- a/plugins/search/src/components/SearchPage/SearchPage.tsx +++ b/plugins/search/src/components/SearchPage/SearchPage.tsx @@ -59,9 +59,7 @@ export const UrlUpdater = () => { setPageCursor(query.pageCursor as string); } - if (query.types) { - setTypes(query.types as string[]); - } + setTypes(query.types ? (query.types as string[]) : []); }, [prevQueryParams, location, setTerm, setTypes, setPageCursor, setFilters]); useEffect(() => {