Skip to content

Commit 95307ce

Browse files
committed
Revert "⬆️ Bump pdfjs-dist from 5.3.31 to 6.1.200"
This reverts commit 5599550.
1 parent c770987 commit 95307ce

4 files changed

Lines changed: 66 additions & 152 deletions

File tree

app/components/PDFReader.vue

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@
286286
<script setup lang="ts">
287287
import type { DropdownMenuItem } from '@nuxt/ui'
288288
import type { RouteLocationRaw } from 'vue-router'
289-
import type { PDFDocumentLoadingTask, PDFDocumentProxy, PDFPageProxy, PageViewport } from 'pdfjs-dist'
289+
import type { PDFDocumentProxy, PDFPageProxy, PageViewport } from 'pdfjs-dist'
290290
import type { TextItem, TextMarkedContent } from 'pdfjs-dist/types/src/display/api'
291291
import type { ReaderLeftSidebarTab } from './ReaderLeftSidebar.props'
292292
import { ANNOTATION_TEXT_MAX_LENGTH } from '~~/shared/constants/annotations'
@@ -387,9 +387,6 @@ const scaleMenuItems = computed<DropdownMenuItem[]>(() => {
387387
})
388388
389389
const pdfDocument = shallowRef<PDFDocumentProxy>()
390-
// Tracked separately from pdfDocument so an in-flight getDocument() can be
391-
// canceled on reload/unmount; destroying the task also destroys the document.
392-
const pdfLoadingTask = shallowRef<PDFDocumentLoadingTask>()
393390
const textContentCache = new Map<number, Awaited<ReturnType<PDFPageProxy['getTextContent']>>>()
394391
const pageSearchTextCache = new Map<number, { raw: string, lower: string }>()
395392
const renderQueue = ref<(() => Promise<void>)[]>([])
@@ -610,8 +607,7 @@ onBeforeUnmount(() => {
610607
renderQueue.value = []
611608
textContentCache.clear()
612609
pageSearchTextCache.clear()
613-
pdfLoadingTask.value?.destroy().catch(() => {})
614-
pdfLoadingTask.value = undefined
610+
pdfDocument.value?.destroy()
615611
pdfDocument.value = undefined
616612
})
617613
@@ -676,24 +672,20 @@ async function loadPDF() {
676672
return
677673
}
678674
679-
pdfLoadingTask.value?.destroy().catch(() => {})
680-
pdfDocument.value = undefined
675+
if (pdfDocument.value) {
676+
pdfDocument.value.destroy()
677+
pdfDocument.value = undefined
678+
}
681679
682-
let loadingTask: PDFDocumentLoadingTask | undefined
683680
try {
684-
loadingTask = pdfjsLib.value.getDocument({
681+
const loadingTask = pdfjsLib.value.getDocument({
685682
data: props.pdfBuffer,
686683
wasmUrl: `https://cdn.jsdelivr.net/npm/pdfjs-dist@${pdfjsLib.value.version}/wasm/`,
687684
cMapUrl: `https://cdn.jsdelivr.net/npm/pdfjs-dist@${pdfjsLib.value.version}/cmaps/`,
688685
cMapPacked: true,
689686
})
690-
pdfLoadingTask.value = loadingTask
691-
692-
const doc = await loadingTask.promise
693-
// Superseded by a newer load or unmount while awaiting.
694-
if (pdfLoadingTask.value !== loadingTask) return
695687
696-
pdfDocument.value = doc
688+
pdfDocument.value = await loadingTask.promise
697689
totalPages.value = pdfDocument.value.numPages
698690
699691
outlineItems.value = []
@@ -706,8 +698,6 @@ async function loadPDF() {
706698
renderPages()
707699
}
708700
catch (error) {
709-
// Destroying a superseded task rejects its promise; not a real error.
710-
if (loadingTask && pdfLoadingTask.value !== loadingTask) return
711701
emit('error', error as Error)
712702
}
713703
}
@@ -922,13 +912,19 @@ async function renderPageToCanvas(
922912
const page = await pdfDocument.value.getPage(pageNum)
923913
const viewport = page.getViewport({ scale: scale.value })
924914
915+
const context = canvas.getContext('2d')
916+
if (!context) {
917+
page.cleanup()
918+
return
919+
}
920+
925921
canvas.height = viewport.height * pixelRatio.value
926922
canvas.width = viewport.width * pixelRatio.value
927923
canvas.style.width = `${viewport.width}px`
928924
canvas.style.height = `${viewport.height}px`
929925
930926
await page.render({
931-
canvas,
927+
canvasContext: context,
932928
transform: pixelRatio.value !== 1
933929
? [pixelRatio.value, 0, 0, pixelRatio.value, 0, 0]
934930
: undefined,

app/utils/parse-book-metadata.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,7 @@ export async function parsePDFMetadata(file: File): Promise<ParsedBookMetadata>
108108
return { title }
109109
}
110110
finally {
111-
// Best-effort teardown; a rejected destroy() must not surface as an
112-
// unhandled rejection or mask the parse result.
113-
doc.loadingTask.destroy().catch(() => {})
111+
doc.destroy()
114112
}
115113
}
116114

0 commit comments

Comments
 (0)