Parcourir la source

Check if plugin exists before rendering

because of deboune, render can happen after a plugin is removed
Artur Paikin il y a 6 ans
Parent
commit
477a00775a
1 fichiers modifiés avec 5 ajouts et 1 suppressions
  1. 5 1
      src/core/Plugin.js

+ 5 - 1
src/core/Plugin.js

@@ -85,6 +85,10 @@ module.exports = class Plugin {
 
       // API for plugins that require a synchronous rerender.
       this.rerender = (state) => {
+        // plugin could be removed, but this.rerender is debounced below,
+        // so it could still be called even after uppy.removePlugin or uppy.close
+        // hence the check
+        if (!this.uppy.getPlugin(this.id)) return
         this.el = preact.render(this.render(state), targetElement, this.el)
       }
       this._updateUI = debounce(this.rerender)
@@ -137,7 +141,7 @@ module.exports = class Plugin {
   }
 
   unmount () {
-    if (this.el && this.el.parentNode) {
+    if (this.isTargetDOMEl && this.el && this.el.parentNode) {
       this.el.parentNode.removeChild(this.el)
     }
   }