fix: rename generated layout hello_world → react_on_rails_default#2482
fix: rename generated layout hello_world → react_on_rails_default#2482
Conversation
|
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:
WalkthroughGenerator now emits a react_on_rails_default layout by default. RSC setup adds layout-resolution logic that reuses a compatible existing layout when possible or creates a new compatible layout and returns the chosen layout name for generated controllers. Tests and templates updated accordingly. Changes
Sequence Diagram(s)sequenceDiagram
participant Gen as RSC Generator
participant RscSetup as RscSetup
participant FS as FileSystem
participant Config as Template Config
Gen->>RscSetup: create_hello_server_controller()
RscSetup->>RscSetup: resolve_hello_server_layout_name()
RscSetup->>FS: read app/controllers/hello_world_controller.rb (if exists)
RscSetup->>FS: scan app/views/layouts/* for candidate layouts
RscSetup->>RscSetup: compatible_layout?(name) -> check for auto-registration pack tags
alt Compatible layout found
RscSetup->>Config: return existing layout name
else No compatible layout
RscSetup->>FS: create new layout file (react_on_rails_default or next available)
RscSetup->>FS: optionally announce incompatible existing layouts
RscSetup->>Config: return new layout name
end
Config-->>Gen: layout_name
Gen->>FS: generate controller using layout_name
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 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 |
Greptile SummaryRenamed the generator layout from Key changes:
Issue found:
Confidence Score: 4/5
Important Files Changed
Last reviewed commit: ede7f4f |
Code ReviewOverall this is a well-scoped rename with a clear rationale. The rename is applied consistently across generator templates, spec files, and the Bundled unrelated changesThe PR title says "rename layout", but three additional concerns are folded in:
None of these are blockers; they're all improvements. Just flagging for awareness. Test coverage gapsNon-RSC layout file not asserted. The four contexts that
Minor nit: CHANGELOG orderingThe new "Changed" section is placed before the existing "Fixed" section, which matches the conventional Keep-a-Changelog order ( |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@CHANGELOG.md`:
- Line 36: Update the Unreleased changelog entry for PR `#2429` to reflect the
rename from hello_world to react_on_rails_default introduced in PR `#2482`:
replace references to hello_world.html.erb and layout "hello_world" with
react_on_rails_default (e.g., the generator now always copies
react_on_rails_default.html.erb and HelloServerController uses layout
"react_on_rails_default") and ensure the sentence about post-install output
still mentioning stream_react_component is preserved or adjusted as needed to
match the final behavior.
ℹ️ Review info
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (11)
CHANGELOG.mdreact_on_rails/lib/generators/react_on_rails/base_generator.rbreact_on_rails/lib/generators/react_on_rails/generator_messages.rbreact_on_rails/lib/generators/react_on_rails/templates/base/base/app/controllers/hello_world_controller.rbreact_on_rails/lib/generators/react_on_rails/templates/base/base/app/views/layouts/react_on_rails_default.html.erbreact_on_rails/lib/generators/react_on_rails/templates/rsc/base/app/controllers/hello_server_controller.rbreact_on_rails/lib/generators/react_on_rails/templates/rsc/base/app/views/hello_server/index.html.erbreact_on_rails/spec/react_on_rails/generators/install_generator_spec.rbreact_on_rails/spec/react_on_rails/support/shared_examples/rsc_generator_examples.rbreact_on_rails_pro/spec/execjs-compatible-dummy/app/controllers/hello_world_controller.rbreact_on_rails_pro/spec/execjs-compatible-dummy/app/views/layouts/react_on_rails_default.html.erb
Code ReviewThis is a clean, well-executed rename. The change is correctly scoped and the implementation is consistent across all relevant files. Correctness
All layout references are updated. No stray CHANGELOG is correct. The PR 2429 entry was also updated to use the new name — the greptile bot's comment about a CHANGELOG inconsistency is incorrect. Test QualityThe refactoring to The new No Issues Found
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
react_on_rails/spec/react_on_rails/support/shared_examples/base_generator_examples.rb (1)
22-26: Make the layout assertion tolerant to quote style.This test will fail if the template uses single quotes or slightly different spacing. A regex keeps the intent while reducing brittleness.
🔧 Suggested tweak
- assert_file "app/controllers/hello_world_controller.rb" do |content| - expect(content).to include('layout "react_on_rails_default"') - end + assert_file "app/controllers/hello_world_controller.rb" do |content| + expect(content).to match(/layout\s+["']react_on_rails_default["']/) + end🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@react_on_rails/spec/react_on_rails/support/shared_examples/base_generator_examples.rb` around lines 22 - 26, The assertion for the controller layout is brittle to quote style and spacing; replace the literal include check inside the assert_file block (the expect(content).to include('layout "react_on_rails_default"') call) with a regex match that allows single or double quotes and optional spacing, e.g. use expect(content).to match(/layout\s+["']react_on_rails_default["']/) so the test accepts either quote style and flexible whitespace.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In
`@react_on_rails/spec/react_on_rails/support/shared_examples/base_generator_examples.rb`:
- Around line 22-26: The assertion for the controller layout is brittle to quote
style and spacing; replace the literal include check inside the assert_file
block (the expect(content).to include('layout "react_on_rails_default"') call)
with a regex match that allows single or double quotes and optional spacing,
e.g. use expect(content).to match(/layout\s+["']react_on_rails_default["']/) so
the test accepts either quote style and flexible whitespace.
ℹ️ Review info
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
CHANGELOG.mdreact_on_rails/spec/react_on_rails/support/shared_examples/base_generator_examples.rb
🚧 Files skipped from review as they are similar to previous changes (1)
- CHANGELOG.md
7fb7859 to
e38e6c4
Compare
Review SummaryThe rename from Issues to Address1. Unescaped regex interpolation in 2. Double file reads per candidate layout (minor, inline comment posted) 3. Unbounded loop in No Issues Found
Overall: solid PR, the three items above are all minor and none are blockers. |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
react_on_rails/spec/react_on_rails/generators/rsc_generator_spec.rb (1)
129-253: Optional: extract shared Pro-installed setup to reduce repetition.These contexts repeat near-identical bootstrap steps; a helper/factory setup would make future scenario additions less error-prone.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@react_on_rails/spec/react_on_rails/generators/rsc_generator_spec.rb` around lines 129 - 253, Extract the repeated Pro-installed setup into a helper/shared_context (e.g., define a method simulate_pro_installed_setup or RSpec.shared_context "pro_installed" that accepts params like controller_name and layout_helper) and replace the duplicated before(:all) blocks with calls to that helper; the helper should call simulate_existing_rails_files, simulate_npm_files, simulate_existing_file (for config/initializers/react_on_rails_pro.rb and Procfile.dev), simulate_pro_webpack_files, and then the variable pieces like simulate_hello_world_controller and either simulate_compatible_auto_registration_layout or simulate_incompatible_pack_named_layout before running run_generator(["--force"]). This keeps each spec focused on only the differing bits (controller/layout name and compatibility helper) and avoids repeating the bootstrap steps.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@react_on_rails/lib/generators/react_on_rails/rsc_setup.rb`:
- Around line 505-507: The method extract_declared_layout_name currently treats
symbol forms (layout :foo) as concrete layout names; change its regex so it only
matches quoted string literals (double or single quoted) and does not capture
the :symbol form—update extract_declared_layout_name to return a layout name
only when controller_content contains layout "name" or layout 'name' (and return
nil for layout :symbol), ensuring callers like layout_destination_path() will
not build file paths for method-based selectors.
---
Nitpick comments:
In `@react_on_rails/spec/react_on_rails/generators/rsc_generator_spec.rb`:
- Around line 129-253: Extract the repeated Pro-installed setup into a
helper/shared_context (e.g., define a method simulate_pro_installed_setup or
RSpec.shared_context "pro_installed" that accepts params like controller_name
and layout_helper) and replace the duplicated before(:all) blocks with calls to
that helper; the helper should call simulate_existing_rails_files,
simulate_npm_files, simulate_existing_file (for
config/initializers/react_on_rails_pro.rb and Procfile.dev),
simulate_pro_webpack_files, and then the variable pieces like
simulate_hello_world_controller and either
simulate_compatible_auto_registration_layout or
simulate_incompatible_pack_named_layout before running
run_generator(["--force"]). This keeps each spec focused on only the differing
bits (controller/layout name and compatibility helper) and avoids repeating the
bootstrap steps.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 578ed311-32dd-4b0f-99da-086bc5509ffc
📒 Files selected for processing (10)
CHANGELOG.mdreact_on_rails/lib/generators/react_on_rails/base_generator.rbreact_on_rails/lib/generators/react_on_rails/rsc_setup.rbreact_on_rails/lib/generators/react_on_rails/templates/base/base/app/controllers/hello_world_controller.rbreact_on_rails/lib/generators/react_on_rails/templates/base/base/app/views/layouts/react_on_rails_default.html.erbreact_on_rails/lib/generators/react_on_rails/templates/rsc/base/app/controllers/hello_server_controller.rb.ttreact_on_rails/spec/react_on_rails/generators/rsc_generator_spec.rbreact_on_rails/spec/react_on_rails/support/generator_spec_helper.rbreact_on_rails/spec/react_on_rails/support/shared_examples/base_generator_examples.rbreact_on_rails/spec/react_on_rails/support/shared_examples/rsc_generator_examples.rb
🚧 Files skipped from review as they are similar to previous changes (2)
- CHANGELOG.md
- react_on_rails/lib/generators/react_on_rails/templates/base/base/app/controllers/hello_world_controller.rb
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@react_on_rails/lib/generators/react_on_rails/rsc_setup.rb`:
- Around line 501-503: candidate_layout_names should include any existing layout
files named like react_on_rails_rsc* so the generator reuses them instead of
creating new names; update the candidate_layout_names method to, in addition to
hello_world_controller_layout_name, DEFAULT_LAYOUT_NAME and LEGACY_LAYOUT_NAME,
scan the layouts directory (e.g. Rails.root.join("app","views","layouts") or
using Dir.glob) for files whose base name matches /^react_on_rails_rsc/
(including react_on_rails_rsc and react_on_rails_rsc_2), add those basenames
(without extensions) into the array, then compact.uniq the result so existing
react_on_rails_rsc* layouts are folded into the candidates.
- Around line 512-514: The method extract_declared_layout_name only matches
macro-style layout "name" and misses parenthesized calls; update the regex in
extract_declared_layout_name to allow optional whitespace and optional
parentheses around the string argument (i.e. accept both layout "name" and
layout("name") and layout ( "name" ) ), preserving the existing capture handling
(match&.captures&.compact&.first) so the first quoted capture is returned;
ensure the pattern still asserts a following comma or end-of-line as before.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 9ead9dbe-6947-4f52-9538-eae1a246c0c7
📒 Files selected for processing (1)
react_on_rails/lib/generators/react_on_rails/rsc_setup.rb
ReviewThe overall approach is clean and well-reasoned. Renaming the layout is the right call — the old name was semantically misleading, especially in RSC-only installs. The compatibility-detection logic (checking for nameless pack tags rather than keying off filenames) is a solid design choice that handles upgrades gracefully. Test coverage for the four layout-detection scenarios (compatible legacy, compatible custom, incompatible legacy fallback, incompatible default fallback) is thorough and well-structured. Issues foundFunctional / correctness
Code quality
Missing test
|
Review: chore: rename generated layout hello_world → react_on_rails_defaultOverall this is a well-thought-out change. The semantic motivation (the layout has nothing to do with HelloWorld) is sound, the backward-compatible upgrade path is carefully designed, and the test coverage is thorough. A few issues worth addressing: Bugs / correctness1. Trailing comments break layout-name extraction
2. Non-deterministic RSC layout selection
3. The inner alternation uses Minor / style4. When 5. No test for the trailing-comment layout scenario Given the regex gap noted above, a test case where |
|
PR Review - Overall this is a well-structured backward-compatible change with thorough test coverage. A few issues worth addressing. (1) Bug: RSC_GENERATED_LAYOUT_NAME_PATTERN misses suffixes 10-19 - see inline comment on line 28. The regex [2-9]\d* excludes _10-_19 because those start with 1. Since next_available_hello_server_layout_name iterates 2..99, it can mint react_on_rails_rsc_10 through react_on_rails_rsc_19, but those are invisible to existing_rsc_layout_names on the next run. Fix: use ([2-9]|[1-9]\d+) instead. (2) Minor: strip_wrapping_parentheses does not verify balanced parens - see inline on line 648. (3) Minor: pack_tag_arguments_without_names? regex scope undocumented for edge cases like **options, debug: true - see inline on line 645. Nits: extract_declared_layout_name uses ^ anchor worth documenting; before(:all) blocks very repetitive. What is good: semantic layout detection rather than filename matching, well-reasoned priority order, comprehensive edge-case spec coverage including symbol selectors, percent signs in keyword args, user-owned rsc_auth prefix, and not overwriting user-owned files. |
Review SummaryThe layout rename from Strengths:
Issues flagged inline:
|
Summary
hello_world.html.erbtoreact_on_rails_default.html.erbreact_on_rails_defaultlayout where appropriaterails g react_on_rails:rscupgrades layout-aware instead of keying only off the legacy filenameHelloServerControllerwhen possible, without renaming or overwriting app-owned filesreact_on_rails_rsc_*layouts while still reusing generator-owned fallback layoutsThe renamed layout is infrastructure for React on Rails/Shakapacker pack tags; it is not tied to the HelloWorld demo. In RSC-only installs, no HelloWorld controller is generated at all, which made the old name especially misleading.
Behavior
Fresh installs
Fresh installs now generate:
app/views/layouts/react_on_rails_default.html.erbHelloWorldControllerwithlayout "react_on_rails_default"HelloServerControllerwithlayout "react_on_rails_default"in fresh RSC installsStandalone
rails g react_on_rails:rscupgradesExisting apps are handled compatibly:
HelloWorldControllerdeclares a reusable string layout,HelloServerControllerreuses it.react_on_rails_default,hello_world, or an existing generatedreact_on_rails_rsc[_n]fallback).stylesheet_pack_tagandjavascript_pack_tag.HelloServerController, without renaming or overwriting existing app layouts.This keeps fresh installs on the clearer canonical name while preserving legacy and custom app layouts during standalone RSC upgrades.
Notes
dummy-for-generators/andgen-examples/are gitignored (generated at test/rake time), so they automatically pick up the new generator behavior.Test Plan
bundle exec rubocoppasses on changed Ruby/spec filesmaster, then runrails g react_on_rails:pro --forceandrails g react_on_rails:rsc --force;HelloServerControllercorrectly reuseslayout "hello_world"--rscapp and confirmHelloServerControlleruseslayout "react_on_rails_default"and the layout file exists