mirror of
https://github.com/outline/outline.git
synced 2026-12-05 10:45:07 +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:
1 parent
ca5c51a712
commit
b0c2a53be2
1 file changed
+6
-4
@@ -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