Przeglądaj źródła

Ignore progress events in timeout tracker after upload was aborted.

Renée Kooi 7 lat temu
rodzic
commit
f8a0c8d51a
1 zmienionych plików z 10 dodań i 1 usunięć
  1. 10 1
      src/plugins/XHRUpload.js

+ 10 - 1
src/plugins/XHRUpload.js

@@ -126,6 +126,8 @@ module.exports = class XHRUpload extends Plugin {
   createProgressTimeout (timeout, timeoutHandler) {
   createProgressTimeout (timeout, timeoutHandler) {
     const uppy = this.uppy
     const uppy = this.uppy
     const self = this
     const self = this
+    let isDone = false
+
     function onTimedOut () {
     function onTimedOut () {
       uppy.log(`[XHRUpload] timed out`)
       uppy.log(`[XHRUpload] timed out`)
       const error = new Error(self.i18n('timedOut', { seconds: Math.ceil(timeout / 1000) }))
       const error = new Error(self.i18n('timedOut', { seconds: Math.ceil(timeout / 1000) }))
@@ -134,17 +136,24 @@ module.exports = class XHRUpload extends Plugin {
 
 
     let aliveTimer = null
     let aliveTimer = null
     function progress () {
     function progress () {
+      // Some browsers fire another progress event when the upload is
+      // cancelled, so we have to ignore progress after the timer was
+      // told to stop.
+      if (isDone) return
+
       if (timeout > 0) {
       if (timeout > 0) {
-        done()
+        if (aliveTimer) clearTimeout(aliveTimer)
         aliveTimer = setTimeout(onTimedOut, timeout)
         aliveTimer = setTimeout(onTimedOut, timeout)
       }
       }
     }
     }
 
 
     function done () {
     function done () {
+      uppy.log(`[XHRUpload] timer done`)
       if (aliveTimer) {
       if (aliveTimer) {
         clearTimeout(aliveTimer)
         clearTimeout(aliveTimer)
         aliveTimer = null
         aliveTimer = null
       }
       }
+      isDone = true
     }
     }
 
 
     return {
     return {