Skip to content

Commit e346593

Browse files
Phase 3: Move RSC utility methods to Pro gem
- Remove RSC utility methods from ReactOnRails::Utils: - rsc_bundle_js_file_path - react_client_manifest_file_path - react_server_client_manifest_file_path - Add these methods to ReactOnRailsPro::Utils with same functionality - Update rsc_support_enabled? in open-source to delegate to Pro gem - Update all internal Pro gem references to use ReactOnRailsPro::Utils: - react_on_rails_pro/lib/react_on_rails_pro/request.rb - react_on_rails_pro/lib/react_on_rails_pro/utils.rb - Update webpack_assets_status_checker.rb to call ReactOnRailsPro::Utils - Remove RSC utility tests from open-source spec (lines 452-839) - Removed rsc_bundle_js_file_path tests - Removed react_client_manifest_file_path tests - Removed react_server_client_manifest_file_path tests - Update Pro gem test mocks to reference ReactOnRailsPro::Utils: - react_on_rails_pro/spec/react_on_rails_pro/utils_spec.rb - react_on_rails_pro/spec/react_on_rails_pro/request_spec.rb Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent bb35666 commit e346593

File tree

7 files changed

+64
-252
lines changed

7 files changed

+64
-252
lines changed

lib/react_on_rails/test_helper/webpack_assets_status_checker.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ def all_compiled_assets
5454
if ReactOnRails::Utils.react_on_rails_pro?
5555
pro_config = ReactOnRailsPro.configuration
5656
if bundle_name == pro_config.react_client_manifest_file
57-
ReactOnRails::Utils.react_client_manifest_file_path
57+
ReactOnRailsPro::Utils.react_client_manifest_file_path
5858
elsif bundle_name == pro_config.react_server_client_manifest_file
59-
ReactOnRails::Utils.react_server_client_manifest_file_path
59+
ReactOnRailsPro::Utils.react_server_client_manifest_file_path
6060
else
6161
ReactOnRails::Utils.bundle_js_file_path(bundle_name)
6262
end

lib/react_on_rails/utils.rb

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -153,34 +153,6 @@ def self.server_bundle_js_file_path
153153
@server_bundle_path = bundle_js_file_path(bundle_name)
154154
end
155155

156-
def self.rsc_bundle_js_file_path
157-
return @rsc_bundle_path if @rsc_bundle_path && !Rails.env.development?
158-
159-
bundle_name = ReactOnRails.configuration.rsc_bundle_js_file
160-
@rsc_bundle_path = bundle_js_file_path(bundle_name)
161-
end
162-
163-
def self.react_client_manifest_file_path
164-
return @react_client_manifest_path if @react_client_manifest_path && !Rails.env.development?
165-
166-
file_name = ReactOnRails.configuration.react_client_manifest_file
167-
@react_client_manifest_path = ReactOnRails::PackerUtils.asset_uri_from_packer(file_name)
168-
end
169-
170-
# React Server Manifest is generated by the server bundle.
171-
# So, it will never be served from the dev server.
172-
def self.react_server_client_manifest_file_path
173-
return @react_server_manifest_path if @react_server_manifest_path && !Rails.env.development?
174-
175-
asset_name = ReactOnRails.configuration.react_server_client_manifest_file
176-
if asset_name.nil?
177-
raise ReactOnRails::Error,
178-
"react_server_client_manifest_file is nil, ensure it is set in your configuration"
179-
end
180-
181-
@react_server_manifest_path = bundle_js_file_path(asset_name)
182-
end
183-
184156
def self.running_on_windows?
185157
(/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
186158
end
@@ -261,13 +233,12 @@ def self.react_on_rails_pro_version
261233
end
262234
end
263235

236+
# RSC support detection has been moved to React on Rails Pro
237+
# See react_on_rails_pro/lib/react_on_rails_pro/utils.rb
264238
def self.rsc_support_enabled?
265239
return false unless react_on_rails_pro?
266240

267-
return @rsc_support_enabled if defined?(@rsc_support_enabled)
268-
269-
rorp_config = ReactOnRailsPro.configuration
270-
@rsc_support_enabled = rorp_config.respond_to?(:enable_rsc_support) && rorp_config.enable_rsc_support
241+
ReactOnRailsPro::Utils.rsc_support_enabled?
271242
end
272243

273244
def self.full_text_errors_enabled?

react_on_rails_pro/lib/react_on_rails_pro/request.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def upload_assets
4949

5050
# Add RSC bundle if enabled
5151
if ReactOnRailsPro.configuration.enable_rsc_support
52-
rsc_bundle_path = ReactOnRails::Utils.rsc_bundle_js_file_path
52+
rsc_bundle_path = ReactOnRailsPro::Utils.rsc_bundle_js_file_path
5353
unless File.exist?(rsc_bundle_path)
5454
raise ReactOnRailsPro::Error, "RSC bundle not found at #{rsc_bundle_path}. " \
5555
"Please build your bundles before uploading assets."
@@ -154,7 +154,7 @@ def populate_form_with_bundle_and_assets(form, check_bundle:)
154154
if ReactOnRailsPro.configuration.enable_rsc_support
155155
add_bundle_to_form(
156156
form,
157-
bundle_path: ReactOnRails::Utils.rsc_bundle_js_file_path,
157+
bundle_path: ReactOnRailsPro::Utils.rsc_bundle_js_file_path,
158158
bundle_file_name: pool.rsc_renderer_bundle_file_name,
159159
bundle_hash: pool.rsc_bundle_hash,
160160
check_bundle: check_bundle
@@ -178,8 +178,8 @@ def add_assets_to_form(form)
178178
assets_to_copy = (ReactOnRailsPro.configuration.assets_to_copy || []).dup
179179
# react_client_manifest and react_server_manifest files are needed to generate react server components payload
180180
if ReactOnRailsPro.configuration.enable_rsc_support
181-
assets_to_copy << ReactOnRails::Utils.react_client_manifest_file_path
182-
assets_to_copy << ReactOnRails::Utils.react_server_client_manifest_file_path
181+
assets_to_copy << ReactOnRailsPro::Utils.react_client_manifest_file_path
182+
assets_to_copy << ReactOnRailsPro::Utils.react_server_client_manifest_file_path
183183
end
184184

185185
return form unless assets_to_copy.present?

react_on_rails_pro/lib/react_on_rails_pro/utils.rb

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,44 @@ def self.rorp_puts(message)
1616
puts "[ReactOnRailsPro] #{message}"
1717
end
1818

19+
# RSC Configuration Utility Methods
20+
# These methods were moved from ReactOnRails::Utils as they are Pro-only features
21+
22+
def self.rsc_bundle_js_file_path
23+
return @rsc_bundle_path if @rsc_bundle_path && !Rails.env.development?
24+
25+
bundle_name = ReactOnRailsPro.configuration.rsc_bundle_js_file
26+
@rsc_bundle_path = ReactOnRails::Utils.bundle_js_file_path(bundle_name)
27+
end
28+
29+
def self.react_client_manifest_file_path
30+
return @react_client_manifest_path if @react_client_manifest_path && !Rails.env.development?
31+
32+
file_name = ReactOnRailsPro.configuration.react_client_manifest_file
33+
@react_client_manifest_path = ReactOnRails::PackerUtils.asset_uri_from_packer(file_name)
34+
end
35+
36+
# React Server Manifest is generated by the server bundle.
37+
# So, it will never be served from the dev server.
38+
def self.react_server_client_manifest_file_path
39+
return @react_server_manifest_path if @react_server_manifest_path && !Rails.env.development?
40+
41+
asset_name = ReactOnRailsPro.configuration.react_server_client_manifest_file
42+
if asset_name.nil?
43+
raise ReactOnRailsPro::Error,
44+
"react_server_client_manifest_file is nil, ensure it is set in your configuration"
45+
end
46+
47+
@react_server_manifest_path = ReactOnRails::Utils.bundle_js_file_path(asset_name)
48+
end
49+
50+
def self.rsc_support_enabled?
51+
return @rsc_support_enabled if defined?(@rsc_support_enabled)
52+
53+
rorp_config = ReactOnRailsPro.configuration
54+
@rsc_support_enabled = rorp_config.respond_to?(:enable_rsc_support) && rorp_config.enable_rsc_support
55+
end
56+
1957
# Validates the license and raises an exception if invalid.
2058
#
2159
# @return [Boolean] true if license is valid
@@ -66,7 +104,7 @@ def self.bundle_hash
66104
def self.rsc_bundle_hash
67105
return @rsc_bundle_hash if @rsc_bundle_hash && !(Rails.env.development? || Rails.env.test?)
68106

69-
server_rsc_bundle_js_file_path = ReactOnRails::Utils.rsc_bundle_js_file_path
107+
server_rsc_bundle_js_file_path = rsc_bundle_js_file_path
70108

71109
return @rsc_bundle_hash if @rsc_bundle_hash && bundle_mtime_same?(server_rsc_bundle_js_file_path)
72110

@@ -114,7 +152,7 @@ def self.bundle_mtime_same?(server_bundle_js_file_path)
114152
def self.contains_hash?(server_bundle_basename)
115153
# TODO: Need to consider if the configuration value has the ".js" on the end.
116154
ReactOnRails.configuration.server_bundle_js_file != server_bundle_basename &&
117-
ReactOnRails.configuration.rsc_bundle_js_file != server_bundle_basename
155+
ReactOnRailsPro.configuration.rsc_bundle_js_file != server_bundle_basename
118156
end
119157

120158
def self.with_trace(message = nil)

react_on_rails_pro/spec/react_on_rails_pro/request_spec.rb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,20 @@
2121
File.write(rsc_server_bundle_path, 'console.log("mock RSC bundle");')
2222

2323
clear_stream_mocks
24-
allow(ReactOnRailsPro.configuration).to receive(:renderer_url).and_return(renderer_url)
25-
allow(ReactOnRailsPro.configuration).to receive(:renderer_http_pool_size).and_return(20)
24+
allow(ReactOnRailsPro.configuration).to receive_messages(renderer_url: renderer_url, renderer_http_pool_size: 20)
2625

2726
original_httpx_plugin = HTTPX.method(:plugin)
2827
allow(HTTPX).to receive(:plugin) do |*args|
2928
original_httpx_plugin.call(:mock_stream).plugin(*args)
3029
end
3130
allow(Rails).to receive(:logger).and_return(logger_mock)
3231

33-
allow(ReactOnRailsPro::ServerRenderingPool::NodeRenderingPool).to receive(:renderer_bundle_file_name)
34-
.and_return(renderer_bundle_file_name)
35-
allow(ReactOnRailsPro::ServerRenderingPool::NodeRenderingPool).to receive(:rsc_renderer_bundle_file_name)
36-
.and_return(rsc_renderer_bundle_file_name)
32+
allow(ReactOnRailsPro::ServerRenderingPool::NodeRenderingPool).to receive_messages(
33+
renderer_bundle_file_name: renderer_bundle_file_name, rsc_renderer_bundle_file_name: rsc_renderer_bundle_file_name
34+
)
3735
allow(ReactOnRails::Utils).to receive(:server_bundle_js_file_path).and_return(server_bundle_path)
3836

39-
allow(ReactOnRails::Utils).to receive(:rsc_bundle_js_file_path).and_return(rsc_server_bundle_path)
37+
allow(ReactOnRailsPro::Utils).to receive(:rsc_bundle_js_file_path).and_return(rsc_server_bundle_path)
4038
end
4139

4240
after do

react_on_rails_pro/spec/react_on_rails_pro/utils_spec.rb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,16 @@ module ReactOnRailsPro
7878
rsc_bundle_js_file_path = File.expand_path("./public/#{rsc_bundle_js_file}")
7979
allow(Shakapacker).to receive_message_chain("manifest.lookup!")
8080
.and_return(rsc_bundle_js_file)
81-
allow(ReactOnRails::Utils).to receive_messages(
82-
server_bundle_js_file_path: rsc_bundle_js_file_path.gsub("rsc-", ""),
83-
rsc_bundle_js_file_path: rsc_bundle_js_file_path
84-
)
81+
allow(ReactOnRails::Utils).to receive(:server_bundle_js_file_path)
82+
.and_return(rsc_bundle_js_file_path.gsub("rsc-", ""))
83+
allow(described_class).to receive(:rsc_bundle_js_file_path)
84+
.and_return(rsc_bundle_js_file_path)
8585
allow(ReactOnRails.configuration)
86-
.to receive_messages(server_bundle_js_file: "webpack-bundle.js",
87-
rsc_bundle_js_file: "rsc-webpack-bundle.js")
86+
.to receive(:server_bundle_js_file)
87+
.and_return("webpack-bundle.js")
88+
allow(ReactOnRailsPro.configuration)
89+
.to receive(:rsc_bundle_js_file)
90+
.and_return("rsc-webpack-bundle.js")
8891
allow(Digest::MD5).to receive(:file)
8992
.with(rsc_bundle_js_file_path)
9093
.and_return("barfoobarfoo")

0 commit comments

Comments
 (0)