Release 0.2.0 #4

Merged
dguiducci merged 96 commits from main into release 2026-08-17 18:07:20 +01:00
Showing only changes of commit f6f94e579d - Show all commits
+20 -2
View File
@@ -62,6 +62,23 @@ const MAX_DPR = 2;
let _pdfjsPromise = null; let _pdfjsPromise = null;
/**
* Tear a document down. pdf.js dropped `PDFDocumentProxy.destroy()` — the
* document is released through its loading task — and calling the absent method
* threw a TypeError out of `_teardown()`, which is called *first* in `_open()`:
* the page list had already been emptied, the rest of `_open()` never ran, and
* the viewer stayed blank for the rest of its life (every later src hit the same
* throw). That is what a file-watcher reload of an open PDF looked like. Hence
* also the swallow: releasing the previous document must never be able to stop
* the next one from loading.
*/
function destroyDoc(doc) {
try {
const p = doc?.loadingTask?.destroy();
if (p?.catch) p.catch(() => { /* already gone */ });
} catch { /* already gone */ }
}
/** Import pdf.js once per page load and point it at the vendored worker. */ /** Import pdf.js once per page load and point it at the vendored worker. */
function loadPdfjs() { function loadPdfjs() {
if (!_pdfjsPromise) { if (!_pdfjsPromise) {
@@ -131,7 +148,7 @@ export class PdfView extends LightElement {
standardFontDataUrl: STD_FONTS_URL, standardFontDataUrl: STD_FONTS_URL,
}).promise; }).promise;
// A newer src landed while we were loading — drop this one on the floor. // A newer src landed while we were loading — drop this one on the floor.
if (seq !== this._loadSeq) { doc.destroy(); return; } if (seq !== this._loadSeq) { destroyDoc(doc); return; }
this._pdfjs = pdfjs; this._pdfjs = pdfjs;
this._doc = doc; this._doc = doc;
this._total = doc.numPages; this._total = doc.numPages;
@@ -186,8 +203,9 @@ export class PdfView extends LightElement {
for (const slot of this._slots) this._release(slot); for (const slot of this._slots) this._release(slot);
this._slots = []; this._slots = [];
this.querySelector('.pdfv-pages')?.replaceChildren(); this.querySelector('.pdfv-pages')?.replaceChildren();
this._doc?.destroy(); const doc = this._doc;
this._doc = null; this._doc = null;
destroyDoc(doc);
this._lastWidth = 0; this._lastWidth = 0;
} }