Commit 8eca8d2
Simplify precompile hook and restore Pro dummy app to async loading (#2053)
## Summary
This PR improves the organization and documentation of precompile hooks
across the React on Rails codebase.
## Changes
### 1. Shared Test Helper for Dummy Apps
- Created `spec/support/shakapacker_precompile_hook_shared.rb` (112
lines)
- Both OSS and Pro dummy apps now load this shared implementation
- Eliminates code duplication between test apps
- Includes ReScript build support and proper error handling
- Keeps test-only code in test directories (not in lib/)
### 2. Test Dummy App Hooks (Simple Wrappers)
Both `spec/dummy/bin/shakapacker-precompile-hook` and
`react_on_rails_pro/spec/dummy/bin/shakapacker-precompile-hook` are now
just ~19 lines that load the shared implementation.
### 3. Generator Template (Standalone, Production-Ready)
The
`lib/generators/react_on_rails/templates/base/base/bin/shakapacker-precompile-hook`
is a 30-line Ruby script that:
- Uses `ReactOnRails::PacksGenerator.instance.generate_packs_if_stale`
directly
- Requires Rails environment to properly use the gem's API
- Has clear error handling with Rainbow-colored output
- Well-documented with emoji scheme and comments
- Sets `REACT_ON_RAILS_SKIP_VALIDATION=true` with explanation
- **Completely standalone** - no dependencies on gem internals, works in
any generated app
### 4. Restored Pro Dummy App to async: true
- Changed from `defer: true` back to `async: true` in
application.html.erb
- `async: true` is the recommended approach for Shakapacker >= 8.2.0
- Enables React 18's Selective Hydration for optimal Time to Interactive
(TTI)
- Aligns with best practices documented in streaming-server-rendering.md
### 5. Better Pro Dummy App Configuration Documentation
- Added clear header: "1 parent 0f6bdcc commit 8eca8d2
File tree
0 file changed
+0
-0
lines changed0 file changed
+0
-0
lines changed
0 commit comments