diff --git a/apps/web/src/components/CommandPallette.tsx b/apps/web/src/components/CommandPallette.tsx index 8119b8a1..5e1e6f7a 100644 --- a/apps/web/src/components/CommandPallette.tsx +++ b/apps/web/src/components/CommandPallette.tsx @@ -45,12 +45,13 @@ export default function CommandPallette({ const { workspace } = useWorkspace(); // Debounce to avoid too many reqs - const [debouncedQuery] = useDebounce(query, 500); + const [debouncedQuery] = useDebounce(query, 300); const { data: searchResults, isLoading, isFetched, + isPlaceholderData, } = api.workspace.search.useQuery( { workspacePublicId: workspace.publicId, @@ -58,10 +59,16 @@ export default function CommandPallette({ }, { enabled: Boolean(workspace.publicId && debouncedQuery.trim().length > 0), + placeholderData: (previousData) => previousData, }, ); - const results = (searchResults ?? []) as SearchResult[]; + // Clear results when query is empty, otherwise show search results + const results = + debouncedQuery.trim().length === 0 + ? [] + : ((searchResults ?? []) as SearchResult[]); + const hasSearched = Boolean(debouncedQuery.trim().length > 0 && isFetched); return ( @@ -102,7 +109,9 @@ export default function CommandPallette({ {results.length > 0 && ( {results.map((result) => (