DEV: ensures tree is present for traverseCustomWidgets (#13855)

DEV: ensures tree is present for traverseCustomWidgets (#13855)

We already had this check sometimes in code, it’s just safer to have this responsibility baked in the function.

diff --git a/app/assets/javascripts/discourse/app/components/mount-widget.js b/app/assets/javascripts/discourse/app/components/mount-widget.js
index f0f7e66..136b28f 100644
--- a/app/assets/javascripts/discourse/app/components/mount-widget.js
+++ b/app/assets/javascripts/discourse/app/components/mount-widget.js
@@ -124,9 +124,7 @@ export default Component.extend({
       newTree._emberView = this;
       const patches = diff(this._tree || this._rootNode, newTree);
 
-      if (this._tree) {
-        traverseCustomWidgets(this._tree, (w) => w.willRerenderWidget());
-      }
+      traverseCustomWidgets(this._tree, (w) => w.willRerenderWidget());
 
       this.beforePatch();
       this._rootNode = patch(this._rootNode, patches);
diff --git a/app/assets/javascripts/discourse/app/widgets/glue.js b/app/assets/javascripts/discourse/app/widgets/glue.js
index 19ae9a2..4795926 100644
--- a/app/assets/javascripts/discourse/app/widgets/glue.js
+++ b/app/assets/javascripts/discourse/app/widgets/glue.js
@@ -47,9 +47,7 @@ export default class WidgetGlue {
     });
     const patches = diff(this._tree || this._rootNode, newTree);
 
-    if (this._tree) {
-      traverseCustomWidgets(this._tree, (w) => w.willRerenderWidget());
-    }
+    traverseCustomWidgets(this._tree, (w) => w.willRerenderWidget());
 
     newTree._rerenderable = this;
     this._rootNode = patch(this._rootNode, patches);
diff --git a/app/assets/javascripts/discourse/app/widgets/widget.js b/app/assets/javascripts/discourse/app/widgets/widget.js
index 59253a0..27faa31 100644
--- a/app/assets/javascripts/discourse/app/widgets/widget.js
+++ b/app/assets/javascripts/discourse/app/widgets/widget.js
@@ -38,6 +38,10 @@ export function decorateWidget(widgetName, cb) {
 }
 
 export function traverseCustomWidgets(tree, callback) {
+  if (!tree) {
+    return;
+  }
+
   if (tree.__type === "CustomWidget") {
     callback(tree);
   }

GitHub sha: d801e33e0bec44a88fff2aa2b37b6b53a27a5fbe

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