Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
AbanoubGhadban committed Nov 5, 2024
1 parent b10f604 commit d437954
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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.
Expand Down Expand Up @@ -230,7 +230,9 @@ def parse_result_and_replay_console_messages(result_string, render_options)
result = nil
begin
result = JSON.parse(result_string)
binding.pry
rescue JSON::ParserError => e
return { html: result_string }
raise ReactOnRails::JsonParseError.new(parse_error: e, json: result_string)
end

Expand Down
5 changes: 5 additions & 0 deletions node_package/src/ReactOnRailsRSC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit d437954

Please sign in to comment.