Skip to content

fix: stop overriding Rails' media default in vite_javascript_tag#610

Merged
ElMassimo merged 2 commits into
ElMassimo:mainfrom
ErnaneJ:fix/535-remove-media-screen-default
Jul 3, 2026
Merged

fix: stop overriding Rails' media default in vite_javascript_tag#610
ElMassimo merged 2 commits into
ElMassimo:mainfrom
ErnaneJ:fix/535-remove-media-screen-default

Conversation

@ErnaneJ

@ErnaneJ ErnaneJ commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Description 📖

Removes the hardcoded media: "screen" default from vite_javascript_tag so it defers to Rails' own apply_stylesheet_media_default setting instead of overriding it.

Fixes #535

Background 📜

Rails introduced config.action_view.apply_stylesheet_media_default to let apps opt out of the legacy media="screen" behavior. Because vite_javascript_tag was explicitly passing media: "screen" to stylesheet_link_tag, though, this config had no effect on stylesheet tags generated by Vite entrypoints. Users who set apply_stylesheet_media_default = false were still getting media="screen".

The Fix 🔨

vite_javascript_tag now passes media: nil instead of media: "screen", so stylesheet_link_tag controls the attribute. When apply_stylesheet_media_default is true (the Rails default), behavior is unchanged. When it's false, no media attribute is rendered. Callers can still pass an explicit media: value if needed.

The change covers both vite_rails and vite_rails_legacy.

Screenshots 📷

Ernane and others added 2 commits July 3, 2026 12:49
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
@ElMassimo

Copy link
Copy Markdown
Owner

Hi Ernane! Given the setting was introduced in Rails 7, I think it makes sense to update vite_rails, but not vite_rails_legacy.

Thanks!

@ElMassimo ElMassimo merged commit a7cd412 into ElMassimo:main Jul 3, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove default media: 'screen' for stylesheet tag in line with Rails defaults

2 participants