-
-
Notifications
You must be signed in to change notification settings - Fork 638
Add Shakapacker precompile hook template for generator #1916
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Warning Rate limit exceeded@justin808 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 11 minutes and 23 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (9)
WalkthroughAdds a Shakapacker precompile hook: generator now installs an executable Changes
Sequence Diagram(s)sequenceDiagram
participant Precompile as Rails Precompile
participant Config as ReactOnRails::Configuration
participant PackerUtils as ReactOnRails::PackerUtils
participant Hook as bin/shakapacker-precompile-hook
participant Gen as PackGenerator / rake task
Precompile->>Config: adjust_precompile_task
Config->>PackerUtils: shakapacker_precompile_hook_configured?
alt precompile_hook configured
Config->>Hook: rely on configured hook (exec)
Hook->>Hook: load Rails env, call generate_packs_if_stale
Hook-->>Precompile: exit success/failure
else no hook
Config->>Gen: invoke react_on_rails:generate_packs
Gen->>Gen: generate packs inline
Gen-->>Precompile: return status
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Possibly related issues
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (2 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Pull Request ReviewSummaryThis PR introduces Shakapacker precompile hook support to automatically generate React on Rails packs before webpack compilation. The implementation is well-designed and solves the issue of manual task configuration, but there are several concerns that should be addressed. 🔴 Critical Issues1. Inconsistent Hook Script TemplatesThe template in
Issue: When users run the generator, they'll get the simple 20-line version, which may fail in contexts where the Rails root isn't easily resolvable (the exact issue #1912 is trying to fix). Recommendation: The generator template should match the more robust implementation in spec/dummy. Users need the same reliability. 2. Missing Tests for New FunctionalityNo tests were added for the new Required tests (in
3. Missing Tests for Skip LogicThe skip logic added to Required tests:
|
11e9b7b to
e403dd4
Compare
c32b1da to
39cdc26
Compare
Code Review - PR #1916OverviewThis PR adds a Shakapacker precompile hook template for the React on Rails generator, enabling automatic pack generation for newly generated projects. The implementation is well-structured and addresses an important DX improvement. ✅ Strengths1. Clean Architecture & Separation of Concerns
2. Error Handling
3. Documentation & Code Quality
4. File Permissions Handling
🔍 Issues & Concerns1. Missing Test Coverage
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
spec/dummy/config/shakapacker.yml (1)
14-14: Critical: Duplicate YAML key - remove this line.This
precompile_hookkey is duplicated on lines 28-31. YAML does not allow duplicate keys in the same mapping. Remove this line since the more complete definition with security comments exists below.Apply this diff:
- precompile_hook: bin/shakapacker-precompile-hooklib/react_on_rails/dev/server_manager.rb (1)
251-256: Remove redundant "Fast recompilation" bullet.Line 255 adds a "Fast recompilation" bullet, but Line 252 already mentions "Webpack dev server for fast recompilation." These convey the same information.
Apply this diff to remove the redundant bullet:
#{Rainbow('•').yellow} #{Rainbow('React on Rails pack generation (via precompile hook or bin/dev)').white} #{Rainbow('•').yellow} #{Rainbow('Webpack dev server for fast recompilation').white} #{Rainbow('•').yellow} #{Rainbow('Source maps for debugging').white} #{Rainbow('•').yellow} #{Rainbow('May have Flash of Unstyled Content (FOUC)').white} - #{Rainbow('•').yellow} #{Rainbow('Fast recompilation').white} #{Rainbow('•').yellow} #{Rainbow('Access at:').white} #{Rainbow('http://localhost:3000/<route>').cyan.underline}
🧹 Nitpick comments (2)
lib/react_on_rails/packer_utils.rb (1)
170-181: Consider the fragility of accessing private methods.The implementation correctly detects the precompile hook configuration. However, line 175 uses
send(:data)to access Shakapacker's private method. While this appears necessary to read the raw config data, it's fragile and could break with Shakapacker updates.The error handling with
rescue StandardErrorprovides a safe fallback, which mitigates this risk.If Shakapacker provides a public API to access config values in the future, consider switching to that approach for better maintainability. For now, the current implementation with error handling is acceptable.
lib/react_on_rails/dev/server_manager.rb (1)
284-293: Consider clarifying when each pack generation mechanism is used.The comment on lines 291-292 mentions two pack generation mechanisms but doesn't specify when each is used. Consider making this more explicit for maintainability.
- # NOTE: Pack generation happens automatically during assets:precompile - # either via precompile hook or via the configuration.rb adjust_precompile_task + # NOTE: Pack generation happens automatically during assets:precompile: + # - via precompile hook (if configured in shakapacker.yml) + # - or via configuration.rb adjust_precompile_task (fallback if no hook configured)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (10)
lib/generators/react_on_rails/base_generator.rb(1 hunks)lib/generators/react_on_rails/templates/base/base/bin/shakapacker-precompile-hook(1 hunks)lib/generators/react_on_rails/templates/base/base/config/shakapacker.yml(1 hunks)lib/react_on_rails/configuration.rb(1 hunks)lib/react_on_rails/dev/pack_generator.rb(1 hunks)lib/react_on_rails/dev/server_manager.rb(4 hunks)lib/react_on_rails/packer_utils.rb(1 hunks)spec/dummy/config/shakapacker.yml(1 hunks)spec/react_on_rails/dev/pack_generator_spec.rb(2 hunks)spec/react_on_rails/packer_utils_spec.rb(1 hunks)
🧰 Additional context used
🧠 Learnings (11)
📚 Learning: 2025-02-18T13:08:01.477Z
Learnt from: AbanoubGhadban
Repo: shakacode/react_on_rails PR: 1644
File: lib/react_on_rails/helper.rb:190-197
Timestamp: 2025-02-18T13:08:01.477Z
Learning: RSC support validation in React on Rails Pro is handled through a chain of validations:
1. Pro version check in `run_stream_inside_fiber`
2. RSC support check during pack generation via `ReactOnRailsPro.configuration.enable_rsc_support`
3. RSC support validation during component registration
This makes additional validation in the helper methods unnecessary.
Applied to files:
spec/react_on_rails/dev/pack_generator_spec.rblib/react_on_rails/packer_utils.rbspec/react_on_rails/packer_utils_spec.rblib/generators/react_on_rails/templates/base/base/bin/shakapacker-precompile-hook
📚 Learning: 2025-10-23T17:22:01.074Z
Learnt from: AbanoubGhadban
Repo: shakacode/react_on_rails PR: 1875
File: lib/react_on_rails/utils.rb:112-124
Timestamp: 2025-10-23T17:22:01.074Z
Learning: In React on Rails, when Pro is installed but not licensed, the intended behavior is to raise an error on boot. The `react_on_rails_pro?` method validates licenses and should raise errors early (including during path resolution in methods like `server_bundle?`) to enforce licensing requirements rather than failing later with obscure errors.
Applied to files:
spec/react_on_rails/dev/pack_generator_spec.rblib/react_on_rails/packer_utils.rblib/generators/react_on_rails/templates/base/base/bin/shakapacker-precompile-hook
📚 Learning: 2024-10-08T20:53:47.076Z
Learnt from: justin808
Repo: shakacode/react_on_rails PR: 1622
File: spec/dummy/spec/rake/assets_precompile_rake_spec.rb:12-12
Timestamp: 2024-10-08T20:53:47.076Z
Learning: When stubbing environment variables in RSpec tests, use `before` and `after` hooks to ensure that the original values are restored after the tests, preventing any side effects on other tests. Example provided by justin808:
```ruby
describe "My test" do
before do
original_value = ENV["VARIABLE_NAME"]
allow(ENV).to receive(:[]).with("VARIABLE_NAME").and_return("stubbed_value")
end
after do
allow(ENV).to receive(:[]).with("VARIABLE_NAME").and_call_original
ENV["VARIABLE_NAME"] = original_value
end
it "tests something" do
# Your test code here
end
end
```
This practice ensures test isolation and reliability.
Applied to files:
spec/react_on_rails/dev/pack_generator_spec.rb
📚 Learning: 2025-02-13T14:29:49.267Z
Learnt from: AbanoubGhadban
Repo: shakacode/react_on_rails PR: 1644
File: spec/react_on_rails/utils_spec.rb:218-218
Timestamp: 2025-02-13T14:29:49.267Z
Learning: In RSpec tests, prefer using local variables over constants within test blocks to avoid constant redefinition warnings and maintain better test isolation.
Applied to files:
spec/react_on_rails/dev/pack_generator_spec.rbspec/react_on_rails/packer_utils_spec.rb
📚 Learning: 2025-09-16T08:01:11.146Z
Learnt from: justin808
Repo: shakacode/react_on_rails PR: 1770
File: lib/generators/react_on_rails/templates/base/base/app/javascript/src/HelloWorld/ror_components/HelloWorld.client.jsx:2-2
Timestamp: 2025-09-16T08:01:11.146Z
Learning: React on Rails uses webpack CSS Modules configuration with namedExports: true, which requires the import syntax `import * as style from './file.module.css'` rather than the default export pattern. This configuration enables better tree shaking and bundle size optimization for CSS modules.
Applied to files:
spec/react_on_rails/dev/pack_generator_spec.rblib/generators/react_on_rails/templates/base/base/config/shakapacker.ymllib/react_on_rails/configuration.rblib/react_on_rails/dev/server_manager.rblib/generators/react_on_rails/templates/base/base/bin/shakapacker-precompile-hook
📚 Learning: 2025-02-12T16:38:06.537Z
Learnt from: Romex91
Repo: shakacode/react_on_rails PR: 1697
File: package-scripts.yml:28-28
Timestamp: 2025-02-12T16:38:06.537Z
Learning: The file `node_package/lib/ReactOnRails.full.js` is autogenerated during the build process and should not be present in the repository.
Applied to files:
lib/generators/react_on_rails/templates/base/base/config/shakapacker.ymllib/generators/react_on_rails/base_generator.rblib/react_on_rails/configuration.rblib/react_on_rails/dev/server_manager.rblib/generators/react_on_rails/templates/base/base/bin/shakapacker-precompile-hook
📚 Learning: 2025-07-08T05:57:29.630Z
Learnt from: AbanoubGhadban
Repo: shakacode/react_on_rails PR: 1745
File: node_package/src/RSCRequestTracker.ts:8-14
Timestamp: 2025-07-08T05:57:29.630Z
Learning: The global `generateRSCPayload` function in React on Rails Pro (RORP) is provided by the framework during rendering requests, not implemented in application code. The `declare global` statements are used to document the expected interface that RORP will inject at runtime.
Applied to files:
lib/generators/react_on_rails/templates/base/base/config/shakapacker.ymllib/generators/react_on_rails/templates/base/base/bin/shakapacker-precompile-hook
📚 Learning: 2025-04-26T21:55:55.874Z
Learnt from: alexeyr-ci2
Repo: shakacode/react_on_rails PR: 1732
File: spec/dummy/client/app-react16/startup/ReduxSharedStoreApp.client.jsx:40-44
Timestamp: 2025-04-26T21:55:55.874Z
Learning: In the react_on_rails project, files under `app-react16` directories are copied/moved to corresponding `/app` directories during the conversion process (removing the `-react16` suffix), which affects their relative import paths at runtime.
Applied to files:
lib/generators/react_on_rails/base_generator.rblib/react_on_rails/configuration.rblib/react_on_rails/dev/server_manager.rblib/generators/react_on_rails/templates/base/base/bin/shakapacker-precompile-hook
📚 Learning: 2025-09-29T14:45:42.687Z
Learnt from: AbanoubGhadban
Repo: shakacode/react_on_rails PR: 1833
File: lib/react_on_rails/dev/process_manager.rb:72-83
Timestamp: 2025-09-29T14:45:42.687Z
Learning: In Ruby bundler contexts, when bundler intercepts system commands for executables not in the Gemfile, both version checks (like `system("foreman", "--version")`) and execution commands (like `system("foreman", "start", ...)`) fail equally, both returning false. This means availability checks using version flags accurately reflect whether execution commands will work in the current bundler context.
Applied to files:
spec/react_on_rails/packer_utils_spec.rb
📚 Learning: 2025-09-15T21:24:48.207Z
Learnt from: AbanoubGhadban
Repo: shakacode/react_on_rails PR: 1781
File: node_package/src/ClientSideRenderer.ts:82-95
Timestamp: 2025-09-15T21:24:48.207Z
Learning: In React on Rails, the force_load feature includes both explicit `data-force-load="true"` usage and the ability to hydrate components during the page loading state (`document.readyState === 'loading'`). Both capabilities require a Pro license, so the condition `!railsContext.rorPro && (isComponentForceLoaded || document.readyState === 'loading')` correctly gates both scenarios.
Applied to files:
lib/react_on_rails/dev/server_manager.rb
📚 Learning: 2025-04-09T12:56:10.756Z
Learnt from: AbanoubGhadban
Repo: shakacode/react_on_rails PR: 1696
File: node_package/src/RSCPayloadContainer.ts:0-0
Timestamp: 2025-04-09T12:56:10.756Z
Learning: In the react_on_rails codebase, RSC payloads are already stringified using `JSON.stringify()` before being processed by the `escapeScript` function, which handles escaping of special characters. The function only needs to handle specific HTML markers like comments and closing script tags.
Applied to files:
lib/generators/react_on_rails/templates/base/base/bin/shakapacker-precompile-hook
🧬 Code graph analysis (5)
spec/react_on_rails/dev/pack_generator_spec.rb (1)
lib/react_on_rails/dev/pack_generator.rb (2)
generate(8-132)generate(10-30)
lib/react_on_rails/dev/pack_generator.rb (1)
lib/react_on_rails/packer_utils.rb (1)
shakapacker_precompile_hook_configured?(172-181)
spec/react_on_rails/packer_utils_spec.rb (1)
lib/react_on_rails/packer_utils.rb (1)
shakapacker_precompile_hook_configured?(172-181)
lib/react_on_rails/configuration.rb (1)
lib/react_on_rails/packer_utils.rb (1)
shakapacker_precompile_hook_configured?(172-181)
lib/react_on_rails/dev/server_manager.rb (1)
lib/react_on_rails/packer_utils.rb (1)
shakapacker_precompile_hook_configured?(172-181)
🪛 YAMLlint (1.37.1)
spec/dummy/config/shakapacker.yml
[error] 31-31: duplication of key "precompile_hook" in mapping
(key-duplicates)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
- GitHub Check: examples (3.2, minimum)
- GitHub Check: rspec-package-tests (3.4, latest)
- GitHub Check: rspec-package-tests (3.2, minimum)
- GitHub Check: build
- GitHub Check: claude-review
🔇 Additional comments (11)
lib/react_on_rails/configuration.rb (1)
241-244: LGTM! Clean conditional logic for hook detection.The implementation correctly skips pack generation when a Shakapacker precompile hook is configured, avoiding redundant work. The comment clearly explains the purpose.
spec/dummy/config/shakapacker.yml (1)
28-31: Keep this definition; remove the duplicate on line 14.This is the correct
precompile_hookdefinition with proper documentation. The duplicate on line 14 should be removed.lib/generators/react_on_rails/base_generator.rb (2)
40-41: LGTM! Precompile hook added to base files.The hook script is correctly included in the base files list for copying.
48-49: LGTM! Proper executable permissions set.The chmod is correctly applied after the file is copied, ensuring the hook script is executable. The 0o755 permissions are appropriate for a shell/script file.
spec/react_on_rails/packer_utils_spec.rb (1)
143-183: LGTM! Comprehensive test coverage for hook detection.The test suite thoroughly covers all scenarios:
- Hook configured (returns true)
- Hook not configured with nil/empty values (returns false)
- Shakapacker not available (returns false)
- Error handling (returns false)
The use of
hide_constand proper mocking demonstrates good testing practices.lib/react_on_rails/dev/pack_generator.rb (1)
11-15: LGTM! Clean early-exit pattern for hook detection.The guard clause correctly skips pack generation when a Shakapacker precompile hook is configured, providing appropriate feedback in verbose mode while remaining silent otherwise.
spec/react_on_rails/dev/pack_generator_spec.rb (2)
8-33: LGTM! Comprehensive test coverage for hook-configured behavior.The new test context thoroughly validates the skip behavior:
- Verbose mode outputs the skip message
- Silent mode produces no output
- The rake task is not invoked
Excellent use of mocking to verify side effects.
47-48: Good practice: Explicit stub to maintain test isolation.Adding the explicit stub to ensure the hook is not configured prevents unintended side effects on existing tests. This demonstrates good test hygiene.
lib/generators/react_on_rails/templates/base/base/bin/shakapacker-precompile-hook (1)
1-30: Verification complete: Rainbow gem is properly declared as a dependency.The Rainbow gem is declared as a dependency in react_on_rails.gemspec with version constraint "~> 3.0", confirming it will be available when the precompile hook script executes. The script is well-structured with clear documentation, proper environment variable configuration, correct require_relative path, and robust error handling with colored output.
lib/react_on_rails/dev/server_manager.rb (2)
260-260: LGTM! Help text accurately reflects the precompile hook mechanism.The updated documentation clearly explains how pack generation works in different modes (via precompile hook or bin/dev for development modes, via precompile hook or assets:precompile for production mode).
Also applies to: 268-268
417-433: LGTM! Conditional pack generation message is correctly implemented.The logic correctly shows "Generating React on Rails packs" only when the precompile hook is not configured, since the hook handles pack generation automatically during shakapacker compilation. The feature descriptions are clear and informative.
lib/generators/react_on_rails/templates/base/base/config/shakapacker.yml
Show resolved
Hide resolved
|
@claude review this PR |
|
I'll analyze this and get back to you. |
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. Changes: - Add bin/shakapacker-precompile-hook script to templates and spec/dummy - Update shakapacker.yml to configure precompile_hook - Add PackerUtils.shakapacker_precompile_hook_configured? method - Skip generate_packs in configuration and PackGenerator when hook configured - Update generator to copy hook script and make it executable The precompile hook runs before webpack compilation and is properly validated by Shakapacker to ensure it points to a file within the project root. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
The template file needs execute permission to pass RuboCop's Lint/ScriptPermission check. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
The shakapacker-precompile-hook was causing generator failures because it loads the Rails environment (which triggers version validation) before the react-on-rails npm package is installed during initial setup. This fix adds ENV["REACT_ON_RAILS_SKIP_VALIDATION"] = "true" at the start of the hook script to skip version validation, since the hook runs as part of the build process and doesn't need package version validation. Fixes CI failures in generator tests where the hook was executed during `rails generate react_on_rails:install` before packages were installed. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
The examples.yml workflow was experiencing Node.js V8 crashes during yarn cache dir commands, similar to the issue fixed in commit a1c71ea. This commit applies the same fix - disabling yarn caching until the upstream V8 issue is resolved. Error observed: ``` # Fatal error in , line 0 # unreachable code ``` Tracking: actions/setup-node#1028 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
The spec/dummy/config/shakapacker.yml had two `precompile_hook` entries which caused a YAML parsing error: YAMLException: duplicated mapping key (31:3) Removed the first instance at line 14, keeping the one with better documentation at line 31. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
The comment claimed "The hook command will be validated to ensure it points to a file within the project root" but no such validation exists in the codebase. Updated the comment to accurately reflect that users must ensure the hook path points to a trusted file they control. This removes the false promise of automatic validation and places the security responsibility appropriately on the user configuring the hook. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
6979fff to
57ddb2c
Compare
The master's sophisticated hook detection was looking for the hook at `:hooks/:precompile` but shakapacker.yml uses `precompile_hook` at the top level. Updated `extract_precompile_hook` to look in the correct location. Also updated specs to match the sophisticated implementation that checks if the hook actually contains the generate_packs rake task, rather than just checking for any hook presence. Fixes failing rspec-package-tests in CI. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
|
@claude review this PR |
|
Claude finished @justin808's task —— View job PR Review Complete ✅I've completed a comprehensive review of PR #1916: Add Shakapacker precompile hook template for generator. 📋 SummaryThis PR successfully adds a Shakapacker precompile hook template that enables automatic pack generation for newly generated React on Rails projects. The implementation is well-structured and addresses an important developer experience improvement. Overall Assessment: ✅ Ready to merge - The PR is well-implemented with proper test coverage and addresses previous review issues effectively. ✅ Strengths1. Comprehensive Test Coverage
2. Previous Review Issues AddressedThe commits show excellent response to previous reviews:
3. Clean Architecture
4. Error Handling
5. Documentation & Code Quality
6. File Permissions Handling
🔍 Code AnalysisKey Implementation Details1. Hook Detection Logic (lib/react_on_rails/packer_utils.rb:178-192)def self.shakapacker_precompile_hook_configured?
return false unless defined?(::Shakapacker)
hook_value = extract_precompile_hook
return false if hook_value.nil?
hook_contains_generate_packs?(hook_value)
rescue StandardError => e
warn "Warning: Unable to detect..." if ENV["DEBUG"]
false # Fail-safe: prefer running packs over skipping
endAnalysis:
2. Skip Logic Integration (lib/react_on_rails/dev/pack_generator.rb:29-36)if ReactOnRails::PackerUtils.shakapacker_precompile_hook_configured?
if verbose
hook_value = ReactOnRails::PackerUtils.shakapacker_precompile_hook_value
puts "⏭️ Skipping pack generation (handled by shakapacker...)"
end
return
endAnalysis:
3. Template Hook Script (lib/generators/react_on_rails/templates/base/base/bin/shakapacker-precompile-hook)ENV["REACT_ON_RAILS_SKIP_VALIDATION"] = "true"
require_relative "../config/environment"
begin
puts Rainbow("🔄 Running React on Rails precompile hook...").cyan
ReactOnRails::PacksGenerator.instance.generate_packs_if_stale
rescue StandardError => e
warn Rainbow("❌ Error in precompile hook: #{e.message}").red
warn e.backtrace.first(5).join("\n")
exit 1
endAnalysis:
💡 Minor Observations (No Action Required)1. Template vs. Dummy Hook DifferencesThe template hook (30 lines) is intentionally simpler than the dummy app hook (100+ lines):
Assessment: This is a reasonable design choice. The dummy app needs extra robustness for testing, while generated projects can use the simpler approach. If issues arise in production, the hook can be enhanced later. 2. Security Comment QualificationAfter commit 57ddb2c, the security comment correctly states:
This is properly qualified - it's guidance for users, not a claim about validation. ✅ Good fix. 3. Accessing Shakapacker Internals
config_data = ::Shakapacker.config.send(:data)Assessment: While accessing private methods is fragile, the error handling (rescue StandardError) provides proper mitigation. If Shakapacker's internals change, the method fails safe (returns false → packs still generate). 4. CHANGELOG Not UpdatedAccording to CLAUDE.md guidelines, user-visible features should be documented in CHANGELOG.md. This PR adds a new feature (precompile hook support for generated projects), but no CHANGELOG entry exists. Recommendation: Consider adding a CHANGELOG entry: #### [PR 1916](https://github.com/shakacode/react_on_rails/pull/1916) by [justin808](https://github.com/justin808)
- Added Shakapacker precompile hook template to React on Rails generator for automatic pack generation in new projectsHowever, this can be done in a follow-up or during release preparation. 🧪 Test Coverage AnalysisExcellent Coverage ✅packer_utils_spec.rb (lines 143-189):
pack_generator_spec.rb (lines 6-34):
Refactoring Quality: 🔒 Security AssessmentNo Security Issues Found ✅
The security comment advises users to only reference trusted scripts, which is appropriate guidance. 📝 Commit History AnalysisThe PR shows excellent iterative improvement:
This demonstrates responsive development and attention to review feedback. 🎯 Performance ImpactPositive Impact ✅
✅ Final RecommendationAPPROVE - Ready to Merge This PR demonstrates:
Optional Follow-up Items (Not Blockers)
🚀 Testing Suggestions for MergeBefore merging, verify:
Great work on this PR! The implementation is solid, well-tested, and significantly improves the developer experience for new React on Rails projects. The responsive iteration based on review feedback demonstrates excellent attention to detail. 🎉 |

Summary
Adds the Shakapacker precompile hook template file that will be used by the React on Rails generator when creating new projects. This template provides automatic pack generation support for projects using auto-bundling.
Changes
Added generator template:
lib/generators/react_on_rails/templates/base/base/bin/shakapacker-precompile-hookrequire_relative "../config/environment"to properly load Rails environmentReactOnRails::PacksGenerator.instance.generate_packs_if_staleto auto-generate packsUpdated base generator: Modified to copy the precompile hook template to new projects
Updated shakapacker.yml templates: Added
precompile_hookconfigurationEnhanced pack generator and server manager: Added support for detecting and using the precompile hook
Context
The dummy app already has its own version of this hook (merged via PR #1904) which includes the
find_rails_rootfunction for robust directory detection. This PR adds the template version that will be used for newly generated projects.Benefits
Testing
Related to #1912
🤖 Generated with Claude Code
This change is
Summary by CodeRabbit
New Features
Improvements
Tests
Chores