diff --git a/CLAUDE.md b/CLAUDE.md index 773ccc8..bd42413 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -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 `` 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 diff --git a/frontend/src/composables/usePdfViewer.js b/frontend/src/composables/usePdfViewer.js index 6a3588b..6f248f0 100644 --- a/frontend/src/composables/usePdfViewer.js +++ b/frontend/src/composables/usePdfViewer.js @@ -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 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