From a2ca430068d9d8baaf52ad5a60e710af8f5a07e3 Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Wed, 1 Sep 2021 14:34:20 +0200 Subject: [PATCH] DEV: prevents hooks to create leaks on widgets (#14207) Before this, mounted widgets were not correctly unhooked and would keep a reference to a custom widget object. --- .../javascripts/discourse/app/components/mount-widget.js | 3 +++ app/assets/javascripts/discourse/app/widgets/glue.js | 3 +++ 2 files changed, 6 insertions(+) diff --git a/app/assets/javascripts/discourse/app/components/mount-widget.js b/app/assets/javascripts/discourse/app/components/mount-widget.js index 136b28fe004..cc29cfb1ce3 100644 --- a/app/assets/javascripts/discourse/app/components/mount-widget.js +++ b/app/assets/javascripts/discourse/app/components/mount-widget.js @@ -63,6 +63,9 @@ export default Component.extend({ this._connected.forEach((v) => v.destroy()); this._connected.length = 0; + + this._rootNode = patch(this._rootNode, diff(this._tree, null)); + this._tree = null; }, willDestroyElement() { diff --git a/app/assets/javascripts/discourse/app/widgets/glue.js b/app/assets/javascripts/discourse/app/widgets/glue.js index 4795926e146..cf192f37fc1 100644 --- a/app/assets/javascripts/discourse/app/widgets/glue.js +++ b/app/assets/javascripts/discourse/app/widgets/glue.js @@ -60,5 +60,8 @@ export default class WidgetGlue { traverseCustomWidgets(this._tree, (w) => w.destroy()); cancel(this._timeout); + + this._rootNode = patch(this._rootNode, diff(this._tree, null)); + this._tree = null; } }