fix: stop overriding Rails' media default in vite_javascript_tag#610
Merged
ElMassimo merged 2 commits intoJul 3, 2026
Merged
Conversation
vite_javascript_tag was explicitly passing media: "screen" to stylesheet_link_tag, overriding Rails' own apply_stylesheet_media_default setting. Users who opt out of the legacy media default (by setting apply_stylesheet_media_default = false) were still getting media="screen" on stylesheet link tags generated by vite_javascript_tag. Changing the default to nil defers to stylesheet_link_tag's own behavior: when apply_stylesheet_media_default is true (Rails default), it still adds media="screen"; when it's false, no media attribute is rendered. Callers who need a specific value can still pass media: "screen" (or any other value) explicitly. Fixes ElMassimo#535
Owner
|
Hi Ernane! Given the setting was introduced in Rails 7, I think it makes sense to update Thanks! |
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.
Description 📖
Removes the hardcoded
media: "screen"default fromvite_javascript_tagso it defers to Rails' ownapply_stylesheet_media_defaultsetting instead of overriding it.Fixes #535
Background 📜
Rails introduced
config.action_view.apply_stylesheet_media_defaultto let apps opt out of the legacymedia="screen"behavior. Becausevite_javascript_tagwas explicitly passingmedia: "screen"tostylesheet_link_tag, though, this config had no effect on stylesheet tags generated by Vite entrypoints. Users who setapply_stylesheet_media_default = falsewere still gettingmedia="screen".The Fix 🔨
vite_javascript_tagnow passesmedia: nilinstead ofmedia: "screen", sostylesheet_link_tagcontrols the attribute. Whenapply_stylesheet_media_defaultistrue(the Rails default), behavior is unchanged. When it'sfalse, nomediaattribute is rendered. Callers can still pass an explicitmedia:value if needed.The change covers both
vite_railsandvite_rails_legacy.Screenshots 📷