From 56d826f255af9f74fc24690c4cc02b828172bb01 Mon Sep 17 00:00:00 2001 From: Miguel Serrano Date: Tue, 11 Jan 2022 18:20:03 +0100 Subject: [PATCH] Force `Promise.allSettled` polyfill (#6192) * Force `Promise.allSettled` polyfill `Promise.allSettled` is required by `pdf.js`, but the polyfill is not available in the bundle. This forces babel to include the polyfill without having to process `pdf.js` with webpack/babel, which causes issues loading documents. * Updated core.js version for test config GitOrigin-RevId: 981da187352ffc8c59cb77ba55a0a9643bd7cc9a --- services/web/babel.config.json | 3 ++- .../frontend/js/features/pdf-preview/util/pdf-js-wrapper.js | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/services/web/babel.config.json b/services/web/babel.config.json index ed94b409a9..74962dd258 100644 --- a/services/web/babel.config.json +++ b/services/web/babel.config.json @@ -32,7 +32,8 @@ { "targets": { "node": "12.21" }, "useBuiltIns": "usage", - "corejs": { "version": 3 } + // This version must be aligned with the `core-js` version in `package.json` + "corejs": { "version": 3.6 } } ] ] diff --git a/services/web/frontend/js/features/pdf-preview/util/pdf-js-wrapper.js b/services/web/frontend/js/features/pdf-preview/util/pdf-js-wrapper.js index a387d424f7..ef52f13fa5 100644 --- a/services/web/frontend/js/features/pdf-preview/util/pdf-js-wrapper.js +++ b/services/web/frontend/js/features/pdf-preview/util/pdf-js-wrapper.js @@ -11,6 +11,11 @@ if (typeof window !== 'undefined' && 'Worker' in window) { PDFJS.GlobalWorkerOptions.workerPort = new PDFJSWorker() } +// forces the method (required by pdf.js) to be polyfilled by webpack, since +// processing pdf.js by webpack/babel causes issues loading documents +// eslint-disable-next-line no-unused-expressions +Promise.allSettled + const params = new URLSearchParams(window.location.search) const disableFontFace = params.get('disable-font-face') === 'true' const cMapUrl = getMeta('ol-pdfCMapsPath')