Revert "Upgrade PDF.js to v5 (#24646)" (#24946)

This reverts commit 3ef46af6363aab5b5b007b6c9d72decae65a36ab.

GitOrigin-RevId: 9c3671b3ff196bb62ff547210a1138cb603d6791
This commit is contained in:
Alf Eaton
2025-04-16 11:44:22 +01:00
committed by Copybot
parent 282cbcc415
commit 2fd8afbe94
8 changed files with 71 additions and 109 deletions

96
package-lock.json generated
View File

@@ -6991,9 +6991,9 @@
]
},
"node_modules/@napi-rs/canvas": {
"version": "0.1.68",
"resolved": "https://registry.npmjs.org/@napi-rs/canvas/-/canvas-0.1.68.tgz",
"integrity": "sha512-LQESrePLEBLvhuFkXx9jjBXRC2ClYsO5mqQ1m/puth5z9SOuM3N/B3vDuqnC3RJFktDktyK9khGvo7dTkqO9uQ==",
"version": "0.1.65",
"resolved": "https://registry.npmjs.org/@napi-rs/canvas/-/canvas-0.1.65.tgz",
"integrity": "sha512-YcFhXQcp+b2d38zFOJNbpyPHnIL7KAEkhJQ+UeeKI5IpE9B8Cpf/M6RiHPQXSsSqnYbrfFylnW49dyh2oeSblQ==",
"dev": true,
"license": "MIT",
"optional": true,
@@ -7001,22 +7001,22 @@
"node": ">= 10"
},
"optionalDependencies": {
"@napi-rs/canvas-android-arm64": "0.1.68",
"@napi-rs/canvas-darwin-arm64": "0.1.68",
"@napi-rs/canvas-darwin-x64": "0.1.68",
"@napi-rs/canvas-linux-arm-gnueabihf": "0.1.68",
"@napi-rs/canvas-linux-arm64-gnu": "0.1.68",
"@napi-rs/canvas-linux-arm64-musl": "0.1.68",
"@napi-rs/canvas-linux-riscv64-gnu": "0.1.68",
"@napi-rs/canvas-linux-x64-gnu": "0.1.68",
"@napi-rs/canvas-linux-x64-musl": "0.1.68",
"@napi-rs/canvas-win32-x64-msvc": "0.1.68"
"@napi-rs/canvas-android-arm64": "0.1.65",
"@napi-rs/canvas-darwin-arm64": "0.1.65",
"@napi-rs/canvas-darwin-x64": "0.1.65",
"@napi-rs/canvas-linux-arm-gnueabihf": "0.1.65",
"@napi-rs/canvas-linux-arm64-gnu": "0.1.65",
"@napi-rs/canvas-linux-arm64-musl": "0.1.65",
"@napi-rs/canvas-linux-riscv64-gnu": "0.1.65",
"@napi-rs/canvas-linux-x64-gnu": "0.1.65",
"@napi-rs/canvas-linux-x64-musl": "0.1.65",
"@napi-rs/canvas-win32-x64-msvc": "0.1.65"
}
},
"node_modules/@napi-rs/canvas-android-arm64": {
"version": "0.1.68",
"resolved": "https://registry.npmjs.org/@napi-rs/canvas-android-arm64/-/canvas-android-arm64-0.1.68.tgz",
"integrity": "sha512-h1KcSR4LKLfRfzeBH65xMxbWOGa1OtMFQbCMVlxPCkN1Zr+2gK+70pXO5ktojIYcUrP6KDcOwoc8clho5ccM/w==",
"version": "0.1.65",
"resolved": "https://registry.npmjs.org/@napi-rs/canvas-android-arm64/-/canvas-android-arm64-0.1.65.tgz",
"integrity": "sha512-ZYwqFYEKcT5Zr8lbiaJNJj/poLaeK2TncolY914r+gD2TJNeP7ZqvE7A2SX/1C9MB4E3DQEwm3YhL3WEf0x3MQ==",
"cpu": [
"arm64"
],
@@ -7031,9 +7031,9 @@
}
},
"node_modules/@napi-rs/canvas-darwin-arm64": {
"version": "0.1.68",
"resolved": "https://registry.npmjs.org/@napi-rs/canvas-darwin-arm64/-/canvas-darwin-arm64-0.1.68.tgz",
"integrity": "sha512-/VURlrAD4gDoxW1GT/b0nP3fRz/fhxmHI/xznTq2FTwkQLPOlLkDLCvTmQ7v6LtGKdc2Ed6rvYpRan+JXThInQ==",
"version": "0.1.65",
"resolved": "https://registry.npmjs.org/@napi-rs/canvas-darwin-arm64/-/canvas-darwin-arm64-0.1.65.tgz",
"integrity": "sha512-Pg1pfiJEyDIsX+V0QaJPRWvXbw5zmWAk3bivFCvt/5pwZb37/sT6E/RqPHT9NnqpDyKW6SriwY9ypjljysUA1Q==",
"cpu": [
"arm64"
],
@@ -7048,9 +7048,9 @@
}
},
"node_modules/@napi-rs/canvas-darwin-x64": {
"version": "0.1.68",
"resolved": "https://registry.npmjs.org/@napi-rs/canvas-darwin-x64/-/canvas-darwin-x64-0.1.68.tgz",
"integrity": "sha512-tEpvGR6vCLTo1Tx9wmDnoOKROpw57wiCWwCpDOuVlj/7rqEJOUYr9ixW4aRJgmeGBrZHgevI0EURys2ER6whmg==",
"version": "0.1.65",
"resolved": "https://registry.npmjs.org/@napi-rs/canvas-darwin-x64/-/canvas-darwin-x64-0.1.65.tgz",
"integrity": "sha512-3Tr+/HjdJN7Z/VKIcsxV2DvDIibZCExgfYTgljCkUSFuoI7iNkOE6Dc1Q6j212EB9PeO8KmfrViBqHYT6IwWkA==",
"cpu": [
"x64"
],
@@ -7065,9 +7065,9 @@
}
},
"node_modules/@napi-rs/canvas-linux-arm-gnueabihf": {
"version": "0.1.68",
"resolved": "https://registry.npmjs.org/@napi-rs/canvas-linux-arm-gnueabihf/-/canvas-linux-arm-gnueabihf-0.1.68.tgz",
"integrity": "sha512-U9xbJsumPOiAYeAFZMlHf62b9dGs2HJ6Q5xt7xTB0uEyPeurwhgYBWGgabdsEidyj38YuzI/c3LGBbSQB3vagw==",
"version": "0.1.65",
"resolved": "https://registry.npmjs.org/@napi-rs/canvas-linux-arm-gnueabihf/-/canvas-linux-arm-gnueabihf-0.1.65.tgz",
"integrity": "sha512-3KP+dYObH7CVkZMZWwk1WX9jRjL+EKdQtD43H8MOI+illf+dwqLlecdQ4d9bQRIxELKJ8dyPWY4fOp/Ngufrdg==",
"cpu": [
"arm"
],
@@ -7082,9 +7082,9 @@
}
},
"node_modules/@napi-rs/canvas-linux-arm64-gnu": {
"version": "0.1.68",
"resolved": "https://registry.npmjs.org/@napi-rs/canvas-linux-arm64-gnu/-/canvas-linux-arm64-gnu-0.1.68.tgz",
"integrity": "sha512-KFkn8wEm3mPnWD4l8+OUUkxylSJuN5q9PnJRZJgv15RtCA1bgxIwTkBhI/+xuyVMcHqON9sXq7cDkEJtHm35dg==",
"version": "0.1.65",
"resolved": "https://registry.npmjs.org/@napi-rs/canvas-linux-arm64-gnu/-/canvas-linux-arm64-gnu-0.1.65.tgz",
"integrity": "sha512-Ka3StKz7Dq7kjTF3nNJCq43UN/VlANS7qGE3dWkn1d+tQNsCRy/wRmyt1TUFzIjRqcTFMQNRbgYq84+53UBA0A==",
"cpu": [
"arm64"
],
@@ -7099,9 +7099,9 @@
}
},
"node_modules/@napi-rs/canvas-linux-arm64-musl": {
"version": "0.1.68",
"resolved": "https://registry.npmjs.org/@napi-rs/canvas-linux-arm64-musl/-/canvas-linux-arm64-musl-0.1.68.tgz",
"integrity": "sha512-IQzts91rCdOALXBWQxLZRCEDrfFTGDtNRJMNu+2SKZ1uT8cmPQkPwVk5rycvFpvgAcmiFiOSCp1aRrlfU8KPpQ==",
"version": "0.1.65",
"resolved": "https://registry.npmjs.org/@napi-rs/canvas-linux-arm64-musl/-/canvas-linux-arm64-musl-0.1.65.tgz",
"integrity": "sha512-O4xMASm2JrmqYoiDyxVWi+z5C14H+oVEag2rZ5iIA67dhWqYZB+iO7wCFpBYRj31JPBR29FOsu6X9zL+DwBFdw==",
"cpu": [
"arm64"
],
@@ -7116,9 +7116,9 @@
}
},
"node_modules/@napi-rs/canvas-linux-riscv64-gnu": {
"version": "0.1.68",
"resolved": "https://registry.npmjs.org/@napi-rs/canvas-linux-riscv64-gnu/-/canvas-linux-riscv64-gnu-0.1.68.tgz",
"integrity": "sha512-e9AS5UttoIKqXSmBzKZdd3NErSVyOEYzJfNOCGtafGk1//gibTwQXGlSXmAKuErqMp09pyk9aqQRSYzm1AQfBw==",
"version": "0.1.65",
"resolved": "https://registry.npmjs.org/@napi-rs/canvas-linux-riscv64-gnu/-/canvas-linux-riscv64-gnu-0.1.65.tgz",
"integrity": "sha512-dblWDaA59ZU8bPbkfM+riSke7sFbNZ70LEevUdI5rgiFEUzYUQlU34gSBzemTACj5rCWt1BYeu0GfkLSjNMBSw==",
"cpu": [
"riscv64"
],
@@ -7133,9 +7133,9 @@
}
},
"node_modules/@napi-rs/canvas-linux-x64-gnu": {
"version": "0.1.68",
"resolved": "https://registry.npmjs.org/@napi-rs/canvas-linux-x64-gnu/-/canvas-linux-x64-gnu-0.1.68.tgz",
"integrity": "sha512-Pa/I36VE3j57I3Obhrr+J48KGFfkZk2cJN/2NmW/vCgmoF7kCP6aTVq5n+cGdGWLd/cN9CJ9JvNwEoMRDghu0g==",
"version": "0.1.65",
"resolved": "https://registry.npmjs.org/@napi-rs/canvas-linux-x64-gnu/-/canvas-linux-x64-gnu-0.1.65.tgz",
"integrity": "sha512-wsp+atutw13OJXGU3DDkdngtBDoEg01IuK5xMe0L6VFPV8maGkh17CXze078OD5QJOc6kFyw3DDscMLOPF8+oA==",
"cpu": [
"x64"
],
@@ -7150,9 +7150,9 @@
}
},
"node_modules/@napi-rs/canvas-linux-x64-musl": {
"version": "0.1.68",
"resolved": "https://registry.npmjs.org/@napi-rs/canvas-linux-x64-musl/-/canvas-linux-x64-musl-0.1.68.tgz",
"integrity": "sha512-9c6rkc5195wNxuUHJdf4/mmnq433OQey9TNvQ9LspJazvHbfSkTij8wtKjASVQsJyPDva4fkWOeV/OQ7cLw0GQ==",
"version": "0.1.65",
"resolved": "https://registry.npmjs.org/@napi-rs/canvas-linux-x64-musl/-/canvas-linux-x64-musl-0.1.65.tgz",
"integrity": "sha512-odX+nN+IozWzhdj31INcHz3Iy9+EckNw+VqsZcaUxZOTu7/3FmktRNI6aC1qe5minZNv1m05YOS1FVf7fvmjlA==",
"cpu": [
"x64"
],
@@ -7167,9 +7167,9 @@
}
},
"node_modules/@napi-rs/canvas-win32-x64-msvc": {
"version": "0.1.68",
"resolved": "https://registry.npmjs.org/@napi-rs/canvas-win32-x64-msvc/-/canvas-win32-x64-msvc-0.1.68.tgz",
"integrity": "sha512-Fc5Dez23u0FoSATurT6/w1oMytiRnKWEinHivdMvXpge6nG4YvhrASrtqMk8dGJMVQpHr8QJYF45rOrx2YU2Aw==",
"version": "0.1.65",
"resolved": "https://registry.npmjs.org/@napi-rs/canvas-win32-x64-msvc/-/canvas-win32-x64-msvc-0.1.65.tgz",
"integrity": "sha512-RZQX3luWnlNWgdMnLMQ1hyfQraeAn9lnxWWVCHuUM4tAWEV8UDdeb7cMwmJW7eyt8kAosmjeHt3cylQMHOxGFg==",
"cpu": [
"x64"
],
@@ -31952,16 +31952,16 @@
}
},
"node_modules/pdfjs-dist": {
"version": "5.1.91",
"resolved": "https://registry.npmjs.org/pdfjs-dist/-/pdfjs-dist-5.1.91.tgz",
"integrity": "sha512-qSIADdagooJB4wWCBnrBJjRvASevmxL0BwafvOuKJG5uTQdYoFBrhrRYnucKNiSc9qS6JIk0hC5y1yktFljXkA==",
"version": "4.10.38",
"resolved": "https://registry.npmjs.org/pdfjs-dist/-/pdfjs-dist-4.10.38.tgz",
"integrity": "sha512-/Y3fcFrXEAsMjJXeL9J8+ZG9U01LbuWaYypvDW2ycW1jL269L3js3DVBjDJ0Up9Np1uqDXsDrRihHANhZOlwdQ==",
"dev": true,
"license": "Apache-2.0",
"engines": {
"node": ">=20"
},
"optionalDependencies": {
"@napi-rs/canvas": "^0.1.67"
"@napi-rs/canvas": "^0.1.65"
}
},
"node_modules/pend": {
@@ -44564,7 +44564,7 @@
"nock": "^13.5.6",
"nvd3": "^1.8.6",
"overleaf-editor-core": "*",
"pdfjs-dist": "5.1.91",
"pdfjs-dist": "4.10.38",
"pirates": "^4.0.1",
"postcss": "^8.4.31",
"postcss-loader": "^7.3.3",

View File

@@ -1,22 +0,0 @@
diff --git a/node_modules/pdfjs-dist/build/pdf.worker.mjs b/node_modules/pdfjs-dist/build/pdf.worker.mjs
index 6c5c6f1..bb6b7d1 100644
--- a/node_modules/pdfjs-dist/build/pdf.worker.mjs
+++ b/node_modules/pdfjs-dist/build/pdf.worker.mjs
@@ -1830,7 +1830,7 @@ async function __wbg_init(module_or_path) {
}
}
if (typeof module_or_path === 'undefined') {
- module_or_path = new URL('qcms_bg.wasm', import.meta.url);
+ module_or_path = new URL(/* webpackIgnore: true */ 'qcms_bg.wasm', import.meta.url);
}
const imports = __wbg_get_imports();
if (typeof module_or_path === 'string' || typeof Request === 'function' && module_or_path instanceof Request || typeof URL === 'function' && module_or_path instanceof URL) {
@@ -5358,7 +5358,7 @@ var OpenJPEG = (() => {
if (Module["locateFile"]) {
return locateFile("openjpeg.wasm");
}
- return new URL("openjpeg.wasm", import.meta.url).href;
+ return new URL(/* webpackIgnore: true */ "openjpeg.wasm", import.meta.url).href;
}
function getBinarySync(file) {
if (file == wasmBinaryFile && wasmBinary) {

View File

@@ -168,10 +168,10 @@ function PdfJsViewer({ url, pdfFile }: PdfJsViewerProps) {
setStartFetch(performance.now())
const abortController = new AbortController()
const handleFetchError = (err: any) => {
const handleFetchError = (err: Error) => {
if (abortController.signal.aborted) return
// The error is already logged at the call-site with additional context.
if (err instanceof PDFJS.ResponseException && err.missing) {
if (err instanceof PDFJS.MissingPDFException) {
setError('rendering-error-expected')
} else {
setError('rendering-error')

View File

@@ -149,11 +149,14 @@ export function generatePdfCachingTransportFactory() {
return blob
})
.catch(err => {
const { statusCode, url } = OError.getFullInfo(err)
throw OError.tag(
new PDFJS.ResponseException(undefined, statusCode, true),
new PDFJS.MissingPDFException(),
'cache-fallback',
{ statusCode, url, err }
{
statusCode: OError.getFullInfo(err).statusCode,
url: OError.getFullInfo(err).url,
err,
}
)
})
}
@@ -185,12 +188,11 @@ export function generatePdfCachingTransportFactory() {
metrics.failedCount++
metrics.failedOnce = true
}
const { statusCode, url } = OError.getFullInfo(err)
throw OError.tag(
new PDFJS.ResponseException(undefined, statusCode, true),
'caching',
{ statusCode, url, err }
)
throw OError.tag(new PDFJS.MissingPDFException(), 'caching', {
statusCode: OError.getFullInfo(err).statusCode,
url: OError.getFullInfo(err).url,
err,
})
}
metrics.failedCount++
metrics.failedOnce = true
@@ -214,12 +216,11 @@ export function generatePdfCachingTransportFactory() {
}).catch(err => {
if (canTryFromCache(err)) return fetchFromCache()
if (isExpectedError(err)) {
const { statusCode, url } = OError.getFullInfo(err)
throw OError.tag(
new PDFJS.ResponseException(undefined, statusCode, true),
'fallback',
{ statusCode, url, err }
)
throw OError.tag(new PDFJS.MissingPDFException(), 'fallback', {
statusCode: OError.getFullInfo(err).statusCode,
url: OError.getFullInfo(err).url,
err,
})
}
throw err
})
@@ -232,7 +233,7 @@ export function generatePdfCachingTransportFactory() {
if (abortSignal.aborted) return
err = OError.tag(err, 'fatal pdf download error', getDebugInfo())
debugConsole.error(err)
if (!(err instanceof PDFJS.ResponseException && err.missing)) {
if (!(err instanceof PDFJS.MissingPDFException)) {
captureException(err, {
tags: {
fromPdfCaching: true,

View File

@@ -57,7 +57,7 @@ export default class PDFJSWrapper {
url: string
pdfFile: Record<string, any>
abortController: AbortController
handleFetchError: (error: any) => void
handleFetchError: (error: Error) => void
}) {
this.url = url
@@ -90,10 +90,7 @@ export default class PDFJSWrapper {
return doc
} catch (error: any) {
if (
!error ||
!(error instanceof PDFJS.ResponseException && error.missing === true)
) {
if (!error || error.name !== 'MissingPDFException') {
captureException(error, {
tags: { handler: 'pdf-preview' },
})

View File

@@ -10,8 +10,6 @@ PDFJS.GlobalWorkerOptions.workerPort = new Worker(
export const imageResourcesPath = '/images/pdfjs-dist/'
const cMapUrl = '/js/pdfjs-dist/cmaps/'
const wasmUrl = '/js/pdfjs-dist/wasm/'
const iccUrl = '/js/pdfjs-dist/iccs/'
const standardFontDataUrl = '/fonts/pdfjs-dist/'
const params = new URLSearchParams(window.location.search)
@@ -25,8 +23,6 @@ export const loadPdfDocumentFromUrl = (
PDFJS.getDocument({
url,
cMapUrl,
wasmUrl,
iccUrl,
standardFontDataUrl,
disableFontFace,
disableAutoFetch: true, // only fetch the data needed for the displayed pages

View File

@@ -320,7 +320,7 @@
"nock": "^13.5.6",
"nvd3": "^1.8.6",
"overleaf-editor-core": "*",
"pdfjs-dist": "5.1.91",
"pdfjs-dist": "4.10.38",
"pirates": "^4.0.1",
"postcss": "^8.4.31",
"postcss-loader": "^7.3.3",

View File

@@ -380,22 +380,12 @@ module.exports = {
context: `${dictionariesDir}/dictionaries`,
},
// Copy CMap files (used to provide support for non-Latin characters),
// wasm, ICC profiles, fonts and images from pdfjs-dist package to build output.
// fonts and images from pdfjs-dist package to build output.
{
from: 'cmaps',
to: 'js/pdfjs-dist/cmaps',
context: pdfjsDir,
},
{
from: 'iccs',
to: 'js/pdfjs-dist/iccs',
context: pdfjsDir,
},
{
from: 'wasm',
to: 'js/pdfjs-dist/wasm',
context: pdfjsDir,
},
{
from: 'standard_fonts',
to: 'fonts/pdfjs-dist',