Skip to content

Commit 45f2540

Browse files
authored
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
1 parent 123894b commit 45f2540

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

src/hooks/useDiscover.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ const useDiscover = <
138138
const isReachingEnd =
139139
isEmpty ||
140140
(!!data && (data[data?.length - 1]?.results.length ?? 0) < 20) ||
141+
(!!data && (data[data?.length - 1]?.totalResults ?? 0) <= size * 20) ||
141142
(!!data && (data[data?.length - 1]?.totalResults ?? 0) < 41);
142143

143144
return {

0 commit comments

Comments
 (0)