mirror of
https://github.com/outline/outline.git
synced 2026-06-13 11:25:03 +03:00
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.
This commit is contained in:
@@ -120,18 +120,20 @@ const PaginatedList = <T extends PaginatedItem>({
|
||||
!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 = <T extends PaginatedItem>({
|
||||
if (fetch) {
|
||||
void fetchResults();
|
||||
}
|
||||
}, [fetch]);
|
||||
}, [fetch, fetchResults]);
|
||||
|
||||
// Handle updates to fetch or options
|
||||
React.useEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user