Skip to content

Commit bcd8151

Browse files
rywallElMassimo
andauthored
fix: respect host and protocol options in vite_preload_tag (#413)
* Respect host and protocol options in vite_preload_tag When specifying the host and protocol options for a vite_javascript_tag we want the preload tags to also respect those options. * chore: use `extract!` instead --------- Co-authored-by: Maximo Mussini <[email protected]>
1 parent 57a6e7a commit bcd8151

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

test/helper_test.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,14 @@ def test_vite_stylesheet_tag
105105
}
106106
end
107107

108+
def test_vite_preload_tag
109+
assert_includes vite_typescript_tag('main', host: 'example.com', protocol: 'https'), [
110+
%(<link rel="modulepreload" href="https://example.com/vite-production/assets/log.818edfb8.js" as="script" crossorigin="anonymous">),
111+
%(<link rel="modulepreload" href="https://example.com/vite-production/assets/vue.3002ada6.js" as="script" crossorigin="anonymous">),
112+
%(<link rel="modulepreload" href="https://example.com/vite-production/assets/vendor.0f7c0ec3.js" as="script" crossorigin="anonymous">),
113+
].join("\n")
114+
end
115+
108116
def test_vite_javascript_tag
109117
assert_similar [
110118
%(<script src="/vite-production/assets/main.9dcad042.js" crossorigin="anonymous" type="module"></script>),

vite_rails/lib/vite_rails/tag_helpers.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ def vite_manifest
101101

102102
# Internal: Renders a modulepreload link tag.
103103
def vite_preload_tag(*sources, crossorigin:, **options)
104-
asset_paths = sources.map { |source| path_to_asset(source) }
104+
url_options = options.extract!(:host, :protocol)
105+
asset_paths = sources.map { |source| path_to_asset(source, **url_options) }
105106
try(:request).try(
106107
:send_early_hints,
107108
'Link' => asset_paths.map { |href|

0 commit comments

Comments
 (0)