From af7e1e18ce31382a26b77b5d3a7489a380ad3888 Mon Sep 17 00:00:00 2001 From: Ryan Wallace Date: Mon, 23 Oct 2023 12:35:10 -0700 Subject: [PATCH] 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. --- vite_rails/lib/vite_rails/tag_helpers.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/vite_rails/lib/vite_rails/tag_helpers.rb b/vite_rails/lib/vite_rails/tag_helpers.rb index f6f5e9cc..c4453139 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, tag_options = options.partition { |key, _| %i[host protocol].include?(key) }.map(&:to_h) + asset_paths = sources.map { |source| path_to_asset(source, url_options) } try(:request).try( :send_early_hints, 'Link' => asset_paths.map { |href| @@ -109,7 +110,7 @@ def vite_preload_tag(*sources, crossorigin:, **options) }.join("\n"), ) asset_paths.map { |href| - tag.link(rel: 'modulepreload', href: href, as: 'script', crossorigin: crossorigin, **options) + tag.link(rel: 'modulepreload', href: href, as: 'script', crossorigin: crossorigin, **tag_options) }.join("\n").html_safe end end