From 894ea7114ce575497b6ffd3cde868da085470735 Mon Sep 17 00:00:00 2001 From: Froidefond Julien Date: Wed, 18 Mar 2026 13:25:42 +0100 Subject: [PATCH] fix: show spinner instead of broken image icon while loading reader pages Only render when blob URL is available from prefetch, preventing broken image icons from src={undefined} or failed direct URL fallbacks. Reset error state when blob URL arrives to recover from transient failures. Co-Authored-By: Claude Opus 4.6 --- src/components/reader/PhotoswipeReader.tsx | 2 - .../reader/components/PageDisplay.tsx | 43 ++++++++++--------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/components/reader/PhotoswipeReader.tsx b/src/components/reader/PhotoswipeReader.tsx index d061424..89d0907 100644 --- a/src/components/reader/PhotoswipeReader.tsx +++ b/src/components/reader/PhotoswipeReader.tsx @@ -265,9 +265,7 @@ export function PhotoswipeReader({ book, pages, onClose, nextBook }: BookReaderP isDoublePage={isDoublePage} shouldShowDoublePage={(page) => shouldShowDoublePage(page, pages.length)} imageBlobUrls={imageBlobUrls} - getPageUrl={getPageUrl} isRTL={isRTL} - isPageLoading={isPageLoading} /> boolean; imageBlobUrls: Record; - getPageUrl: (pageNum: number) => string; isRTL: boolean; - isPageLoading?: (pageNum: number) => boolean; } export function PageDisplay({ @@ -18,9 +16,7 @@ export function PageDisplay({ isDoublePage, shouldShowDoublePage, imageBlobUrls, - getPageUrl, isRTL, - isPageLoading, }: PageDisplayProps) { const [isLoading, setIsLoading] = useState(true); const [hasError, setHasError] = useState(false); @@ -53,6 +49,21 @@ export function PageDisplay({ setSecondPageHasError(false); }, [currentPage, isDoublePage]); + // Reset error state when blob URL becomes available + useEffect(() => { + if (imageBlobUrls[currentPage] && hasError) { + setHasError(false); + setIsLoading(true); + } + }, [imageBlobUrls[currentPage], currentPage, hasError]); + + useEffect(() => { + if (imageBlobUrls[currentPage + 1] && secondPageHasError) { + setSecondPageHasError(false); + setSecondPageLoading(true); + } + }, [imageBlobUrls[currentPage + 1], currentPage, secondPageHasError]); + return (
@@ -99,15 +110,12 @@ export function PageDisplay({ Image non disponible
- ) : ( + ) : imageBlobUrls[currentPage] ? ( <> {/* eslint-disable-next-line @next/next/no-img-element */} {`Page - )} + ) : null}
{/* Page 2 (double page) */} @@ -166,17 +174,12 @@ export function PageDisplay({ Image non disponible - ) : ( + ) : imageBlobUrls[currentPage + 1] ? ( <> {/* eslint-disable-next-line @next/next/no-img-element */} {`Page - )} + ) : null} )}