Skip to content

A platform for community discussion. Free, open, simple.

FIX: call method only if it exists

Vinoth Kannan59e5af466bdc
diff --git a/app/models/theme_field.rb b/app/models/theme_field.rb
index 07e6e3fd76d..a2d4af431e6 100644
--- a/app/models/theme_field.rb
+++ b/app/models/theme_field.rb
@@ -63,7 +63,7 @@ class ThemeField < ActiveRecord::Base
def transpile(es6_source, version)
template = Tilt::ES6ModuleTranspilerTemplate.new {}
wrapped = <<PLUGIN_API_JS
-if ('Discourse' in window) {
+if ('Discourse' in window && typeof Discourse._registerPluginCode === 'function') {
Discourse._registerPluginCode('#{version}', api => {
#{settings(es6_source)}
#{es6_source}
diff --git a/spec/models/theme_spec.rb b/spec/models/theme_spec.rb
index 26c706ba79d..ed8bca19e6a 100644
--- a/spec/models/theme_spec.rb
+++ b/spec/models/theme_spec.rb
@@ -326,7 +326,7 @@ HTML
theme.save!
transpiled = <<~HTML
- if ('Discourse' in window) {
+ if ('Discourse' in window && typeof Discourse._registerPluginCode === 'function') {
Discourse._registerPluginCode('1.0', function (api) {
var settings = { "name": "bob" };
alert(settings.name);var a = function a() {};
@@ -342,7 +342,7 @@ HTML
setting.value = 'bill'
transpiled = <<~HTML
- if ('Discourse' in window) {
+ if ('Discourse' in window && typeof Discourse._registerPluginCode === 'function') {
Discourse._registerPluginCode('1.0', function (api) {
var settings = { "name": "bill" };
alert(settings.name);var a = function a() {};