Conversation
This branch has not been deployed
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 📖
This pull request fixes #615.
vite_stylesheet_tagnow links the CSS that Vite emitted for a CSS-only entrypoint, including the Vite 8 / Rolldown case where the manifestfilefor that entry is a JavaScript wrapper.Background 📜
This was happening because
vite_stylesheet_tagusedpath_for, which always returns the entry'sfile. For some CSS-only entrypoints Rolldown writes a.jswrapper tofileand puts the real stylesheet incss[], like this:So in production the helper rendered
<link rel="stylesheet" href="/vite/assets/print.4b6e2a1f.js">and the page lost its styles. Development is not affected, because the dev server serves the source path directly.The Fix 🔨
By changing
vite_stylesheet_tagto resolve each name withresolve_entries(name, type: :stylesheet), which is the same approach as the workaround in the issue:fileis a.cssfile, it is kept (normal CSS entries render exactly as before);css[]paths are added and deduplicated;css[]paths (always the case while the dev server runs),fileis used, so dev paths such asentrypoints/sassy.scssare unchanged.Tests:
test_vite_stylesheet_tag_with_javascript_wrapper_entryintest/helper_test.rb, with a wrapper entry added to themanifest-assets.jsonfixture. Onmainit fails withhref="/vite-production/assets/print.4b6e2a1f.js"; with this change it rendersprint.9c0d7e35.css, and the dev-server path stays/vite-dev/entrypoints/print.css.bin/rake test(Ruby 4.0.3, Rails 8.1 from the rootGemfile): 121 tests, 0 failures (120 tests, 0 failures onmain).rubocopon the changed Ruby files: no offenses.git diff --check: clean.An AI coding agent (Claude Code, run by breken-ai) found this bug and wrote this change; I checked the red/green test above before opening the PR.
Screenshots 📷
Not applicable: this changes the generated stylesheet URL and has no visual UI.