From bcd8151e77e90b5c219650db604ccf6bb6617720 Mon Sep 17 00:00:00 2001 From: Ryan Wallace Date: Tue, 5 Nov 2024 04:59:02 -0800 Subject: [PATCH] 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 --- test/helper_test.rb | 8 ++++++++ vite_rails/lib/vite_rails/tag_helpers.rb | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/test/helper_test.rb b/test/helper_test.rb index deadb3b3..4ec629d3 100644 --- a/test/helper_test.rb +++ b/test/helper_test.rb @@ -105,6 +105,14 @@ def test_vite_stylesheet_tag } end + def test_vite_preload_tag + assert_includes vite_typescript_tag('main', host: 'example.com', protocol: 'https'), [ + %(), + %(), + %(), + ].join("\n") + end + def test_vite_javascript_tag assert_similar [ %(), diff --git a/vite_rails/lib/vite_rails/tag_helpers.rb b/vite_rails/lib/vite_rails/tag_helpers.rb index f6f5e9cc..066d8c7f 100644 --- a/vite_rails/lib/vite_rails/tag_helpers.rb +++ b/vite_rails/lib/vite_rails/tag_helpers.rb @@ -101,7 +101,8 @@ def vite_manifest # Internal: Renders a modulepreload link tag. def vite_preload_tag(*sources, crossorigin:, **options) - asset_paths = sources.map { |source| path_to_asset(source) } + url_options = options.extract!(:host, :protocol) + asset_paths = sources.map { |source| path_to_asset(source, **url_options) } try(:request).try( :send_early_hints, 'Link' => asset_paths.map { |href|