Fix scroll position lost after PDF zoom re-render
All checks were successful
Build and push Docker image / build (push) Successful in 14s
Test / test (push) Successful in 16s

Scroll position was restored before browser finished layout, so
scrollHeight was still wrong. Now waits two animation frames after
reRenderPdf completes before restoring position.

Also shows loading overlay during zoom re-renders, not just on initial load.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
marwin 2026-04-05 18:44:49 +02:00
parent 89cb70392a
commit 20a1b9a889

View file

@ -3712,6 +3712,9 @@ async function applyPdfZoom(newZoom) {
pdfSmartZoomPage(pdfCurrentPage); pdfSmartZoomPage(pdfCurrentPage);
} else { } else {
await reRenderPdf(); await reRenderPdf();
// Wait for two animation frames so the browser finishes layout
// before reading scrollHeight for position restoration
await new Promise(r => requestAnimationFrame(() => requestAnimationFrame(r)));
if (contentEl2 && fraction > 0) { if (contentEl2 && fraction > 0) {
contentEl2.scrollTop = fraction * (contentEl2.scrollHeight - contentEl2.clientHeight); contentEl2.scrollTop = fraction * (contentEl2.scrollHeight - contentEl2.clientHeight);
} }
@ -3722,7 +3725,13 @@ async function reRenderPdf() {
if (!currentPdfBuffer) return; if (!currentPdfBuffer) return;
const contentEl = $('reader-content'); const contentEl = $('reader-content');
if (!contentEl) return; if (!contentEl) return;
const overlay = $('reader-overlay');
const loadingEl = document.createElement('div');
loadingEl.className = 'pdf-loading-overlay';
loadingEl.innerHTML = '<span class="pdf-loading-spinner"></span>';
if (overlay) overlay.appendChild(loadingEl);
await renderPdf(currentPdfBuffer, contentEl); await renderPdf(currentPdfBuffer, contentEl);
loadingEl.remove();
if (readerSettings.pdfPaginated) enterPdfPaginatedMode(); if (readerSettings.pdfPaginated) enterPdfPaginatedMode();
} }