From 886cc469bc96099cd944b202a5f48b46e5c50575 Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Tue, 31 Dec 2024 16:54:21 +0100 Subject: [PATCH] Fix TypeError when reaching scroll end in continuous pager When the end of the scrollable element is reached in the continuous reader, the last image is not visible anymore. Thus, the "firstVisibleImageIndex" is invalid and gets incorrectly used for the "isEndReached" case which results in an TypeError when trying to use the actual page via the index --- src/modules/reader/services/ReaderControls.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/modules/reader/services/ReaderControls.ts b/src/modules/reader/services/ReaderControls.ts index ef3b4b4a..d6ba231a 100644 --- a/src/modules/reader/services/ReaderControls.ts +++ b/src/modules/reader/services/ReaderControls.ts @@ -465,15 +465,17 @@ export class ReaderControls { const lastPage = imageRefs.current?.[imageRefs.current.length - 1]; const isEndReached = lastPage && isEndOfPageInViewport(lastPage, type, readingDirection); + if (firstVisibleImageIndex === -1) { + return; + } + // handle cases where the last page is too small to ever be the "firstVisibleImageIndex" if (isEndReached) { updateCurrentPageIndex(firstVisibleImageIndex, false, true); return; } - if (firstVisibleImageIndex !== -1) { - updateCurrentPageIndex(firstVisibleImageIndex, firstVisibleImageIndex !== lastPageIndex); - } + updateCurrentPageIndex(firstVisibleImageIndex, firstVisibleImageIndex !== lastPageIndex); } static useHandleClick(