Repository navigation
UN-4502 [DEV] Add the v1 PDF loader, document hook and viewer states - #2404
muhammad-ali-e wants to merge 7 commits into
Conversation
…states - lib/pdf/pdfjs.ts is the only v1 import of pdf.js: the existing pdfjs-dist 3.11.174 legacy build, its worker bundled with ?url, both loaded on first use. getDocument always gets isEvalSupported: false (CVE-2024-4367), and in-memory bytes are copied before the worker transfer empties them. - Page sizes are read in parallel, bounded at 16 in flight. - hooks/usePdfDocument tracks empty, loading, password (missing or wrong), unsupported, failed (with Retry) and ready. It reopens only when the source's URL, request options or bytes change, and destroys the previous load on change and on unmount. - components/patterns/document-viewer/ViewerStatus renders every state except ready. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01R7trgcAzu6jxDnit3eeozm
|
The failing hook is There's no fix to port yet. The fix is a one-line change on #2399: Generated by Claude Code |
pdf.js puts the full URL in MissingPDFException and UnexpectedResponseException messages, so a signed URL's token reached the screen. Build those messages from the status instead. Also cover the reset that lets Retry load pdf.js again after a failed chunk. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01R7trgcAzu6jxDnit3eeozm
[Medium impact] The reviewed changes appear safe to merge.
|
Submitting swaps the prompt for the loading state, so the field lost focus and a keyboard user had to find it again. Raised by Greptile on #2404. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01R7trgcAzu6jxDnit3eeozm
praveen-formido
left a comment
There was a problem hiding this comment.
Reviewed as the base of the stack (lens: v1 styles and tokens, plus the loader logic). On the stack tip (68af05717) typecheck:v1, lint:v1 and the 173 v1 tests pass, and the current check-v1-styles.mjs from #2399 reports clean, so the --*-only style objects are fine throughout.
Two things I would fix before this goes in: the password/retry path re-downloads the document (comment on usePdfDocument.ts), and the legacy pdf.js build puts a second engine and worker in the bundle (comment on pdfjs.ts). The rest are smaller.
Stack note: these five fork from #2399 at 8028a7320, before its last commits. Once #2399 merges they retarget to main and need a rebase onto it (for example git rebase --onto main 8028a7320 from the bottom of the stack), otherwise the diffs keep showing the #2399 commits.
…iling the open From review on #2404: - A password goes to pdf.js's onPassword callback on the live loading task, so a password (right or wrong) no longer downloads the file again or starts a new worker, and Retry carries no stale password. - A page whose size cannot be read borrows a neighbour's size and is logged; only a document with no readable page fails to open. - An unknown pdf.js error shows a plain message and is logged, instead of showing pdf.js's own wording. - destroy() handles the rejection pdf.js gives when the worker is gone. - The hook's request type is OpenRequest, not a shadow of fetch's Request. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01R7trgcAzu6jxDnit3eeozm
Dismissed because a newer commit was pushed; Greptile will re-review the current head.
…uild The legacy build put a second pdf.js engine and worker next to v0's. v1 now imports pdfjs-dist and its default worker, the copy v0 already ships. Also hands the rejected destroy promise in the loader test a handler up front, so Vitest no longer reports it as an unhandled rejection while the test waits. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01R7trgcAzu6jxDnit3eeozm
Dismissed because a newer commit was pushed; Greptile will re-review the current head.
|



What
src/v1/lib/pdf/pdfjs.tsandtypes.ts: the only place v1 imports pdf.js.src/v1/hooks/usePdfDocument.ts: opens a PDF and tracks it through each state.src/v1/components/patterns/document-viewer/ViewerStatus.tsx: renders every state exceptready. The page list rendersready(UN-4503).First of the P1-T21 DocumentViewer sub-tasks (UN-4390).
Why
Six v1 page tasks need one document viewer. This PR is its foundation: one way to load a PDF, with the security defaults set once.
How
pdfjs-dist@3.11.174already inpackage.json, as Jaseem asked: one pdf.js for the whole frontend.?url, never fetched from a CDN.getDocumentalways getsisEvalSupported: false(CVE-2024-4367; 3.x has no other fix).{kind: "url", url, withCredentials?, httpHeaders?}or{kind: "data", data}. In-memory bytes are copied first, because pdf.js transfers its buffer to the worker and would empty the caller's copy before a Retry.usePdfDocument(source)returns{state, retry, submitPassword}.stateis one of:empty,loading,password(with anincorrectflag),unsupported,failed(with its message) orready(documentandpageSizes).PasswordExceptioncode 1 = password needed, code 2 = wrong passwordInvalidPDFException= unsupportedui:tokens only. There's no core Button yet, so these are plain elements with the focus ring. They'll swap to the core component once it exists.Can this PR break any existing features. If yes, please list possible items. If no, please explain why. (PS: Admins do not merge the PR without this section filled)
src/v1/, and nothing in v0 or the v1 entry imports it yet. There are no package or config changes, and v0's pdf.js setup is untouched. v1 shares v0's pdf.js module and sets the sameGlobalWorkerOptions.workerSrc(the bundledpdf.worker.min.jsURL), so loading either one first leaves the other working.Database Migrations
Env Config
Relevant Docs
Related Issues or PRs
mainonce both merge.Dependencies Versions
pdfjs-dist@3.11.174.Notes on Testing
bun run typecheck:v1,bun run lint:v1andbun run test:v1pass: 65 unit tests and 56 boundary fixtures.biome ci src/reports no errors.Screenshots
Checklist
I have read and understood the Contribution Guidelines.
Generated by Claude Code