-
-
Notifications
You must be signed in to change notification settings - Fork 633
Description
Summary
Add --pro and --rsc flags to the existing rails g react_on_rails:install generator to enable native setup of React on Rails Pro and React Server Components.
New commands:
rails g react_on_rails:install --pro # Sets up Pro with Node Renderer
rails g react_on_rails:install --rsc # Sets up RSC (includes Pro)Motivation
Currently, setting up React on Rails Pro or RSC requires manual file creation:
- Creating
config/initializers/react_on_rails_pro.rb - Creating
client/node-renderer.js - Adding processes to
Procfile.dev - Installing npm packages manually
- For RSC: webpack config, component wrappers, routes
This is error-prone and doesn't follow the pattern of the existing generator which handles all setup automatically.
Proposed Implementation
Phase 1: Foundation
- Add
--proand--rscclass options toInstallGenerator - Add detection helpers (
use_pro?,use_rsc?,pro_gem_installed?) - Add prerequisite validation (Pro gem must be installed)
Phase 2: Pro Generator
When --pro is used:
- Create
config/initializers/react_on_rails_pro.rbwith Node Renderer config - Create
client/node-renderer.jsbootstrap file - Append node-renderer process to
Procfile.dev - Install
react-on-rails-proandreact-on-rails-pro-node-renderernpm packages
Phase 3: RSC Generator
When --rsc is used (automatically includes Pro):
- Create RSC webpack config (
rscWebpackConfig.js) - Create RSC example components with proper wrapper pattern
- Add RSC bundle watcher to
Procfile.dev - Add
rsc_payload_routeto routes - Install RSC npm packages
Phase 4: Testing
- Unit tests for prerequisite validation
- Integration tests for
--proflag - Integration tests for
--rscflag - Test combinations with existing flags (
--typescript,--redux,--rspack)
Phase 5: Documentation
- Update generator USAGE file
- Update docs with Pro/RSC generator options
Design Decisions
Additive Pattern (Sidekiq-style)
Follow Sidekiq's open-core pattern - extend the existing generator with flags rather than creating separate generators. Single entry point is cleaner UX, and Pro adds capabilities, not separate workflows.
--rsc Implies --pro
RSC technically requires Pro (can't use RSC without it). This reduces redundant typing and follows Rails convention (e.g., --api implies many other changes).
Node Renderer is Core Pro
When --pro is used, Node Renderer is set up by default. Node Renderer is the primary reason to upgrade to Pro - ExecJS is described as crash-prone at scale in Pro docs.
No Separate Migration Generator
The --pro flag works for both fresh installs AND existing React on Rails apps. Adding Pro to an existing app is the normal flow (most users already have React on Rails), and Pro-specific files are inherently additive.
Additive File Operations
Pro/RSC file generation uses additive operations (append_to_file, inject_into_file) that work on both fresh and existing apps. This makes the generator idempotent and safe to run multiple times.
Compatibility
Both flags should work with existing flags:
--typescript/--no-typescript--redux--rspack
Success Criteria
-
rails g react_on_rails:install --procreates working Pro setup -
rails g react_on_rails:install --rsccreates working RSC setup - All existing tests continue to pass
- Generated app starts and renders correctly