Skip to content

Commit 8eca8d2

Browse files
justin808claude
andauthored
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: "⚠️ TEST CONFIGURATION - Do not copy directly for production apps" - Organized config into sections: Essential, Pro Features, Test-specific - Added comments explaining each configuration choice - References production docs for users ## Architecture ``` Generator Template (for user apps) └── Standalone Ruby script using PacksGenerator API Test Dummy Apps ├── spec/dummy/bin/shakapacker-precompile-hook (loads shared) ├── react_on_rails_pro/spec/dummy/bin/shakapacker-precompile-hook (loads shared) └── spec/support/shakapacker_precompile_hook_shared.rb (shared implementation) ``` ## Known Issues The "React Router Sixth Page" RSpec test failure is a pre-existing flaky test that also fails intermittently on master. This is not a regression from these changes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
1 parent 0f6bdcc commit 8eca8d2

File tree

0 file changed

+0
-0
lines changed

    0 file changed

    +0
    -0
    lines changed

    0 commit comments

    Comments
     (0)