Skip to content

Commit 4e72506

Browse files
authored
Merge pull request rails#55725 from byroot/js-include-type-module-sym
Fix javascript_include_tag `type:` option to accept symbols
2 parents a72018d + 8adc277 commit 4e72506

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

actionview/lib/action_view/helpers/asset_tag_helper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def javascript_include_tag(*sources)
121121
crossorigin = options.delete("crossorigin")
122122
crossorigin = "anonymous" if crossorigin == true
123123
integrity = options["integrity"]
124-
rel = options["type"] == "module" ? "modulepreload" : "preload"
124+
rel = options["type"] == "module" || options["type"] == :module ? "modulepreload" : "preload"
125125

126126
sources_tags = sources.uniq.map { |source|
127127
href = path_to_javascript(source, path_options)
@@ -370,7 +370,7 @@ def preload_link_tag(source, options = {})
370370
integrity = options[:integrity]
371371
fetchpriority = options.delete(:fetchpriority)
372372
nopush = options.delete(:nopush) || false
373-
rel = mime_type == "module" ? "modulepreload" : "preload"
373+
rel = mime_type == "module" || mime_type == :module ? "modulepreload" : "preload"
374374
add_nonce = content_security_policy_nonce &&
375375
respond_to?(:request) &&
376376
request.content_security_policy_nonce_directives&.include?("#{as_type}-src")

actionview/test/template/asset_tag_helper_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ def content_security_policy_nonce
337337

338338
PreloadLinkToTag = {
339339
%(preload_link_tag '/application.js', type: 'module') => %(<link rel="modulepreload" href="/application.js" as="script" type="module" >),
340+
%(preload_link_tag '/application.js', type: :module) => %(<link rel="modulepreload" href="/application.js" as="script" type="module" >),
340341
%(preload_link_tag '/styles/custom_theme.css') => %(<link rel="preload" href="/styles/custom_theme.css" as="style" type="text/css" />),
341342
%(preload_link_tag '/videos/video.webm') => %(<link rel="preload" href="/videos/video.webm" as="video" type="video/webm" />),
342343
%(preload_link_tag '/posts.json', as: 'fetch') => %(<link rel="preload" href="/posts.json" as="fetch" type="application/json" />),

0 commit comments

Comments
 (0)