Skip to content

Commit 54bb39b

Browse files
ihabadhamclaude
andcommitted
Fix DEFAULT_ROUTE for --rsc installs using gsub_file instead of .tt template
The previous approach renamed bin/dev to bin/dev.tt to make DEFAULT_ROUTE dynamic via ERB. This broke the dummy app (which exec's bin/dev directly) and the dev_spec.rb tests (which read/load the file from source). Instead, keep bin/dev as a plain Ruby file and use gsub_file after copying to change DEFAULT_ROUTE from "hello_world" to "hello_server" when --rsc is used without --redux (the only case where hello_world doesn't exist). Co-Authored-By: Claude Opus 4.6 <[email protected]>
1 parent 9f3bf0a commit 54bb39b

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

react_on_rails/lib/generators/react_on_rails/install_generator.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,11 @@ def add_bin_scripts
225225
template_bin_path = "#{__dir__}/templates/base/base/bin"
226226
directory template_bin_path, "bin"
227227

228+
# For --rsc without --redux, hello_world doesn't exist — update DEFAULT_ROUTE
229+
if use_rsc? && !options.redux?
230+
gsub_file "bin/dev", 'DEFAULT_ROUTE = "hello_world"', 'DEFAULT_ROUTE = "hello_server"'
231+
end
232+
228233
# Make these and only these files executable
229234
files_to_copy = []
230235
Dir.chdir(template_bin_path) do

react_on_rails/spec/react_on_rails/generators/install_generator_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313
include_examples "base_generator", application_js: true
1414
include_examples "no_redux_generator"
1515

16+
it "sets DEFAULT_ROUTE to hello_world in bin/dev" do
17+
assert_file "bin/dev" do |content|
18+
expect(content).to include('DEFAULT_ROUTE = "hello_world"')
19+
end
20+
end
21+
1622
it "installs appropriate transpiler dependencies based on Shakapacker version" do
1723
assert_file "package.json" do |content|
1824
package_json = JSON.parse(content)
@@ -743,6 +749,12 @@
743749
expect(content).to include("rsc_payload")
744750
end
745751
end
752+
753+
it "sets DEFAULT_ROUTE to hello_server in bin/dev" do
754+
assert_file "bin/dev" do |content|
755+
expect(content).to include('DEFAULT_ROUTE = "hello_server"')
756+
end
757+
end
746758
end
747759

748760
context "with --rsc --redux" do

0 commit comments

Comments
 (0)