From d06dd5139330ae2d378ba3dd22edd83091962500 Mon Sep 17 00:00:00 2001 From: Jonathan Roebuck Date: Tue, 17 Mar 2026 08:16:50 +0000 Subject: [PATCH] Fix effect firing default getData for data prop variant The effect was calling the default getData = () => [] even when the consumer used the data prop, immediately clearing the loading state. Now detects whether getData was explicitly provided and only runs the async loading logic for that case. Also clears isLoading when data transitions from undefined to defined. Co-Authored-By: Claude Opus 4.6 Signed-off-by: Jonathan Roebuck --- .../components/Table/hooks/useCompletePagination.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/ui/src/components/Table/hooks/useCompletePagination.ts b/packages/ui/src/components/Table/hooks/useCompletePagination.ts index d652f5203f..e382cf6413 100644 --- a/packages/ui/src/components/Table/hooks/useCompletePagination.ts +++ b/packages/ui/src/components/Table/hooks/useCompletePagination.ts @@ -37,6 +37,7 @@ export function useCompletePagination( filterFn, searchFn, } = options; + const hasGetData = 'getData' in options; const { initialOffset = 0 } = paginationOptions; const defaultPageSize = getEffectivePageSize(paginationOptions); @@ -54,6 +55,11 @@ export function useCompletePagination( // Load data on mount and when loadCount changes (reload trigger) useEffect(() => { if (data) { + setIsLoading(false); + return; + } + + if (!hasGetData) { return; } @@ -64,9 +70,9 @@ export function useCompletePagination( (async () => { try { const result = getData(); - const data = result instanceof Promise ? await result : result; + const resolvedData = result instanceof Promise ? await result : result; if (!cancelled) { - setItems(data); + setItems(resolvedData); setIsLoading(false); } } catch (err) { @@ -80,7 +86,7 @@ export function useCompletePagination( return () => { cancelled = true; }; - }, [data, getData, loadCount]); + }, [data, getData, hasGetData, loadCount]); // Reset offset when query changes (query object is memoized) const prevQueryRef = useRef(query);