Skip to content

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

Revert "DEV: Switch to `type="module"` for translation files (#33107)" (#33125)

Natalie Tayc28353b0dd0b
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 56c70b68eb5..a34cf0c2a95 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -151,14 +151,14 @@ module ApplicationHelper
.html_safe
end
- def preload_script_url(url, entrypoint: nil, type_module: false)
+ def preload_script_url(url, entrypoint: nil)
entrypoint_attribute = entrypoint ? "data-discourse-entrypoint=\"#{entrypoint}\"" : ""
nonce_attribute = "nonce=\"#{csp_nonce_placeholder}\""
add_resource_preload_list(url, "script")
<<~HTML.html_safe
- <script #{type_module ? 'type="module"' : "defer"} src="#{url}" #{entrypoint_attribute} #{nonce_attribute}></script>
+ <script defer src="#{url}" #{entrypoint_attribute} #{nonce_attribute}></script>
HTML
end
diff --git a/app/models/theme.rb b/app/models/theme.rb
index 6681a1f78cd..8cd10fcf8d1 100644
--- a/app/models/theme.rb
+++ b/app/models/theme.rb
@@ -6,7 +6,7 @@ require "json_schemer"
class Theme < ActiveRecord::Base
include GlobalPath
- BASE_COMPILER_VERSION = 91
+ BASE_COMPILER_VERSION = 90
class SettingsMigrationError < StandardError
end
diff --git a/app/models/theme_field.rb b/app/models/theme_field.rb
index faaeb551ebd..8eb9a370d42 100644
--- a/app/models/theme_field.rb
+++ b/app/models/theme_field.rb
@@ -322,16 +322,18 @@ class ThemeField < ActiveRecord::Base
data = translation_data
js = <<~JS
- /* Translation data for theme #{self.theme_id} (#{self.name})*/
- const data = #{data.to_json};
-
- for (let lang in data){
- let cursor = I18n.translations;
- for (let key of [lang, "js", "theme_translations"]){
- cursor = cursor[key] ??= {};
+ (function(){
+ /* Translation data for theme #{self.theme_id} (#{self.name})*/
+ const data = #{data.to_json};
+
+ for (let lang in data){
+ let cursor = I18n.translations;
+ for (let key of [lang, "js", "theme_translations"]){
+ cursor = cursor[key] ??= {};
+ }
+ cursor[#{self.theme_id}] = data[lang];
}
- cursor[#{self.theme_id}] = data[lang];
- }
+ })()
JS
javascript_cache.content = js
@@ -340,7 +342,7 @@ class ThemeField < ActiveRecord::Base
doc = ""
doc = <<~HTML.html_safe if javascript_cache.content.present?
- <script type="module" src="#{javascript_cache.url}" data-theme-id="#{theme_id}" nonce="#{ThemeField::CSP_NONCE_PLACEHOLDER}"></script>
+ <script defer src="#{javascript_cache.url}" data-theme-id="#{theme_id}" nonce="#{ThemeField::CSP_NONCE_PLACEHOLDER}"></script>
HTML
[doc, errors&.join("\n")]
rescue ThemeTranslationParser::InvalidYaml => e
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb
index 7fc8988c626..aad72181a06 100644
--- a/app/views/layouts/application.html.erb
+++ b/app/views/layouts/application.html.erb
@@ -36,19 +36,19 @@
<%= preload_script file %>
<%- end %>
- <%= preload_script_url ExtraLocalesController.url("main"), type_module: true %>
- <%= preload_script_url ExtraLocalesController.url("mf"), type_module: true %>
+ <%= preload_script_url ExtraLocalesController.url("main") %>
+ <%= preload_script_url ExtraLocalesController.url("mf") %>
<%- if ExtraLocalesController.client_overrides_exist? %>
- <%= preload_script_url ExtraLocalesController.url("overrides"), type_module: true %>
+ <%= preload_script_url ExtraLocalesController.url("overrides") %>
<%- end %>
<%- if staff? %>
- <%= preload_script_url ExtraLocalesController.url("admin"), type_module: true %>
+ <%= preload_script_url ExtraLocalesController.url("admin") %>
<%= preload_script "admin" %>
<%- end %>
<%- if admin? %>
- <%= preload_script_url ExtraLocalesController.url("wizard"), type_module: true %>
+ <%= preload_script_url ExtraLocalesController.url("wizard") %>
<%- end %>
<%- unless customization_disabled? %>
diff --git a/spec/models/theme_field_spec.rb b/spec/models/theme_field_spec.rb
index 8e6a5c13146..117d3b6cd03 100644
--- a/spec/models/theme_field_spec.rb
+++ b/spec/models/theme_field_spec.rb
@@ -612,7 +612,7 @@ HTML
it "is generated correctly" do
fr1.ensure_baked!
expect(fr1.value_baked).to include(
- "<script type=\"module\" src=\"#{fr1.javascript_cache.url}\" data-theme-id=\"#{fr1.theme_id}\" nonce=\"#{ThemeField::CSP_NONCE_PLACEHOLDER}\"></script>",
+ "<script defer src=\"#{fr1.javascript_cache.url}\" data-theme-id=\"#{fr1.theme_id}\" nonce=\"#{ThemeField::CSP_NONCE_PLACEHOLDER}\"></script>",
)
expect(fr1.javascript_cache.content).to include("bonjourworld")
expect(fr1.javascript_cache.content).to include("helloworld")