diff --git a/gulpfile.mjs b/gulpfile.mjs index ac43c1503..1ea48fe2e 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,