DEV: prevents hooks to create leaks on widgets (#14207)

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.

diff --git a/app/assets/javascripts/discourse/app/components/mount-widget.js b/app/assets/javascripts/discourse/app/components/mount-widget.js
index 136b28f..cc29cfb 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 4795926..cf192f3 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;
   }
 }

GitHub sha: a2ca430068d9d8baaf52ad5a60e710af8f5a07e3

This commit appears in #14207 which was approved by CvX. It was merged by jjaffeux.