From 5f2b3a03ed8d6c0762681be516cb9a293c636ac3 Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Wed, 18 May 2022 13:25:54 +0200 Subject: [PATCH] Avoid errors in Resizer if the component is removed. Closes #4333 --- src/utils/Resizer.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/utils/Resizer.js b/src/utils/Resizer.js index 079934c60..fff0c2ad5 100644 --- a/src/utils/Resizer.js +++ b/src/utils/Resizer.js @@ -287,11 +287,12 @@ class Resizer { }; // Listen events - var doc = this.getDocumentEl(); - on(doc, 'mousemove', this.move); - on(doc, 'keydown', this.handleKeyDown); - on(doc, 'mouseup', this.stop); - isFunction(this.onStart) && this.onStart(e, { docs: doc, config, el, resizer }); + const docs = this.getDocumentEl(); + this.docs = docs; + on(docs, 'mousemove', this.move); + on(docs, 'keydown', this.handleKeyDown); + on(docs, 'mouseup', this.stop); + isFunction(this.onStart) && this.onStart(e, { docs, config, el, resizer }); this.toggleFrames(1); this.move(e); } @@ -339,13 +340,14 @@ class Resizer { */ stop(e) { const config = this.opts; - var doc = this.getDocumentEl(); - off(doc, 'mousemove', this.move); - off(doc, 'keydown', this.handleKeyDown); - off(doc, 'mouseup', this.stop); + const docs = this.docs || this.getDocumentEl(); + off(docs, 'mousemove', this.move); + off(docs, 'keydown', this.handleKeyDown); + off(docs, 'mouseup', this.stop); this.updateRect(1); this.toggleFrames(); - isFunction(this.onEnd) && this.onEnd(e, { docs: doc, config }); + isFunction(this.onEnd) && this.onEnd(e, { docs, config }); + delete this.docs; } /**