Skip to content

Commit 9a1209e

Browse files
Add prepare_incremental_render_path for incremental rendering
Extract common path generation logic into build_render_path and add support for incremental rendering endpoint paths. Changes: - Add prepare_incremental_render_path method for generating /bundles/{hash}/incremental-render/{digest} paths - Extract shared logic to private build_render_path method - Supports both server and RSC bundle selection - Add minimal tests covering path format and bundle selection 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent db48f68 commit 9a1209e

File tree

2 files changed

+62
-4
lines changed

2 files changed

+62
-4
lines changed

react_on_rails_pro/lib/react_on_rails_pro/server_rendering_pool/node_rendering_pool.rb

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,27 @@ def rsc_bundle_hash
9696
end
9797

9898
def prepare_render_path(js_code, render_options)
99+
# TODO: Remove the request_digest. See https://github.com/shakacode/react_on_rails_pro/issues/119
100+
# From the request path
101+
# path = "/bundles/#{@bundle_hash}/render"
102+
build_render_path(js_code, render_options, "render")
103+
end
104+
105+
def prepare_incremental_render_path(js_code, render_options)
106+
build_render_path(js_code, render_options, "incremental-render")
107+
end
108+
109+
private
110+
111+
def build_render_path(js_code, render_options, endpoint)
99112
ReactOnRailsPro::ServerRenderingPool::ProRendering
100113
.set_request_digest_on_render_options(js_code, render_options)
101114

102115
rsc_support_enabled = ReactOnRailsPro.configuration.enable_rsc_support
103116
is_rendering_rsc_payload = rsc_support_enabled && render_options.rsc_payload_streaming?
104117
bundle_hash = is_rendering_rsc_payload ? rsc_bundle_hash : server_bundle_hash
105-
# TODO: Remove the request_digest. See https://github.com/shakacode/react_on_rails_pro/issues/119
106-
# From the request path
107-
# path = "/bundles/#{@bundle_hash}/render"
108-
"/bundles/#{bundle_hash}/render/#{render_options.request_digest}"
118+
119+
"/bundles/#{bundle_hash}/#{endpoint}/#{render_options.request_digest}"
109120
end
110121

111122
def fallback_exec_js(js_code, render_options, error)
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# frozen_string_literal: true
2+
3+
require_relative "../spec_helper"
4+
5+
module ReactOnRailsPro
6+
module ServerRenderingPool
7+
RSpec.describe NodeRenderingPool do
8+
let(:js_code) { "console.log('test');" }
9+
let(:render_options) do
10+
instance_double(
11+
ReactOnRails::ReactComponent::RenderOptions,
12+
request_digest: "abc123",
13+
rsc_payload_streaming?: false
14+
)
15+
end
16+
17+
before do
18+
allow(ReactOnRailsPro::ServerRenderingPool::ProRendering)
19+
.to receive(:set_request_digest_on_render_options)
20+
allow(ReactOnRailsPro.configuration).to receive(:enable_rsc_support).and_return(false)
21+
allow(described_class).to receive(:server_bundle_hash).and_return("server123")
22+
allow(described_class).to receive(:rsc_bundle_hash).and_return("rsc456")
23+
end
24+
25+
describe ".prepare_incremental_render_path" do
26+
it "returns path with incremental-render endpoint" do
27+
path = described_class.prepare_incremental_render_path(js_code, render_options)
28+
29+
expect(path).to eq("/bundles/server123/incremental-render/abc123")
30+
end
31+
32+
context "when RSC support is enabled and rendering RSC payload" do
33+
before do
34+
allow(ReactOnRailsPro.configuration).to receive(:enable_rsc_support).and_return(true)
35+
allow(render_options).to receive(:rsc_payload_streaming?).and_return(true)
36+
end
37+
38+
it "uses RSC bundle hash instead of server bundle hash" do
39+
path = described_class.prepare_incremental_render_path(js_code, render_options)
40+
41+
expect(path).to eq("/bundles/rsc456/incremental-render/abc123")
42+
end
43+
end
44+
end
45+
end
46+
end
47+
end

0 commit comments

Comments
 (0)