From 65756fcc5004ef8aa0ee2d6ef7cbf06b1e0c260e Mon Sep 17 00:00:00 2001
From: Paul Kaplan <pkaplan@media.mit.edu>
Date: Wed, 6 Feb 2019 14:32:17 -0500
Subject: [PATCH] Load files one at a time to enforce load order

---
 src/lib/file-uploader.js | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/src/lib/file-uploader.js b/src/lib/file-uploader.js
index dec463d6d..483f31edf 100644
--- a/src/lib/file-uploader.js
+++ b/src/lib/file-uploader.js
@@ -21,23 +21,25 @@ const extractFileName = function (nameExt) {
  * @param {Function} onload The function that handles loading the file
  */
 const handleFileUpload = function (fileInput, onload) {
-    const readFile = file => {
-        const reader = new FileReader();
-        reader.onload = () => {
+    const readFile = (i, files) => {
+        if (i === files.length) {
             // Reset the file input value now that we have everything we need
             // so that the user can upload the same sound multiple times if
             // they choose
             fileInput.value = null;
+            return;
+        }
+        const file = files[i];
+        const reader = new FileReader();
+        reader.onload = () => {
             const fileType = file.type;
             const fileName = extractFileName(file.name);
-
             onload(reader.result, fileType, fileName);
+            readFile(i + 1, files);
         };
         reader.readAsArrayBuffer(file);
     };
-    for (let i = 0; i < fileInput.files.length; i++) {
-        readFile(fileInput.files[i]);
-    }
+    readFile(0, fileInput.files);
 };
 
 /**
-- 
GitLab