FIX: workaround constructor name not available after transpilation (#10623)

FIX: workaround constructor name not available after transpilation (#10623)

This is only reproducible en production build. In this case, constructor.name could be any value like ā€œiā€ for example.

diff --git a/app/assets/javascripts/discourse/app/widgets/widget.js b/app/assets/javascripts/discourse/app/widgets/widget.js
index 9fbabf7..a00ccc8 100644
--- a/app/assets/javascripts/discourse/app/widgets/widget.js
+++ b/app/assets/javascripts/discourse/app/widgets/widget.js
@@ -38,7 +38,7 @@ export function decorateWidget(widgetName, cb) {
 }
 
 export function traverseCustomWidgets(tree, callback) {
-  if (tree.constructor.name === "CustomWidget") {
+  if (tree.__type === "CustomWidget") {
     callback(tree);
   }
 
@@ -71,6 +71,11 @@ export function changeSetting(widgetName, settingName, newValue) {
 export function createWidgetFrom(base, name, opts) {
   const result = class CustomWidget extends base {};
 
+  // todo this shouldn't been needed anymore once we don't transpile for IE anymore
+  // see: https://discuss.emberjs.com/t/constructor-name-behaves-differently-in-dev-and-prod-builds-for-models-defined-with-the-es6-class-syntax/15572/6
+  // once done, we can just check on constructor.name
+  result.prototype.__type = "CustomWidget";
+
   if (name) {
     _registry[name] = result;
   }

GitHub sha: 02495510

This commit appears in #10623 which was merged by jjaffeux.