Add Pro/RSC setup checks to react_on_rails:doctor#2674
Conversation
Extend the doctor diagnostic command with two new conditional sections: - "React on Rails Pro Setup" — detects Pro gem, reports renderer mode (NodeRenderer vs ExecJS), provides guidance for RSC readiness. - "React Server Components" — when RSC is enabled via Pro config, validates: renderer mode (NodeRenderer required), rsc_payload_route presence, RSC bundler config (webpack/rspack), react-on-rails-rsc npm package, React version compatibility (19.0.x required, 19.0.4+ recommended), and Procfile RSC watcher entry. Both sections are skipped entirely for base-only installs (no noise). Uses runtime config (ReactOnRailsPro.configuration) instead of regex parsing for reliable detection. Each check includes actionable fix instructions. Closes #2427 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Two new checks in the Pro Setup section: 1. Pro initializer existence — warns if config/initializers/react_on_rails_pro.rb is missing, since Pro runs with all defaults without it. 2. Base package import scanning — detects JS files that import from 'react-on-rails' instead of 'react-on-rails-pro'. The base package is a transitive dependency of Pro, so these imports resolve silently but load the base version without Pro features (streaming, caching, RSC). Reproduced: webpack compiles without errors, but components registered through the base import lack Pro capabilities. Ref: #2427 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
react-on-rails-rsc is a peer dependency of react-on-rails-pro. When missing, webpack fails with a clear "Cannot find module 'react-on-rails-rsc/WebpackPlugin'" error that points directly to the cause. The doctor check added no diagnostic value over that error. Verified via reproduction in a test app: the webpack error is loud, specific, and includes the full require stack. Ref: #2427 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughAdds lazy Rails environment loading and new Pro and React Server Components (RSC) diagnostics to ReactOnRails::Doctor: initializer and renderer checks, JS/TS source import scanning, bundler config and route validation, React version detection, Procfile watcher checks, and extensive specs for these flows. Changes
Sequence Diagram(s)sequenceDiagram
participant CLI as Doctor (rsc:doctor)
participant Rails as Rails Env
participant FS as File System
participant Bundler as Bundler Configs
participant Procfile as Procfile.dev
participant Console as Console Output
CLI->>Rails: ensure_rails_environment_loaded()
Rails-->>CLI: loaded / failed (cached `@rails_environment_loaded`)
CLI->>FS: resolve_js_source_path() and scan imports
FS-->>CLI: report import findings
CLI->>Bundler: check RSC bundler config paths
Bundler-->>CLI: present / missing
CLI->>FS: check_rsc_payload_route() in routes.rb
FS-->>CLI: route present / missing
CLI->>FS: detect_react_version_from_deps()
FS-->>CLI: react version or compatibility warning
CLI->>Procfile: inspect Procfile.dev for RSC watcher (RSC_BUNDLE_ONLY)
Procfile-->>CLI: watcher present / missing
CLI->>Console: emit aggregated success/info/warning/error messages
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
📝 Coding Plan
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 |
Code ReviewOverall this is a well-structured addition. The gating logic ( Issues1. 2. Regex matches commented-out imports — false positives (inline comment) 3. 4. 5. Missing Minor / nits
🤖 Generated with Claude Code |
Greptile SummaryThis PR extends Key issues found during review:
Confidence Score: 3/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[run_all_checks] --> B{check_pro_setup}
B -->|react_on_rails_pro? = false| SKIP1[skip — no output]
B -->|react_on_rails_pro? = true| C[check_pro_initializer_existence]
C --> D[check_pro_renderer_mode]
D -->|NodeRenderer| D1[add_success]
D -->|other| D2[add_info x2]
D -->|raises| D3[add_warning rescue]
D1 & D2 & D3 --> E[check_base_package_imports]
E -->|no base imports| E1[add_success]
E -->|base imports found| E2[add_warning with file list]
E -->|raises| E3[add_warning rescue]
A --> F{check_rsc_setup}
F -->|react_on_rails_pro? = false| SKIP2[skip — no output]
F -->|RSC disabled| SKIP3[skip — no output]
F -->|RSC enabled| G[add_info x3]
G --> H[check_rsc_renderer_mode]
H -->|NodeRenderer| H1[pass — no message]
H -->|other| H2[add_error]
H1 & H2 --> I[check_rsc_payload_route]
I -->|route present| I1[add_success]
I -->|missing| I2[add_error]
I1 & I2 --> J[check_rsc_bundler_config]
J -->|config found| J1[add_success]
J -->|missing| J2[add_error]
J1 & J2 --> K[check_rsc_react_version]
K -->|19.0.4+| K1[add_success]
K -->|19.0.0-19.0.3| K2[add_warning — security vulns]
K -->|19.1+| K3[add_warning — unverified]
K -->|lt 19| K4[add_error]
K -->|undetectable| K5[add_info skip]
K1 & K2 & K3 & K4 & K5 --> L[check_rsc_procfile_watcher]
L -->|RSC_BUNDLE_ONLY present| L1[add_success]
L -->|missing| L2[add_warning]
F -->|raises anywhere| ERR[add_warning rescue]
Last reviewed commit: "Remove redundant RSC..." |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3dd56c080a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Two bugs found by review: 1. The doctor rake task doesn't depend on :environment, so Rails initializers haven't run when Pro/RSC checks execute. This means ReactOnRailsPro.configuration returns defaults (ExecJS, RSC disabled) instead of the app's configured values. Fix: lazily load config/environment.rb before reading Pro config, with a warning fallback if the app can't boot. 2. The base-package import scan hardcoded app/javascript/**, but Shakapacker's source_path can be anything (both dummy apps use client/app). Fix: read source_path from Shakapacker config, falling back to app/javascript. Ref: #2427 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Code ReviewOverall this is a solid, well-structured addition. The separation of concerns is clean, the messages are actionable, and gating the new sections on Pro detection avoids noise for OSS users. A few things worth addressing before merge: Bug: detect_react_version_from_deps reads the declared version, not the installed version. package.json frequently contains ranges like caret-19.0.0. After stripping the prefix the method yields 19.0.0 and the RSC check warns/errors even though 19.0.4 is actually installed. Reading from package-lock.json (.packages[node_modules/react].version) or yarn.lock would give the accurate installed version. Bug: check_base_package_imports can abort early on encoding errors. The inner File.read loop has no per-file encoding rescue. A single binary asset or non-UTF-8 file inside the source path raises Encoding::InvalidByteSequenceError and silently skips all remaining files; the outer rescue on line 2294 only surfaces a generic warning for the whole method. The existing scan_pattern_for_async already rescues encoding errors per file -- the same pattern should apply here. Fragile implicit ordering: check_rsc_setup depends on check_pro_setup having run first. check_rsc_setup reads ReactOnRailsPro.configuration but never calls ensure_rails_environment_loaded. It works today because check_pro_setup appears earlier in the checks array and calls it. If the order ever changes, or check_rsc_setup is invoked standalone in a test, it reads uninitialised default config values. Adding an explicit ensure_rails_environment_loaded call at the top of check_rsc_setup (mirroring check_pro_setup) makes the dependency self-contained. Minor: check_rsc_react_version errors on React 20+. The version logic covers major == 19 but has no branch for major >= 20. Future users on React 20 hit the else-branch and see a hard error claiming incompatibility. Worth adding a major >= 20 warning (unverified) or at minimum a comment noting the conservative intent. Nit: check_rsc_payload_route and check_rsc_procfile_watcher do not filter comments. String#include? will match a commented-out rsc_payload_route or RSC_BUNDLE_ONLY line and report a false success. Low likelihood in practice, but easy to address with a line-by-line filter similar to config_has_async_loading_strategy?. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6d3cb788a1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Reuse the existing parse_shakapacker_config method (which passes aliases: true) instead of a separate YAML.safe_load call. Without aliases: true, the fallback fails on standard shakapacker.yml files that use YAML anchors (default: &default / <<: *default). Also add ensure_rails_environment_loaded to check_rsc_setup for self-containment — it was relying on check_pro_setup running first. Ref: #2427 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Review: Add Pro/RSC setup checks to react_on_rails:doctorGood addition overall. The gating logic (skip entirely for non-Pro installs), the fallback chain for detecting the JS source path, and the decision to use Node module resolution instead of stripping semver ranges are all solid choices. Test coverage is thorough. Four issues to address (see inline comments for details): Bugs1. Duplicate warnings from ensure_rails_environment_loaded (line 2196) 2. Unreadable file aborts the entire import scan (line 2274) Minor issues3. Side-effect imports not detected (line 2263) 4. devDependencies silently wins in declared_react_version (line 2459) Nits
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 21cc667181
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
1. Cache failed Rails boot attempts so ensure_rails_environment_loaded doesn't retry and emit the same warning from both check_pro_setup and check_rsc_setup. Reproduced: confirmed 2 identical warnings before fix, 1 after. 2. Remove `npm install react@~19.0.4` from the React 19.1+/20+ warning since it would suggest downgrading. Now just states verified compatibility is 19.0.4+. Ref: #2427 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Review: Add Pro/RSC setup checks to
|
|
Thanks @ihabadham |
## Summary - Extends `react_on_rails:doctor` with two new conditional diagnostic sections: **React on Rails Pro Setup** and **React Server Components** - Both sections are skipped entirely for base-only installs — zero noise for OSS users - Uses runtime config (`ReactOnRailsPro.configuration`) instead of regex parsing for reliable detection - Every error/warning includes actionable fix instructions ### Pro Setup checks (3) - **Pro initializer existence** — warns if `config/initializers/react_on_rails_pro.rb` is missing - **Renderer mode** — reports NodeRenderer vs ExecJS, notes NodeRenderer is required for RSC - **Base package import scanning** — detects JS files importing from `'react-on-rails'` instead of `'react-on-rails-pro'`. The base package is a transitive dependency of Pro, so these imports resolve silently but load the base version without Pro features (verified via reproduction) ### RSC checks (5, gated on `enable_rsc_support`) - **Renderer mode** — errors if RSC is enabled without NodeRenderer - **RSC payload route** — errors if `rsc_payload_route` is missing from routes (causes silent 404s) - **RSC bundler config** — errors if `rscWebpackConfig.js` is missing (checks both webpack and rspack paths) - **React version** — error for <19, warning for 19.0.0-19.0.3 (security vulns), warning for 19.1+ (unverified), success for 19.0.4+ - **Procfile RSC watcher** — warns if `RSC_BUNDLE_ONLY` entry is missing (warning-only since custom process managers are valid) Closes #2427 ## Test plan - [x] 98 doctor specs pass (7 new test groups with 30 examples covering all checks) - [x] RuboCop passes with zero offenses - [x] CI passes - [ ] Manual: run `rake react_on_rails:doctor` on a base install — Pro/RSC sections should not appear - [ ] Manual: run on a Pro install — Pro section should appear with initializer/renderer/import checks 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Enhanced diagnostics for Pro and React Server Components (RSC): validates renderer mode, bundler config presence, payload route, Procfile watcher, React version compatibility, and flags incorrect base-package imports. Detects Rails environment load issues and reports clear warnings with guidance. Scans customizable JS source paths when checking imports. * **Tests** * Expanded test coverage for the new diagnostics, edge cases, and error/warning reporting. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
## Summary - Extends `react_on_rails:doctor` with two new conditional diagnostic sections: **React on Rails Pro Setup** and **React Server Components** - Both sections are skipped entirely for base-only installs — zero noise for OSS users - Uses runtime config (`ReactOnRailsPro.configuration`) instead of regex parsing for reliable detection - Every error/warning includes actionable fix instructions ### Pro Setup checks (3) - **Pro initializer existence** — warns if `config/initializers/react_on_rails_pro.rb` is missing - **Renderer mode** — reports NodeRenderer vs ExecJS, notes NodeRenderer is required for RSC - **Base package import scanning** — detects JS files importing from `'react-on-rails'` instead of `'react-on-rails-pro'`. The base package is a transitive dependency of Pro, so these imports resolve silently but load the base version without Pro features (verified via reproduction) ### RSC checks (5, gated on `enable_rsc_support`) - **Renderer mode** — errors if RSC is enabled without NodeRenderer - **RSC payload route** — errors if `rsc_payload_route` is missing from routes (causes silent 404s) - **RSC bundler config** — errors if `rscWebpackConfig.js` is missing (checks both webpack and rspack paths) - **React version** — error for <19, warning for 19.0.0-19.0.3 (security vulns), warning for 19.1+ (unverified), success for 19.0.4+ - **Procfile RSC watcher** — warns if `RSC_BUNDLE_ONLY` entry is missing (warning-only since custom process managers are valid) Closes #2427 ## Test plan - [x] 98 doctor specs pass (7 new test groups with 30 examples covering all checks) - [x] RuboCop passes with zero offenses - [x] CI passes - [ ] Manual: run `rake react_on_rails:doctor` on a base install — Pro/RSC sections should not appear - [ ] Manual: run on a Pro install — Pro section should appear with initializer/renderer/import checks 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Enhanced diagnostics for Pro and React Server Components (RSC): validates renderer mode, bundler config presence, payload route, Procfile watcher, React version compatibility, and flags incorrect base-package imports. Detects Rails environment load issues and reports clear warnings with guidance. Scans customizable JS source paths when checking imports. * **Tests** * Expanded test coverage for the new diagnostics, edge cases, and error/warning reporting. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
Summary
react_on_rails:doctorwith two new conditional diagnostic sections: React on Rails Pro Setup and React Server ComponentsReactOnRailsPro.configuration) instead of regex parsing for reliable detectionPro Setup checks (3)
config/initializers/react_on_rails_pro.rbis missing'react-on-rails'instead of'react-on-rails-pro'. The base package is a transitive dependency of Pro, so these imports resolve silently but load the base version without Pro features (verified via reproduction)RSC checks (5, gated on
enable_rsc_support)rsc_payload_routeis missing from routes (causes silent 404s)rscWebpackConfig.jsis missing (checks both webpack and rspack paths)RSC_BUNDLE_ONLYentry is missing (warning-only since custom process managers are valid)Closes #2427
Test plan
rake react_on_rails:doctoron a base install — Pro/RSC sections should not appear🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Tests