From 38a18b7aa0bc4adc9e368e32e62892e4031dc1ba Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Wed, 13 Nov 2019 09:28:43 +0100 Subject: [PATCH] DEV: call destroy() on widget when glue is cleaned up (#8338) --- app/assets/javascripts/discourse/widgets/glue.js.es6 | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/assets/javascripts/discourse/widgets/glue.js.es6 b/app/assets/javascripts/discourse/widgets/glue.js.es6 index 93c5b35ec40..7d8a2a45614 100644 --- a/app/assets/javascripts/discourse/widgets/glue.js.es6 +++ b/app/assets/javascripts/discourse/widgets/glue.js.es6 @@ -54,6 +54,18 @@ export default class WidgetGlue { } cleanUp() { + const widgets = []; + const findWidgets = widget => { + widget.vnode.children.forEach(child => { + if (child.constructor.name === "CustomWidget") { + widgets.push(child); + findWidgets(child, widgets); + } + }); + }; + findWidgets(this._tree, widgets); + widgets.reverse().forEach(widget => widget.destroy()); + cancel(this._timeout); } }