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

Merged

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.

@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) :)

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.
@stewart stewart force-pushed the remove-remixicon-from-asset-pipeline branch from a60443d to 7e432d8 Compare October 30, 2024 16:02
Copy link

codecov bot commented Oct 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.58%. Comparing base (5a9dc62) to head (7e432d8).
Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5878      +/-   ##
==========================================
+ Coverage   87.88%   89.58%   +1.70%     
==========================================
  Files         477      783     +306     
  Lines       11659    17991    +6332     
==========================================
+ Hits        10246    16117    +5871     
- Misses       1413     1874     +461     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@MadelineCollier MadelineCollier merged commit 9b3ac21 into solidusio:main Oct 30, 2024
14 checks passed
@stewart stewart deleted the remove-remixicon-from-asset-pipeline branch October 30, 2024 17:36
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