From 45f25408c62f87e4a2b73e270644fb2f1f79a290 Mon Sep 17 00:00:00 2001 From: Gauthier Date: Fri, 9 May 2025 13:15:05 +0200 Subject: [PATCH] fix(usediscover hook): detect end of pagination when totalSize is a multiple of pageSize (#1649) Fixes a crash on the `/discover/watchlist` page that occurred when the number of items was exactly a multiple of the page size (e.g., 80, 100, 120). The issue was caused by incorrect end-of-pagination detection, leading to infinite data fetching. This update adjusts the `isReachingEnd` condition to correctly handle these edge cases by checking if `totalResults` is less than or equal to the expected total based on `size * pageSize`. fix #1623 --- src/hooks/useDiscover.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/hooks/useDiscover.ts b/src/hooks/useDiscover.ts index b6eba1c28..4afaa90c0 100644 --- a/src/hooks/useDiscover.ts +++ b/src/hooks/useDiscover.ts @@ -138,6 +138,7 @@ const useDiscover = < const isReachingEnd = isEmpty || (!!data && (data[data?.length - 1]?.results.length ?? 0) < 20) || + (!!data && (data[data?.length - 1]?.totalResults ?? 0) <= size * 20) || (!!data && (data[data?.length - 1]?.totalResults ?? 0) < 41); return {