From d9759120670b677e1b111c5b8cf52f367249c2a1 Mon Sep 17 00:00:00 2001 From: Abanoub Ghadban Date: Tue, 5 Nov 2024 20:02:53 +0200 Subject: [PATCH] tmp --- Gemfile.lock | 2 +- .../server_rendering_pool/ruby_embedded_java_script.rb | 5 +++-- node_package/src/ReactOnRailsRSC.ts | 5 +++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 5774853c3..054ab5a71 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - react_on_rails (14.0.5) + react_on_rails (15.0.0.alpha.1) addressable connection_pool execjs (~> 2.5) diff --git a/lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb b/lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb index 169c81d7d..c44866b89 100644 --- a/lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb +++ b/lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb @@ -56,7 +56,7 @@ def exec_server_render_js(js_code, render_options, js_evaluator = nil) @file_index += 1 end begin - result = if render_options.stream? + result = if render_options.stream? || render_options.rsc? js_evaluator.eval_streaming_js(js_code, render_options) else js_evaluator.eval_js(js_code, render_options) @@ -76,7 +76,7 @@ def exec_server_render_js(js_code, render_options, js_evaluator = nil) raise ReactOnRails::Error, msg, err.backtrace end - return parse_result_and_replay_console_messages(result, render_options) unless render_options.stream? + return parse_result_and_replay_console_messages(result, render_options) unless render_options.stream? || render_options.rsc? # Streamed component is returned as stream of strings. # We need to parse each chunk and replay the console messages. @@ -231,6 +231,7 @@ def parse_result_and_replay_console_messages(result_string, render_options) begin result = JSON.parse(result_string) rescue JSON::ParserError => e + return { html: result_string } raise ReactOnRails::JsonParseError.new(parse_error: e, json: result_string) end diff --git a/node_package/src/ReactOnRailsRSC.ts b/node_package/src/ReactOnRailsRSC.ts index cd265b566..7a44ed798 100644 --- a/node_package/src/ReactOnRailsRSC.ts +++ b/node_package/src/ReactOnRailsRSC.ts @@ -62,14 +62,19 @@ See https://github.com/shakacode/react_on_rails#renderer-functions`); } renderResult = new PassThrough(); + let finalValue = ""; const streamReader = renderToReadableStream(reactRenderingResult, getBundleConfig()).getReader(); + const decoder = new TextDecoder(); const processStream = async () => { const { done, value } = await streamReader.read(); if (done) { renderResult?.push(null); + // @ts-expect-error value is not typed + debugConsole.log('value', finalValue); return; } + finalValue += decoder.decode(value); renderResult?.push(value); processStream(); }