fix: close reader immediately while cancelling prefetches
All checks were successful
Deploy with Docker Compose / deploy (push) Successful in 2m21s

This commit is contained in:
2026-03-01 21:36:40 +01:00
parent fead5ff6a0
commit 4441c59584
3 changed files with 53 additions and 5 deletions

View File

@@ -34,6 +34,7 @@ export function PhotoswipeReader({ book, pages, onClose, nextBook }: BookReaderP
imageBlobUrls,
prefetchPages,
prefetchNextBook,
cancelAllPrefetches,
handleForceReload,
getPageUrl,
prefetchCount,
@@ -105,6 +106,14 @@ export function PhotoswipeReader({ book, pages, onClose, nextBook }: BookReaderP
]);
// Keyboard events
const handleCloseReader = useCallback(
(page: number) => {
cancelAllPrefetches();
onClose?.(page);
},
[cancelAllPrefetches, onClose]
);
useEffect(() => {
const handleKeyDown = (e: KeyboardEvent) => {
if (e.key === "ArrowLeft") {
@@ -123,7 +132,7 @@ export function PhotoswipeReader({ book, pages, onClose, nextBook }: BookReaderP
}
} else if (e.key === "Escape" && onClose) {
e.preventDefault();
onClose(currentPage);
handleCloseReader(currentPage);
}
};
@@ -132,7 +141,7 @@ export function PhotoswipeReader({ book, pages, onClose, nextBook }: BookReaderP
return () => {
window.removeEventListener("keydown", handleKeyDown);
};
}, [handleNextPage, handlePreviousPage, onClose, isRTL, currentPage]);
}, [handleNextPage, handlePreviousPage, onClose, isRTL, currentPage, handleCloseReader]);
const handleContainerClick = useCallback(
(e: React.MouseEvent) => {
@@ -173,7 +182,7 @@ export function PhotoswipeReader({ book, pages, onClose, nextBook }: BookReaderP
<ReaderContainer onContainerClick={handleContainerClick}>
<EndOfSeriesModal
show={showEndMessage}
onClose={onClose || (() => undefined)}
onClose={handleCloseReader}
currentPage={currentPage}
/>
@@ -183,7 +192,7 @@ export function PhotoswipeReader({ book, pages, onClose, nextBook }: BookReaderP
onPreviousPage={handlePreviousPage}
onNextPage={handleNextPage}
onPageChange={navigateToPage}
onClose={onClose}
onClose={handleCloseReader}
currentPage={currentPage}
totalPages={pages.length}
isDoublePage={isDoublePage}