Skip to content

Commit f7d5c67

Browse files
Wire up incremental rendering in NodeRenderingPool
- Modify eval_streaming_js to detect async_props_block in render_options - Route to incremental rendering path when async_props_block is present - Fall back to standard streaming when async_props_block is absent - Add tests for both execution paths 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent dd30ef4 commit f7d5c67

File tree

2 files changed

+74
-6
lines changed

2 files changed

+74
-6
lines changed

react_on_rails_pro/lib/react_on_rails_pro/server_rendering_pool/node_rendering_pool.rb

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,27 @@ def exec_server_render_js(js_code, render_options)
5353
end
5454

5555
def eval_streaming_js(js_code, render_options)
56-
path = prepare_render_path(js_code, render_options)
57-
ReactOnRailsPro::Request.render_code_as_stream(
58-
path,
59-
js_code,
60-
is_rsc_payload: ReactOnRailsPro.configuration.enable_rsc_support && render_options.rsc_payload_streaming?
61-
)
56+
is_rsc_payload = ReactOnRailsPro.configuration.enable_rsc_support && render_options.rsc_payload_streaming?
57+
async_props_block = render_options.internal_option(:async_props_block)
58+
59+
if async_props_block
60+
# Use incremental rendering when async props block is provided
61+
path = prepare_incremental_render_path(js_code, render_options)
62+
ReactOnRailsPro::Request.render_code_with_incremental_updates(
63+
path,
64+
js_code,
65+
async_props_block: async_props_block,
66+
is_rsc_payload: is_rsc_payload
67+
)
68+
else
69+
# Use standard streaming when no async props block
70+
path = prepare_render_path(js_code, render_options)
71+
ReactOnRailsPro::Request.render_code_as_stream(
72+
path,
73+
js_code,
74+
is_rsc_payload: is_rsc_payload
75+
)
76+
end
6277
end
6378

6479
def eval_js(js_code, render_options, send_bundle: false)

react_on_rails_pro/spec/react_on_rails_pro/server_rendering_pool/node_rendering_pool_spec.rb

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,59 @@ module ServerRenderingPool
4242
end
4343
end
4444
end
45+
46+
describe ".eval_streaming_js" do
47+
context "when async_props_block is present in render_options" do
48+
let(:async_props_block) { proc { { data: "async_data" } } }
49+
let(:render_options) do
50+
instance_double(
51+
ReactOnRails::ReactComponent::RenderOptions,
52+
rsc_payload_streaming?: false,
53+
internal_option: async_props_block
54+
)
55+
end
56+
57+
it "calls prepare_incremental_render_path and render_code_with_incremental_updates" do
58+
expected_path = "/bundles/server123/incremental-render/abc123"
59+
allow(described_class).to receive(:prepare_incremental_render_path)
60+
.with(js_code, render_options)
61+
.and_return(expected_path)
62+
allow(ReactOnRailsPro::Request).to receive(:render_code_with_incremental_updates)
63+
64+
described_class.eval_streaming_js(js_code, render_options)
65+
66+
expect(described_class).to have_received(:prepare_incremental_render_path)
67+
.with(js_code, render_options)
68+
expect(ReactOnRailsPro::Request).to have_received(:render_code_with_incremental_updates)
69+
.with(expected_path, js_code, async_props_block: async_props_block, is_rsc_payload: false)
70+
end
71+
end
72+
73+
context "when async_props_block is NOT present" do
74+
let(:render_options) do
75+
instance_double(
76+
ReactOnRails::ReactComponent::RenderOptions,
77+
rsc_payload_streaming?: false,
78+
internal_option: nil
79+
)
80+
end
81+
82+
it "calls prepare_render_path and render_code_as_stream" do
83+
expected_path = "/bundles/server123/render/abc123"
84+
allow(described_class).to receive(:prepare_render_path)
85+
.with(js_code, render_options)
86+
.and_return(expected_path)
87+
allow(ReactOnRailsPro::Request).to receive(:render_code_as_stream)
88+
89+
described_class.eval_streaming_js(js_code, render_options)
90+
91+
expect(described_class).to have_received(:prepare_render_path)
92+
.with(js_code, render_options)
93+
expect(ReactOnRailsPro::Request).to have_received(:render_code_as_stream)
94+
.with(expected_path, js_code, is_rsc_payload: false)
95+
end
96+
end
97+
end
4598
end
4699
end
47100
end

0 commit comments

Comments
 (0)