From 823d375b8b979680a0932f3e199a76fbdb453ac8 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Fri, 10 Nov 2023 12:49:37 +0100 Subject: [PATCH] Ensure that the viewer waits for the library to complete loading (issue 17228) This should *hopefully* fix 17228, by tweaking the build scripts to give the GENERIC viewer something to await to avoid breaking third-party users of the standalone viewer components. --- gulpfile.mjs | 2 +- web/pdfjs.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/gulpfile.mjs b/gulpfile.mjs index 2de6f1f8b..55bc5f001 100644 --- a/gulpfile.mjs +++ b/gulpfile.mjs @@ -422,7 +422,7 @@ function tweakWebpackOutput(jsName) { case " __webpack_exports__ = {};": return ` __webpack_exports__ = globalThis.${jsName} = {};`; case " __webpack_exports__ = await __webpack_exports__;": - return ` __webpack_exports__ = globalThis.${jsName} = await __webpack_exports__;`; + return ` __webpack_exports__ = globalThis.${jsName} = await (globalThis.${jsName}Promise = __webpack_exports__);`; } return match; }); diff --git a/web/pdfjs.js b/web/pdfjs.js index 3ca9b5490..30da7c8d6 100644 --- a/web/pdfjs.js +++ b/web/pdfjs.js @@ -13,6 +13,15 @@ * limitations under the License. */ +// Ensure that the viewer waits for the library to complete loading, +// to avoid breaking e.g. the standalone viewer components (see issue 17228). +if ( + (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) && + !globalThis.pdfjsLib +) { + await globalThis.pdfjsLibPromise; +} + const { AbortException, AnnotationEditorLayer,