Repository navigation
fix(reader): render the PDF reader with the pdfjs legacy build - #129
Merged
Merged
Conversation
`pdfjs-dist` 6.3.289 calls `Map.prototype.getOrInsertComputed` (and
`getOrInsert`) throughout the API build and the worker, but those shipped in
Chromium 145 and Electron 39 is Chromium 142. The renderer imported the modern
build, so the first `page.render()` threw
TypeError: this[#methodPromises].getOrInsertComputed is not a function
from `WorkerTransport.getOptionalContentConfig`, and every page painted blank.
The main-process loader already imports `pdfjs-dist/legacy/build/pdf.mjs`, whose
core-js polyfills install those methods, so text extraction was unaffected while
the reader was broken.
Point the reader and its worker at the same legacy build. Switch back to
`pdfjs-dist/build/*` once the app runs on Chromium >= 145.
The reader path slipped through #124 (the upgrade for #121), whose own message
records the rendering path as unverified manual QA. `test/pdfjsScriptingBoundary.test.ts`
now fails if any source file imports the modern build, and its self-check accepts
the legacy subpath.
Verified: `npm test` (271 pass), `npm run typecheck`, `npm run build`; the built
`out/renderer/assets/pdf.worker.min-*.mjs` carries the polyfill
(`target:"Map",proto:!0`) and the renderer bundle references that legacy worker.
The new guard was falsified by temporarily restoring the modern import, which
fails it as intended.
Not verified: canvas render, text-layer selection, bbox highlighting and zoom
under a real window - that needs manual QA, and is #125's job.
This was referenced Sep 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Makes the PDF reader actually render pages. The renderer now loads
pdfjs-distfrom its legacy build (pdfjs-dist/legacy/build/*) instead of the modern one, matching what the main-process loader has always done.Adds a CI guard so the modern build cannot be imported again while the app runs on Chromium < 145.
Why?
The v1.4 release QA (#125) found the reader canvas blank. The first Console error is decisive:
pdfjs-dist6.3.289 callsMap.prototype.getOrInsertComputed/getOrInsertthroughout the API build and the worker. That proposal only shipped in Chromium 145; Electron 39 is Chromium 142, so the call throws on the firstpage.render()and every page stays blank.The legacy build bundles the core-js polyfills for
Map/WeakMapgetOrInsert/getOrInsertComputed.PdfLoader(main process) already importspdfjs-dist/legacy/build/pdf.mjs, which is why PDF text extraction passed the packaged smoke test while rendering was broken.This slipped through #124 (the
pdfjs-distupgrade for #121): that commit's own message records the reader rendering path as unverified manual QA, and the reader was the only call site left on the modern build.Related issue
Related to #125. Related to #121 / #124 (the upgrade that introduced the regression).
What changed?
src/renderer/src/components/notebook/source/reader/PdfSourceReader.tsx: import the runtime and the worker frompdfjs-dist/legacy/build/*, with a comment on why and when to switch back (Chromium >= 145).test/pdfjsScriptingBoundary.test.ts: new test that fails if any source file imports the modern build (pdfjs-distorpdfjs-dist/build/*), while allowingimport type ... from 'pdfjs-dist'. Its self-check now accepts the legacy subpath.No dependency or
package.jsonchange; this only selects a different entry point of the same installed package.How was this tested?
npm run typecheck(node, web, test) - passnpm test- 271 pass, 0 fail (5/5 in the boundary suite)npm run build- passimport * as pdfjs from 'pdfjs-dist'makes it fail with the intended message, then it was reverted.out/renderer/assets/pdf.worker.min-*.mjscarries the polyfill (getOrInsertComputedandtarget:"Map",proto:!0), and the renderer bundle references that legacy worker asset by hash.Not verified here: canvas rendering, text-layer selection, bbox highlighting and zoom under a real window need a display. That is manual QA and belongs to #125. The reporter confirmed the reader now works locally.
Screenshots / recordings
getOrInsertComputed is not a functionfor every pageChecklist
npm run typecheckpasses.npm run buildpasses.Desktop / build changes