Skip to content

Commit ccdecd7

Browse files
add some comments and remove unneeded calls
1 parent 6ad16f1 commit ccdecd7

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

lib/react_on_rails/helper.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -431,29 +431,28 @@ def build_react_component_result_for_server_rendered_string(
431431
end
432432

433433
def build_react_component_result_for_server_streamed_content(
434-
rendered_html_stream: required("rendered_html_stream"),
435-
component_specification_tag: required("component_specification_tag"),
436-
render_options: required("render_options")
434+
rendered_html_stream:,
435+
component_specification_tag:,
436+
render_options:
437437
)
438438
is_first_chunk = true
439439
rendered_html_stream.transform do |chunk_json_result|
440440
if is_first_chunk
441441
is_first_chunk = false
442-
next build_react_component_result_for_server_rendered_string(
442+
build_react_component_result_for_server_rendered_string(
443443
server_rendered_html: chunk_json_result["html"],
444444
component_specification_tag: component_specification_tag,
445445
console_script: chunk_json_result["consoleReplayScript"],
446446
render_options: render_options
447447
)
448+
else
449+
result_console_script = render_options.replay_console ? chunk_json_result["consoleReplayScript"] : ""
450+
# No need to prepend component_specification_tag or add rails context again
451+
# as they're already included in the first chunk
452+
compose_react_component_html_with_spec_and_console(
453+
"", chunk_json_result["html"], result_console_script
454+
)
448455
end
449-
450-
result_console_script = render_options.replay_console ? chunk_json_result["consoleReplayScript"] : ""
451-
# No need to prepend component_specification_tag or add rails context again
452-
# as they're already included in the first chunk
453-
compose_react_component_html_with_spec_and_console(
454-
"", chunk_json_result["html"], result_console_script
455-
)
456-
end
457456
end
458457

459458
def build_react_component_result_for_server_rendered_hash(
@@ -688,3 +687,4 @@ def raise_missing_autoloaded_bundle(react_component_name)
688687
end
689688
# rubocop:enable Metrics/ModuleLength
690689
# rubocop:enable Metrics/MethodLength
690+

lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,13 @@ def parse_result_and_replay_console_messages(result_string, render_options)
237237
if render_options.logging_on_server
238238
console_script = result["consoleReplayScript"]
239239
console_script_lines = console_script.split("\n")
240+
# Skip the first two lines (new line and opening <script> tag) and the last line (closing </script> tag)
240241
console_script_lines = console_script_lines[2..-2]
242+
# Regular expression to match console.log or console.error calls with SERVER prefix
241243
re = /console\.(?:log|error)\.apply\(console, \["\[SERVER\] (?<msg>.*)"\]\);/
242244
console_script_lines&.each do |line|
243245
match = re.match(line)
246+
# Log matched messages to Rails logger with react_on_rails prefix
244247
Rails.logger.info { "[react_on_rails] #{match[:msg]}" } if match
245248
end
246249
end

0 commit comments

Comments
 (0)