Parcourir la source

@uppy/core: detach event listeners on close (#3035)

Fixes: https://github.com/transloadit/uppy/issues/3026
Antoine du Hamel il y a 3 ans
Parent
commit
3bbddf8ed7
1 fichiers modifiés avec 10 ajouts et 6 suppressions
  1. 10 6
      packages/@uppy/core/src/index.js

+ 10 - 6
packages/@uppy/core/src/index.js

@@ -172,9 +172,6 @@ class Uppy {
     //    [Practical Check] Firefox, try to upload a big file for a prolonged period of time. Laptop will start to heat up.
     this.calculateProgress = throttle(this.calculateProgress.bind(this), 500, { leading: true, trailing: true })
 
-    this.updateOnlineStatus = this.updateOnlineStatus.bind(this)
-    this.resetProgress = this.resetProgress.bind(this)
-
     this.pauseAll = this.pauseAll.bind(this)
     this.resumeAll = this.resumeAll.bind(this)
     this.retryAll = this.retryAll.bind(this)
@@ -1256,9 +1253,9 @@ class Uppy {
 
     // show informer if offline
     if (typeof window !== 'undefined' && window.addEventListener) {
-      window.addEventListener('online', () => this.updateOnlineStatus())
-      window.addEventListener('offline', () => this.updateOnlineStatus())
-      setTimeout(() => this.updateOnlineStatus(), 3000)
+      window.addEventListener('online', this.#updateOnlineStatus)
+      window.addEventListener('offline', this.#updateOnlineStatus)
+      setTimeout(this.#updateOnlineStatus, 3000)
     }
   }
 
@@ -1281,6 +1278,8 @@ class Uppy {
     }
   }
 
+  #updateOnlineStatus = this.updateOnlineStatus.bind(this)
+
   getID () {
     return this.opts.id
   }
@@ -1406,6 +1405,11 @@ class Uppy {
     this.iteratePlugins((plugin) => {
       this.removePlugin(plugin)
     })
+
+    if (typeof window !== 'undefined' && window.removeEventListener) {
+      window.removeEventListener('online', this.#updateOnlineStatus)
+      window.removeEventListener('offline', this.#updateOnlineStatus)
+    }
   }
 
   /**