Skip to content

Commit

Permalink
add some comments and remove unneeded calls
Browse files Browse the repository at this point in the history
  • Loading branch information
AbanoubGhadban committed Oct 20, 2024
1 parent 6ad16f1 commit ccdecd7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
24 changes: 12 additions & 12 deletions lib/react_on_rails/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -431,29 +431,28 @@ def build_react_component_result_for_server_rendered_string(
end

def build_react_component_result_for_server_streamed_content(
rendered_html_stream: required("rendered_html_stream"),
component_specification_tag: required("component_specification_tag"),
render_options: required("render_options")
rendered_html_stream:,
component_specification_tag:,
render_options:
)
is_first_chunk = true
rendered_html_stream.transform do |chunk_json_result|
if is_first_chunk
is_first_chunk = false
next build_react_component_result_for_server_rendered_string(
build_react_component_result_for_server_rendered_string(
server_rendered_html: chunk_json_result["html"],
component_specification_tag: component_specification_tag,
console_script: chunk_json_result["consoleReplayScript"],
render_options: render_options
)
else
result_console_script = render_options.replay_console ? chunk_json_result["consoleReplayScript"] : ""
# No need to prepend component_specification_tag or add rails context again
# as they're already included in the first chunk
compose_react_component_html_with_spec_and_console(
"", chunk_json_result["html"], result_console_script
)
end

result_console_script = render_options.replay_console ? chunk_json_result["consoleReplayScript"] : ""
# No need to prepend component_specification_tag or add rails context again
# as they're already included in the first chunk
compose_react_component_html_with_spec_and_console(
"", chunk_json_result["html"], result_console_script
)
end
end

def build_react_component_result_for_server_rendered_hash(
Expand Down Expand Up @@ -688,3 +687,4 @@ def raise_missing_autoloaded_bundle(react_component_name)
end
# rubocop:enable Metrics/ModuleLength
# rubocop:enable Metrics/MethodLength

Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,13 @@ def parse_result_and_replay_console_messages(result_string, render_options)
if render_options.logging_on_server
console_script = result["consoleReplayScript"]
console_script_lines = console_script.split("\n")
# Skip the first two lines (new line and opening <script> tag) and the last line (closing </script> tag)
console_script_lines = console_script_lines[2..-2]
# Regular expression to match console.log or console.error calls with SERVER prefix
re = /console\.(?:log|error)\.apply\(console, \["\[SERVER\] (?<msg>.*)"\]\);/
console_script_lines&.each do |line|
match = re.match(line)
# Log matched messages to Rails logger with react_on_rails prefix
Rails.logger.info { "[react_on_rails] #{match[:msg]}" } if match
end
end
Expand Down

0 comments on commit ccdecd7

Please sign in to comment.