Bypass asset_host configuration for icon sprite#5895
Merged
Conversation
aduth
commented
Feb 2, 2022
app/components/icon_component.rb
Outdated
Comment on lines
+269
to
+270
Contributor
Author
There was a problem hiding this comment.
This comes from the fallback here:
Contributor
There was a problem hiding this comment.
this branch is not covered by tests, I'd consider adding it
if we don't want to stub Rails.env, we could do some dependency injection:
def asset_host(rails_env = Rails.env)
if rails_env.production?
and then in the test pass in a ActiveSupport::EnvironmentInquirer.new("production") or ActiveSupport::EnvironmentInquirer.new("development") etc
Contributor
Author
There was a problem hiding this comment.
this branch is not covered by tests, I'd consider adding it
👍 Added specs in rebased 8f82e3b.
Went for stubbing due to light preference to keep asset_host a private method.
app/components/icon_component.rb
Outdated
Comment on lines
+271
to
+272
Contributor
Author
There was a problem hiding this comment.
...and this matches the default behavior of Rails asset URL calculation:
Contributor
Author
**Why**: Icon sprites consumed via SVG `<use>` cannot reference cross-domain resources, so it must be served from the same host.
a28fe8f to
8f82e3b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Why: Icon sprites consumed via SVG
<use>cannot reference cross-domain resources, so it must be served from the same host.Related Slack discussion: https://gsa-tts.slack.com/archives/C0NGESUN5/p1643749421139809