From 1ad7247700c6709e3fb8f5e762eb506caf912b19 Mon Sep 17 00:00:00 2001 From: Brendan Bond Date: Tue, 23 Apr 2024 10:34:17 -0500 Subject: [PATCH] FIO 7733: move polyfill to conditional lazy import (#5506) * move polyfill to conditional import * minor change to eslint config --- .eslintrc.json | 4 ++-- src/providers/storage/s3.js | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 72f5f3bc66..7417481951 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -2,13 +2,13 @@ "parser": "@typescript-eslint/parser", "extends": "formio", "parserOptions": { - "ecmaVersion": 2015, + "ecmaVersion": 2020, "sourceType": "module" }, "plugins": ["@typescript-eslint"], "env": { "browser": true, - "es6": true, + "es2020": true, "node": true, "mocha": true }, diff --git a/src/providers/storage/s3.js b/src/providers/storage/s3.js index d5795b73e2..5afc8cc7da 100644 --- a/src/providers/storage/s3.js +++ b/src/providers/storage/s3.js @@ -1,7 +1,12 @@ import XHR from './xhr'; import { withRetries } from './util'; -const AbortController = window.AbortController || require('abortcontroller-polyfill/dist/cjs-ponyfill'); +const loadAbortControllerPolyfill = async() => { + if (typeof AbortController === 'undefined') { + await import('abortcontroller-polyfill/dist/polyfill-patch-fetch'); + } +}; + function s3(formio) { return { async uploadFile(file, fileName, dir, progressCallback, url, options, fileKey, groupPermissions, groupId, abortCallback, multipartOptions) { @@ -11,6 +16,7 @@ function s3(formio) { if (response.signed) { if (multipartOptions && Array.isArray(response.signed)) { // patch abort callback + await loadAbortControllerPolyfill(); const abortController = new AbortController(); const abortSignal = abortController.signal; if (typeof abortCallback === 'function') {