-
-
Notifications
You must be signed in to change notification settings - Fork 633
Description
Environment
- Ruby version: 3.3.7
- Rails version: 8.0.4
- Shakapacker version: 9.4.0
- React on Rails version: 16.2.0.rc.0
Summary
When running rails generate react_on_rails:install on a fresh Rails app, the generator creates bin/shakapacker-precompile-hook but doesn't configure it in shakapacker.yml when Shakapacker is installed first (which is the normal flow).
Expected behavior
After running the generator, config/shakapacker.yml should have:
precompile_hook: 'bin/shakapacker-precompile-hook'This is the intended configuration per PR #1916 commit message:
"This change leverages Shakapacker's new precompile_hook feature to automatically generate packs before webpack compilation, replacing the need to manually modify assets:precompile tasks or bin/dev scripts."
Actual behavior
The generator:
- ✅ Creates
bin/shakapacker-precompile-hookscript - ❌ Leaves
precompile_hook: ~(commented out) inshakapacker.yml
$ ls -la bin/shakapacker-precompile-hook
-rwxr-xr-x 1 user user 1023 Jan 4 18:06 bin/shakapacker-precompile-hook
$ grep precompile_hook config/shakapacker.yml
# Example: precompile_hook: 'bin/shakapacker-precompile-hook'
# precompile_hook: ~Root Cause
In base_generator.rb, when Shakapacker is installed first:
def copy_packer_config
if File.exist?(".shakapacker_just_installed")
puts "Skipping Shakapacker config copy..."
File.delete(".shakapacker_just_installed")
configure_rspack_in_shakapacker if options.rspack? # rspack gets configured
return # but precompile_hook doesn't!
end
# ... copies template with precompile_hook configured
endThe generator has configure_rspack_in_shakapacker to modify existing shakapacker.yml for rspack, but no equivalent method for precompile_hook.
Steps to Reproduce
rails new test_app --minimal
cd test_app
# Add react_on_rails to Gemfile
bundle install
rails generate react_on_rails:install
grep precompile_hook config/shakapacker.yml
# Shows: # precompile_hook: ~Impact
The app still works because bin/dev and adjust_precompile_task have fallback logic. But:
- The intended/optimized configuration isn't applied
- Pack generation happens later in the pipeline instead of before webpack
- Users don't get the benefit of the precompile_hook optimization
Suggested Fix
Add a configure_precompile_hook_in_shakapacker method similar to configure_rspack_in_shakapacker that adds the precompile_hook line to existing shakapacker.yml files.