From b0c2a53be2e2fd4a171aa7cb6f304ac4dc038b3a Mon Sep 17 00:00:00 2001 From: "codegen-sh[bot]" <131295404+codegen-sh[bot]@users.noreply.github.com> Date: Mon, 23 Jun 2025 20:49:00 +0000 Subject: [PATCH] fix: Initialize renderCount with existing items length in PaginatedList The functional component conversion in PR #9030 introduced a bug where renderCount was always initialized to defaultLimit, causing only the first defaultLimit items to render on initial load when items were already available (e.g., from cached store data). This fix ensures renderCount is initialized to the maximum of existing items length or defaultLimit, allowing all available items to render on first load while maintaining the pagination behavior. --- app/components/PaginatedList.tsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/components/PaginatedList.tsx b/app/components/PaginatedList.tsx index 8f2b619e88..8027d809a5 100644 --- a/app/components/PaginatedList.tsx +++ b/app/components/PaginatedList.tsx @@ -120,18 +120,20 @@ const PaginatedList = ({ !items?.length ); const [fetchCounter, setFetchCounter] = React.useState(0); - const [renderCount, setRenderCount] = React.useState(Pagination.defaultLimit); + const [renderCount, setRenderCount] = React.useState( + Math.max(items?.length ?? 0, Pagination.defaultLimit) + ); const [offset, setOffset] = React.useState(0); const [allowLoadMore, setAllowLoadMore] = React.useState(true); const reset = React.useCallback(() => { setOffset(0); setAllowLoadMore(true); - setRenderCount(Pagination.defaultLimit); + setRenderCount(Math.max(items?.length ?? 0, Pagination.defaultLimit)); setIsFetching(false); setIsFetchingInitial(false); setIsFetchingMore(false); - }, []); + }, [items?.length]); const fetchResults = React.useCallback(async () => { if (!fetch) { @@ -206,7 +208,7 @@ const PaginatedList = ({ if (fetch) { void fetchResults(); } - }, [fetch]); + }, [fetch, fetchResults]); // Handle updates to fetch or options React.useEffect(() => {