From 7fa8f2355587bc1bd06be8656ac5a5683fd55503 Mon Sep 17 00:00:00 2001 From: ehhuang Date: Tue, 24 Jun 2025 03:22:55 -0700 Subject: [PATCH] fix(ui): ensure initial data fetch only happens once (#2486) # What does this PR do? Bug: 1. go to responses chat logs in UI 2. go to chat completions logs page 3. observe that same data appears in the table twice This is because `fetchData` is called multiple times when multiple renders occur. ## Test Plan manual testing of above bug repro steps --- llama_stack/ui/hooks/usePagination.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/llama_stack/ui/hooks/usePagination.ts b/llama_stack/ui/hooks/usePagination.ts index 135754a77..55a8d4ac8 100644 --- a/llama_stack/ui/hooks/usePagination.ts +++ b/llama_stack/ui/hooks/usePagination.ts @@ -56,6 +56,9 @@ export function usePagination({ const stateRef = useRef(state); stateRef.current = state; + // Track if initial data has been fetched + const hasFetchedInitialData = useRef(false); + /** * Fetches data from the API with cursor-based pagination */ @@ -119,8 +122,11 @@ export function usePagination({ // Auto-load initial data on mount useEffect(() => { - fetchData(); - }, []); + if (!hasFetchedInitialData.current) { + hasFetchedInitialData.current = true; + fetchData(); + } + }, [fetchData]); return { data: state.data,