Skip to content

Commit 4a36576

Browse files
linting
1 parent fd24a52 commit 4a36576

File tree

4 files changed

+25
-22
lines changed

4 files changed

+25
-22
lines changed

lib/react_on_rails/helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ def should_raise_streaming_prerender_error?(chunk_json_result, render_options)
611611
end
612612

613613
# Returns object with values that are NOT html_safe!
614-
def server_rendered_react_component(render_options)
614+
def server_rendered_react_component(render_options) # rubocop:disable Metrics/CyclomaticComplexity
615615
return { "html" => "", "consoleReplayScript" => "" } unless render_options.prerender
616616

617617
react_component_name = render_options.react_component_name

lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def reset_pool_if_server_bundle_was_modified
4646
# Note, js_code does not have to be based on React.
4747
# js_code MUST RETURN json stringify Object
4848
# Calling code will probably call 'html_safe' on return value before rendering to the view.
49-
# rubocop:disable Metrics/CyclomaticComplexity
49+
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
5050
def exec_server_render_js(js_code, render_options, js_evaluator = nil)
5151
js_evaluator ||= self
5252
if render_options.trace
@@ -76,13 +76,16 @@ def exec_server_render_js(js_code, render_options, js_evaluator = nil)
7676
raise ReactOnRails::Error, msg, err.backtrace
7777
end
7878

79-
return parse_result_and_replay_console_messages(result, render_options) unless render_options.stream? || render_options.rsc?
79+
unless render_options.stream? || render_options.rsc?
80+
return parse_result_and_replay_console_messages(result,
81+
render_options)
82+
end
8083

8184
# Streamed component is returned as stream of strings.
8285
# We need to parse each chunk and replay the console messages.
8386
result.transform { |chunk| parse_result_and_replay_console_messages(chunk, render_options) }
8487
end
85-
# rubocop:enable Metrics/CyclomaticComplexity
88+
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
8689

8790
def trace_js_code_used(msg, js_code, file_name = "tmp/server-generated.js", force: false)
8891
return unless ReactOnRails.configuration.trace || force
@@ -227,11 +230,12 @@ def file_url_to_string(url)
227230
end
228231

229232
def parse_result_and_replay_console_messages(result_string, render_options)
233+
return { html: result_string } if render_options.rsc?
234+
230235
result = nil
231236
begin
232237
result = JSON.parse(result_string)
233238
rescue JSON::ParserError => e
234-
return { html: result_string }
235239
raise ReactOnRails::JsonParseError.new(parse_error: e, json: result_string)
236240
end
237241

script/convert

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ new_config = File.expand_path("../spec/dummy/config/webpacker.yml", __dir__)
1414
File.rename(old_config, new_config)
1515

1616
gsub_file_content("../Gemfile.development_dependencies", 'gem "shakapacker", "8.0.0"', 'gem "shakapacker", "6.6.0"')
17-
gsub_file_content("../Gemfile.development_dependencies", 'gem "webpacker", "6.0.0.rc.6"', '')
17+
gsub_file_content("../Gemfile.development_dependencies", 'gem "webpacker", "6.0.0.rc.6"', "")
1818

1919
gsub_file_content("../spec/dummy/package.json", '"shakapacker": "8.0.0",', '"shakapacker": "6.6.0",')
2020

spec/react_on_rails/utils_spec.rb

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ module ReactOnRails
1010
# If rspec tests are run locally, we want to test both packers.
1111
# If rspec tests are run in CI, we want to test the packer specified in the CI_PACKER_VERSION environment variable.
1212
# Check script/convert and .github/workflows/rspec-package-specs.yml for more details.
13-
PACKERS_TO_TEST = if ENV["CI_PACKER_VERSION"] == "old"
13+
packers_to_test = if ENV["CI_PACKER_VERSION"] == "old"
1414
["webpacker"]
1515
elsif ENV["CI_PACKER_VERSION"] == "new"
1616
["shakapacker"]
1717
else
18-
["shakapacker", "webpacker"]
18+
%w[shakapacker webpacker]
1919
end
2020

2121
shared_context "with packer enabled" do
@@ -36,8 +36,8 @@ module ReactOnRails
3636
shared_context "with shakapacker enabled" do
3737
before do
3838
# Mock that shakapacker is not installed, so webpacker will be used instead
39-
allow(ReactOnRails::Utils).to receive(:gem_available?).with("shakapacker").and_return(true)
40-
allow(ReactOnRails::Utils).to receive(:gem_available?).with("webpacker").and_return(false)
39+
allow(described_class).to receive(:gem_available?).with("shakapacker").and_return(true)
40+
allow(described_class).to receive(:gem_available?).with("webpacker").and_return(false)
4141
end
4242

4343
include_context "with packer enabled"
@@ -54,8 +54,8 @@ module ReactOnRails
5454
shared_context "with webpacker enabled" do
5555
before do
5656
# Mock that shakapacker is not installed, so webpacker will be used instead
57-
allow(ReactOnRails::Utils).to receive(:gem_available?).with("shakapacker").and_return(false)
58-
allow(ReactOnRails::Utils).to receive(:gem_available?).with("webpacker").and_return(true)
57+
allow(described_class).to receive(:gem_available?).with("shakapacker").and_return(false)
58+
allow(described_class).to receive(:gem_available?).with("webpacker").and_return(true)
5959
end
6060

6161
include_context "with packer enabled"
@@ -72,8 +72,8 @@ module ReactOnRails
7272
before do
7373
allow(ReactOnRails).to receive_message_chain(:configuration, :generated_assets_dir)
7474
.and_return("public/webpack/dev")
75-
allow(ReactOnRails::Utils).to receive(:gem_available?).with("shakapacker").and_return(false)
76-
allow(ReactOnRails::Utils).to receive(:gem_available?).with("webpacker").and_return(false)
75+
allow(described_class).to receive(:gem_available?).with("shakapacker").and_return(false)
76+
allow(described_class).to receive(:gem_available?).with("webpacker").and_return(false)
7777
end
7878

7979
it "does not use packer" do
@@ -128,25 +128,22 @@ def mock_dev_server_running
128128
allow(Rails).to receive(:root).and_return(File.expand_path("."))
129129
described_class.instance_variable_set(:@server_bundle_path, nil)
130130
described_class.instance_variable_set(:@rsc_bundle_path, nil)
131+
ReactOnRails::PackerUtils.instance_variables.each do |instance_variable|
132+
ReactOnRails::PackerUtils.remove_instance_variable(instance_variable)
133+
end
131134
end
132135

133136
after do
134137
described_class.instance_variable_set(:@server_bundle_path, nil)
135138
described_class.instance_variable_set(:@rsc_bundle_path, nil)
136139
end
137140

138-
before :each do
139-
ReactOnRails::PackerUtils.instance_variables.each do |instance_variable|
140-
ReactOnRails::PackerUtils.remove_instance_variable(instance_variable)
141-
end
142-
end
143-
144141
describe ".bundle_js_file_path" do
145142
subject do
146143
described_class.bundle_js_file_path("webpack-bundle.js")
147144
end
148145

149-
PACKERS_TO_TEST.each do |packer_type|
146+
packers_to_test.each do |packer_type|
150147
context "with #{packer_type} enabled", packer_type.to_sym do
151148
include_context "with #{packer_type} enabled"
152149

@@ -210,9 +207,10 @@ def mock_dev_server_running
210207
end
211208
end
212209

213-
PACKERS_TO_TEST.each do |packer_type|
210+
packers_to_test.each do |packer_type|
214211
describe ".server_bundle_js_file_path with #{packer_type} enabled" do
215212
let(:packer_public_output_path) { Pathname.new("public/webpack/development") }
213+
216214
include_context "with #{packer_type} enabled"
217215

218216
context "with server file not in manifest", packer_type.to_sym do
@@ -275,6 +273,7 @@ def mock_dev_server_running
275273

276274
describe ".rsc_bundle_js_file_path with #{packer_type} enabled" do
277275
let(:packer_public_output_path) { Pathname.new("public/webpack/development") }
276+
278277
include_context "with #{packer_type} enabled"
279278

280279
context "with server file not in manifest", packer_type.to_sym do

0 commit comments

Comments
 (0)