From 984039edcea65f11e660c860382fdc7ab54f8125 Mon Sep 17 00:00:00 2001 From: Sam Becker Date: Sun, 26 Oct 2025 10:21:12 -0500 Subject: [PATCH] Make infinite scroll pagination more precise --- src/photo/InfinitePhotoScroll.tsx | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/photo/InfinitePhotoScroll.tsx b/src/photo/InfinitePhotoScroll.tsx index 8a892fda..6579e0c2 100644 --- a/src/photo/InfinitePhotoScroll.tsx +++ b/src/photo/InfinitePhotoScroll.tsx @@ -109,7 +109,7 @@ export default function InfinitePhotoScroll({ focal, ]); - const { data, isLoading, isValidating, error, mutate, size, setSize } = + const { data, isLoading, isValidating, error, mutate, setSize } = useSwrInfinite( keyGenerator, fetcher, @@ -137,9 +137,9 @@ export default function InfinitePhotoScroll({ const advance = useCallback(() => { if (!isFinished && !isLoadingOrValidating) { - setSize(size => size + 1); + setSize((data?.length ?? 0) + 1); } - }, [isFinished, isLoadingOrValidating, setSize]); + }, [isFinished, isLoadingOrValidating, setSize, data]); const revalidatePhoto: RevalidatePhoto = useCallback(( photoId: string, @@ -152,11 +152,7 @@ export default function InfinitePhotoScroll({ }, } as any), [data, mutate]); - useVisibility({ ref: buttonContainerRef, onVisible: () => { - if (ADMIN_DB_OPTIMIZE_ENABLED && size === 0) { - advance(); - } - }}); + useVisibility({ ref: buttonContainerRef, onVisible: advance }); const renderMoreButton =