Fix pdf.js pages staying blank until a zoom action

Reported: pages appeared blank/"a silhouette" on first load and
refresh, becoming visible only after hitting zoom.

Root cause: loadDocument() computed fitZoom/zoom correctly after
loading a PDF, but never actually called renderAllPages() - only
zoomIn/zoomOut/resetZoom do (via applyZoom), which is why touching zoom
"fixed" it. With nothing drawing into them, every <canvas> sat at the
browser's own unset-canvas default (300x150px), a small blank shadowed
rectangle. The render pipeline itself was never in question - already
proven correct by zoom successfully triggering it - this was purely a
sequencing bug.

Fixed with nextTick() before renderAllPages(): setting numPages only
queues the v-for's canvas elements, they don't exist in the DOM (so
canvasRefs stays empty) until Vue flushes that update, which nextTick
explicitly waits for.

Also investigated the separately reported "no longer see the other top
bar pdf options" - checked the zoom-controls row's own v-if and CSS,
found no second bug there. Most likely the same blank-canvas symptom
read as the whole panel looking broken; not confirmed as the same
issue, flagged to the user to check once this fix is live rather than
assumed resolved.

Verified: npm run build passes, the app container rebuilt. measure.py
unaffected. Not machine-verified - Claude-in-Chrome did not connect
this session.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
JasonFraser 2026-10-13 15:05:46 -04:00
parent 23bba7e760
commit 4c0973b6b5
2 changed files with 45 additions and 1 deletions

View File

@ -1476,6 +1476,39 @@ machine-verified: whether the modal now actually appears above everything and is
clickable from every call site (sidebar delete, document delete, move-to-project,
download choice) - Claude-in-Chrome still did not connect this session.
**A third `usePdfViewer.js` bug, found by the user's next real test: pages stayed blank
("a silhouette") until zoom was touched.** Root cause, confirmed by re-reading
`loadDocument()`'s own code: it computed `fitZoom`/`zoom` correctly after loading, but
**never actually called `renderAllPages()`** - only `zoomIn()`/`zoomOut()`/`resetZoom()`
do (via `applyZoom()`), which is exactly why touching zoom "fixed" it. With nothing ever
drawing into them, every `<canvas>` sat at the browser's own unset-canvas default
(300×150px) - a small, blank, shadowed rectangle, matching "silhouette" exactly. The
render pipeline itself was never in question here (already proven correct by the user's
own zoom test succeeding) - this was purely a sequencing bug, nothing called it at the
right time.
Fixed with `await nextTick(); await renderAllPages()` right after `numPages.value` is
set and zoom is computed - `nextTick()` is needed because setting `numPages` only
*queues* the `v-for`'s canvas elements; they don't exist in the DOM (so
`canvasRefs.value` stays empty) until Vue actually flushes that update, which
`nextTick()` explicitly waits for before `renderAllPages()` tries to draw into them.
**The user also reported no longer seeing "the other top bar pdf options" of the source
panel.** Checked the zoom-controls row's own gate (`v-if="previewUrl"`, unconditional on
file type or load state) and its CSS (`.img-zoom-controls{display:flex}`, no hidden
state) - found no second bug there. Most likely the same blank-canvas symptom read as
"the whole panel looks broken, including its header" rather than a literally separate
issue, but **not confirmed** - flagged to the user to confirm specifically once the
render fix is live, rather than assumed fixed by the same change.
Verified: `npm run build` passes; the `app` container rebuilt. `measure.py` unaffected
(no backend touched). The render pipeline this fix now actually calls on load was
already independently proven correct (the user's own zoom-triggered render worked) -
the fix itself is a well-understood, standard Vue `nextTick()`-before-acting-on-refs
pattern, not new rendering logic needing its own from-scratch verification. Not
machine-verified: whether pages now actually paint on first load without needing a
zoom nudge - Claude-in-Chrome still did not connect this session.
**Governing rule: never silently correct or exclude data.** This shows up in several
concrete places, not just as an abstract principle:
- A row with an unusual status (e.g. HSBC's "Cancelled" wires) stays in the output and is

View File

@ -20,7 +20,7 @@
* convention), matching a canvas's own pixel space - so overlay position
* is just `value * zoom`, no axis flip needed.
*/
import { ref, computed, shallowRef } from 'vue'
import { ref, computed, shallowRef, nextTick } from 'vue'
import * as pdfjsLib from 'pdfjs-dist'
import pdfWorkerUrl from 'pdfjs-dist/build/pdf.worker.mjs?url'
@ -126,6 +126,17 @@ export function usePdfViewer() {
const widest = Math.max(...pageViewports.map((v) => v.width))
fitZoom.value = wrap && widest ? Math.min(1.5, wrap.clientWidth / widest) : 1
zoom.value = fitZoom.value
// Setting numPages above only queues the v-for's <canvas> elements
// to be created - they don't exist in the DOM (so canvasRefs is
// still empty) until Vue actually flushes that update, which
// nextTick waits for. Skipping this was the real bug behind "blank
// until you zoom" - zoomIn/zoomOut happened to call
// renderAllPages() themselves (via applyZoom), but nothing ever
// did on the initial load, so every canvas sat at the browser's
// default 300x150 size with nothing ever drawn into it until a
// zoom action incidentally triggered the first real render.
await nextTick()
await renderAllPages()
} catch (e) {
loadError.value = e?.message || 'Could not load this PDF.'
numPages.value = 0