Browse Source

@uppy/transloadit: fix TypeError when file is cancelled asynchronously (#3872)

Co-authored-by: Artur Paikin <artur@arturpaikin.com>
Antoine du Hamel 2 years ago
parent
commit
418b25c39a
1 changed files with 9 additions and 2 deletions
  1. 9 2
      packages/@uppy/transloadit/src/AssemblyOptions.js

+ 9 - 2
packages/@uppy/transloadit/src/AssemblyOptions.js

@@ -30,7 +30,7 @@ function validateParams (params) {
  */
 function dedupe (list) {
   const dedupeMap = Object.create(null)
-  for (const { fileIDs, options } of list) {
+  for (const { fileIDs, options } of list.filter(Boolean)) {
     const id = JSON.stringify(options)
     if (id in dedupeMap) {
       dedupeMap[id].fileIDArrays.push(fileIDs)
@@ -62,9 +62,16 @@ class AssemblyOptions {
    * Get Assembly options for a file.
    */
   async #getAssemblyOptions (file) {
-    const options = this.opts
+    if (file == null) return undefined
 
+    const options = this.opts
     const assemblyOptions = await options.getAssemblyOptions(file, options)
+
+    // We check if the file is present here again, because it could had been
+    // removed during the await, e.g. if the user hit cancel while we were
+    // waiting for the options.
+    if (file == null) return undefined
+
     if (Array.isArray(assemblyOptions.fields)) {
       assemblyOptions.fields = Object.fromEntries(
         assemblyOptions.fields.map((fieldName) => [fieldName, file.meta[fieldName]]),