Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude 'remixicon.symbol.svg' from asset pipeline #5878

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

stewart
Copy link
Contributor

@stewart stewart commented Oct 16, 2024

Addresses #5657 - when a Solidus store has config.action_controller.asset_host configured to point to a different hostname than the Rails application (i.e. an assets CDN, in production), the admin menu icons do not render as expected.

This is because for security reasons, referencing SVG icons from an external file (using <use xlink:href="">) is not possible when the asset is served from a different domain to the one requesting it.

Providing an empty host option allows us to skip Rails' built-in asset-path helper methods that are falling back to the global asset_host config, and correct the issue.

Note: this change does result in the generated asset path being a protocol-prefixed relative URL (i.e. "http:/assets/solidus_admin/remixicon.symbol-[SHA].svg"), but this seems to work OK from my testing.

Referencing SVG icons from an external host using `<use xlink:href="">` is not
supported, for CORS (cross-origin request scripting) security reasons.

This doesn't come up often in development but can rear its head in a production
deployment. To avoid this, we'll always provide an empty host.

This results in the generated paths being protocol-prefixed relative URLs (i.e.
"http:/assets/solidus_admin/remixicon.symbol.svg") but this seems to work OK.
@tvdeyen
Copy link
Member

tvdeyen commented Oct 17, 2024

Interesting. In Alchemy we have the same issue and we tried to fix it with a preload tag

  1. Issue No icons in admin interface (CORS problem) AlchemyCMS/alchemy_cms#2937
  2. PR that adds the preload Preload SVG Icon Sprite AlchemyCMS/alchemy_cms#3046

I have no assets host that I can test this with, though I trust your approach. But, can we try to preload the asset and verify if it works as well or not?

Copy link
Member

@jarednorman jarednorman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tend to think this approach is fine (rather than preloads) because:

  1. It's in the admin and serving one asset in the admin from the app server isn't a performance concern.
  2. Keeping preloads in sync with usage seems like a maintenance burden. It would be pretty easy for people to change something and miss that.

Copy link
Contributor

@MadelineCollier MadelineCollier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The solidus_installer step will pass if you rebase this off main (which has a fix fpr that step merged now) :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants