diff --git a/packages/ui/src/hooks/use-filtered-list.tsx b/packages/ui/src/hooks/use-filtered-list.tsx index b6bd7d5c6c0..db2fee5482b 100644 --- a/packages/ui/src/hooks/use-filtered-list.tsx +++ b/packages/ui/src/hooks/use-filtered-list.tsx @@ -24,6 +24,7 @@ export function useFilteredList(props: FilteredListProps) { const [grouped, { refetch }] = createResource( () => { // When items is a function (not async filter function), call it to track changes + // Don't call async functions here - they'll be called in the fetcher with the filter const itemsValue = typeof props.items === "function" ? (props.items as () => T[])() // Call synchronous function to track it @@ -36,7 +37,13 @@ export function useFilteredList(props: FilteredListProps) { }, async ({ filter, items }) => { const needle = filter?.toLowerCase() - const all = (items ?? (await (props.items as (filter: string) => T[] | Promise)(needle))) || [] + // Handle case where items is a Promise (from async function called without filter) + // In that case, we need to call the function again with the proper filter + const resolvedItems = + items instanceof Promise || !Array.isArray(items) + ? await (props.items as (filter: string) => T[] | Promise)(needle ?? "") + : items + const all = resolvedItems || [] const result = pipe( all, (x) => {