From cc0d460f6b0eb726bbfb6f22a71563155845edec Mon Sep 17 00:00:00 2001 From: Richard R Date: Mon, 1 Jun 2026 04:54:12 -0600 Subject: [PATCH] fix pdf loader flash --- src/app/(app)/pdf/[id]/page.tsx | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/app/(app)/pdf/[id]/page.tsx b/src/app/(app)/pdf/[id]/page.tsx index 819e641..4b1f9af 100644 --- a/src/app/(app)/pdf/[id]/page.tsx +++ b/src/app/(app)/pdf/[id]/page.tsx @@ -39,6 +39,7 @@ const PDFViewer = dynamic( ); const PARSE_LOADER_EXPAND_DELAY_MS = 320; +const INITIAL_LOADER_DELAY_MS = 180; export default function PDFViewerPage() { const canExportAudiobook = useFeatureFlag('enableAudiobookExport'); @@ -70,6 +71,7 @@ export default function PDFViewerPage() { const [activeSidebar, setActiveSidebar] = useState(null); const [showForceReparseConfirm, setShowForceReparseConfirm] = useState(false); const [showDetailedParseLoader, setShowDetailedParseLoader] = useState(false); + const [showInitialLoader, setShowInitialLoader] = useState(false); const [containerHeight, setContainerHeight] = useState('auto'); const inFlightDocIdRef = useRef(null); const loadedDocIdRef = useRef(null); @@ -90,6 +92,7 @@ export default function PDFViewerPage() { setIsPdfViewerReady(false); setError(null); setActiveSidebar(null); + setShowInitialLoader(false); inFlightDocIdRef.current = null; loadedDocIdRef.current = null; }, [id]); @@ -155,6 +158,17 @@ export default function PDFViewerPage() { useUnmountCleanupRef(clearCurrDoc); + useEffect(() => { + if (!isLoading) { + setShowInitialLoader(false); + return; + } + const timeout = window.setTimeout(() => { + setShowInitialLoader(true); + }, INITIAL_LOADER_DELAY_MS); + return () => window.clearTimeout(timeout); + }, [isLoading, id]); + useEffect(() => { if (isLoading) return; if (isParseReady) return; @@ -281,6 +295,7 @@ export default function PDFViewerPage() { : 0; const hasMeasuredProgress = totalPages > 0; const isMerging = parseProgress?.phase === 'merge'; + const compactProgressWidth = hasMeasuredProgress ? `${progressPercent}%` : '24%'; let statusText = 'Loading PDF...'; let statusSubText = 'Initializing document renderer'; @@ -365,10 +380,11 @@ export default function PDFViewerPage() { -
- - - +
+
)} @@ -423,7 +439,7 @@ export default function PDFViewerPage() { />
) : null} - {isLoading || !isParseReady || !isPdfViewerReady ? ( + {(!isLoading || showInitialLoader) && (isLoading || !isParseReady || !isPdfViewerReady) ? (
{renderPdfStatusLoader()}