From 02495510e812808e279828915bd04304543ef90a Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Tue, 8 Sep 2020 10:14:41 +0200 Subject: [PATCH] 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. --- app/assets/javascripts/discourse/app/widgets/widget.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/discourse/app/widgets/widget.js b/app/assets/javascripts/discourse/app/widgets/widget.js index 9fbabf71399..a00ccc8af75 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; }