You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Our problem is related to this github issue.
Everything worked fine until we recently updated vite & vite-ruby. We host our assets on S3, however we do have CORS issues on Chrome/Chromium. The reason is a change in Vite and this package, vite-ruby.
The result is a stylesheet beeing loaded twice, one time with the crossorigin attribute (due to async component, f.e.) and one time without (component is bundled, not in a separate chunk).
Example:
component B is a sub-component of A that is directly bundled
component B is also a sub-component of C that is defined as an async component (we use Vue)
The stylesheet of component B is then inserted by vite-ruby in the <head> via:
<!-- Vite rails stylesheet via vite_javascript_tag (not preloaded), by component A --><linkrel="stylesheet" src="cdn.blabla.test/component-b-css-123123.css"><!-- Vite preload, by component C --><linkrel="stylesheet" crossoriginsrc="cdn.blabla.test/component-b-css-123123.css">
The CORS policy of chrome then blocks the second request because the origin header is now there which wasn't the case before. Imho an easy fix would be that we could add the crossorigin attribute to the stylesheets as well within the tag helpers. Unfortunately, this is currently not possible within vite-ruby.
Vite however adds the crossorigin attribtue to stylesheets by default therefore the implementations diverge. Responsible source code in Vite
Part within the tag helpers that would need a change:
defvite_javascript_tag(*names,type: "module",asset_type: :javascript,skip_preload_tags: false,skip_style_tags: false,crossorigin: "anonymous",media: "screen",
**options)entries=vite_manifest.resolve_entries(*names,type: asset_type)tags=javascript_include_tag(*entries.fetch(:scripts),crossorigin: crossorigin,type: type,extname: false, **options)tags << vite_preload_tag(*entries.fetch(:imports),crossorigin: crossorigin, **options)unlessskip_preload_tagsoptions[:extname]=falseifRails::VERSION::MAJOR >= 7# here we would need to also pass the crossorigin param# see https://github.com/ElMassimo/vite_ruby/blob/main/vite_rails/lib/vite_rails/tag_helpers.rb#L52tags << stylesheet_link_tag(*entries.fetch(:stylesheets),media: media, **options)unlessskip_style_tagstagsend
Best would be to use a flag if the crossorigin attribute should be applied to the stylesheet tags or not. This would prevent a change to the current behavior.
Description 📖
Similar issue as #189
Our problem is related to this github issue.
Everything worked fine until we recently updated vite & vite-ruby. We host our assets on S3, however we do have CORS issues on Chrome/Chromium. The reason is a change in Vite and this package, vite-ruby.
The result is a stylesheet beeing loaded twice, one time with the
crossorigin
attribute (due to async component, f.e.) and one time without (component is bundled, not in a separate chunk).Example:
The stylesheet of component B is then inserted by vite-ruby in the
<head>
via:The CORS policy of chrome then blocks the second request because the origin header is now there which wasn't the case before. Imho an easy fix would be that we could add the
crossorigin
attribute to the stylesheets as well within the tag helpers. Unfortunately, this is currently not possible within vite-ruby.Vite however adds the
crossorigin
attribtue to stylesheets by default therefore the implementations diverge. Responsible source code in VitePart within the tag helpers that would need a change:
Best would be to use a flag if the
crossorigin
attribute should be applied to the stylesheet tags or not. This would prevent a change to the current behavior.Reproduction 🐞
Vite Ruby Info
Run
bin/rake vite:info
and provide the output:Screenshots 📷
The text was updated successfully, but these errors were encountered: