[codex] Fix Propshaft asset version cache busting#1403
[codex] Fix Propshaft asset version cache busting#1403
Conversation
Code ReviewThis is a clean, well-scoped fix for the Propshaft boot crash (fixes #1358). The duck-typing approach is the right call for supporting multiple asset pipeline backends. A few observations: Positive
Issues & Suggestions1. Missing test:
test "cache busting is a no-op when assets is nil" do
assert_nothing_raised do
React::Rails::Railtie.append_react_build_to_assets_version!(nil, "development")
end
end2. Missing test: assets with no resolvable version Similarly, if test "cache busting is a no-op when assets has no version" do
assets = Object.new # no version, no config
assert_nothing_raised do
React::Rails::Railtie.append_react_build_to_assets_version!(assets, "development")
end
end3.
A small comment near the method declaration (e.g., 4. Idempotency: multiple calls compound the version string If the initializer runs more than once (e.g., in certain test harness or Spring reloader scenarios), each call appends another versioned_assets.version = [versioned_assets.version, "react-#{react_build}"].compact.join("-")
# Note: not idempotent — repeated calls keep appending. This is acceptable because
# Rails initializers run exactly once per process.Minor nitIn def self.versioned_assets?(assets)
assets&.respond_to?(:version) && assets.respond_to?(:version=)
endThe first clause uses the safe-navigation SummaryThe fix itself is correct and handles the Propshaft case cleanly. The main gap is test coverage for edge-case inputs (nil, unrecognized objects). Addressing those would make this production-ready without concern. |
Summary
Fix the
react_rails.bust_cacheinitializer so it can update the asset version for both Sprockets-style asset environments and Propshaft assemblies.Root Cause
react-railstreatedapp.assetslike a Sprockets environment and wroteversiondirectly on it. In Propshaft 1.3.1,app.assetsis aPropshaft::Assembly, and the writableversionlives onapp.assets.config, which caused boot to fail withundefined method 'version'.Changes
versionobjects and Propshaft-style assembliesValidation
PATH=$HOME/.local/share/mise/installs/ruby/3.2.9/bin:$PATH bundle exec ruby -Itest test/react/rails/railtie_test.rbPATH=$HOME/.local/share/mise/installs/ruby/3.2.9/bin:$PATH BUNDLE_GEMFILE=gemfiles/propshaft.gemfile bundle exec ruby -Itest test/react/rails/railtie_test.rbFixes #1358