Skip to content

Commit bb35666

Browse files
Phase 2: Move RSC configuration options to Pro gem
Moved RSC-specific configurations from open-source to Pro gem: - rsc_bundle_js_file - react_client_manifest_file - react_server_client_manifest_file Changes: - Removed RSC configs from ReactOnRails::Configuration - Added RSC configs to ReactOnRailsPro::Configuration with same defaults - Updated all code references to use Pro config when available - Updated Pro dummy app to use ReactOnRailsPro.configure for RSC config - Removed RSC config tests from open-source spec - Added comprehensive RSC config tests to Pro spec Files modified: - lib/react_on_rails/configuration.rb - lib/react_on_rails/utils.rb - lib/react_on_rails/test_helper/webpack_assets_status_checker.rb - lib/react_on_rails/packer_utils.rb - react_on_rails_pro/lib/react_on_rails_pro/configuration.rb - react_on_rails_pro/spec/dummy/config/initializers/*.rb - spec/react_on_rails/configuration_spec.rb - react_on_rails_pro/spec/react_on_rails_pro/configuration_spec.rb Related to #1874
1 parent 78d5717 commit bb35666

File tree

9 files changed

+105
-127
lines changed

9 files changed

+105
-127
lines changed

lib/react_on_rails/configuration.rb

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ def self.configure
99
end
1010

1111
DEFAULT_GENERATED_ASSETS_DIR = File.join(%w[public webpack], Rails.env).freeze
12-
DEFAULT_REACT_CLIENT_MANIFEST_FILE = "react-client-manifest.json"
13-
DEFAULT_REACT_SERVER_CLIENT_MANIFEST_FILE = "react-server-client-manifest.json"
1412
DEFAULT_COMPONENT_REGISTRY_TIMEOUT = 5000
1513

1614
def self.configuration
@@ -20,9 +18,6 @@ def self.configuration
2018
# generated_assets_dirs is deprecated
2119
generated_assets_dir: "",
2220
server_bundle_js_file: "",
23-
rsc_bundle_js_file: "",
24-
react_client_manifest_file: DEFAULT_REACT_CLIENT_MANIFEST_FILE,
25-
react_server_client_manifest_file: DEFAULT_REACT_SERVER_CLIENT_MANIFEST_FILE,
2621
prerender: false,
2722
auto_load_bundle: false,
2823
replay_console: true,
@@ -72,8 +67,8 @@ class Configuration
7267
:server_render_method, :random_dom_id, :auto_load_bundle,
7368
:same_bundle_for_client_and_server, :rendering_props_extension,
7469
:make_generated_server_bundle_the_entrypoint,
75-
:generated_component_packs_loading_strategy, :immediate_hydration, :rsc_bundle_js_file,
76-
:react_client_manifest_file, :react_server_client_manifest_file, :component_registry_timeout,
70+
:generated_component_packs_loading_strategy, :immediate_hydration,
71+
:component_registry_timeout,
7772
:server_bundle_output_path, :enforce_private_server_bundles
7873

7974
# rubocop:disable Metrics/AbcSize
@@ -90,7 +85,6 @@ def initialize(node_modules_location: nil, server_bundle_js_file: nil, prerender
9085
i18n_dir: nil, i18n_yml_dir: nil, i18n_output_format: nil, i18n_yml_safe_load_options: nil,
9186
random_dom_id: nil, server_render_method: nil, rendering_props_extension: nil,
9287
components_subdirectory: nil, auto_load_bundle: nil, immediate_hydration: nil,
93-
rsc_bundle_js_file: nil, react_client_manifest_file: nil, react_server_client_manifest_file: nil,
9488
component_registry_timeout: nil, server_bundle_output_path: nil, enforce_private_server_bundles: nil)
9589
self.node_modules_location = node_modules_location.present? ? node_modules_location : Rails.root
9690
self.generated_assets_dirs = generated_assets_dirs
@@ -119,9 +113,6 @@ def initialize(node_modules_location: nil, server_bundle_js_file: nil, prerender
119113

120114
# Server rendering:
121115
self.server_bundle_js_file = server_bundle_js_file
122-
self.rsc_bundle_js_file = rsc_bundle_js_file
123-
self.react_client_manifest_file = react_client_manifest_file
124-
self.react_server_client_manifest_file = react_server_client_manifest_file
125116
self.same_bundle_for_client_and_server = same_bundle_for_client_and_server
126117
self.server_renderer_pool_size = self.development_mode ? 1 : server_renderer_pool_size
127118
self.server_renderer_timeout = server_renderer_timeout # seconds

lib/react_on_rails/packer_utils.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,12 @@ def self.bundle_js_uri_from_packer(bundle_name)
5555
# the webpack-dev-server is provided by the config value
5656
# "same_bundle_for_client_and_server" where a value of true
5757
# would mean that the bundle is created by the webpack-dev-server
58-
is_bundle_running_on_server = (bundle_name == ReactOnRails.configuration.server_bundle_js_file) ||
59-
(bundle_name == ReactOnRails.configuration.rsc_bundle_js_file)
58+
is_bundle_running_on_server = bundle_name == ReactOnRails.configuration.server_bundle_js_file
59+
60+
# Check Pro RSC bundle if Pro is available
61+
if ReactOnRails::Utils.react_on_rails_pro? && defined?(ReactOnRailsPro)
62+
is_bundle_running_on_server ||= (bundle_name == ReactOnRailsPro.configuration.rsc_bundle_js_file)
63+
end
6064

6165
if ::Shakapacker.dev_server.running? && (!is_bundle_running_on_server ||
6266
ReactOnRails.configuration.same_bundle_for_client_and_server)

lib/react_on_rails/test_helper/webpack_assets_status_checker.rb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,16 @@ def stale_generated_files(files)
5050
def all_compiled_assets
5151
@all_compiled_assets ||= begin
5252
webpack_generated_files = @webpack_generated_files.map do |bundle_name|
53-
if bundle_name == ReactOnRails.configuration.react_client_manifest_file
54-
ReactOnRails::Utils.react_client_manifest_file_path
55-
elsif bundle_name == ReactOnRails.configuration.react_server_client_manifest_file
56-
ReactOnRails::Utils.react_server_client_manifest_file_path
53+
# Check if this is a Pro RSC manifest file
54+
if ReactOnRails::Utils.react_on_rails_pro?
55+
pro_config = ReactOnRailsPro.configuration
56+
if bundle_name == pro_config.react_client_manifest_file
57+
ReactOnRails::Utils.react_client_manifest_file_path
58+
elsif bundle_name == pro_config.react_server_client_manifest_file
59+
ReactOnRails::Utils.react_server_client_manifest_file_path
60+
else
61+
ReactOnRails::Utils.bundle_js_file_path(bundle_name)
62+
end
5763
else
5864
ReactOnRails::Utils.bundle_js_file_path(bundle_name)
5965
end

lib/react_on_rails/utils.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,16 @@ def self.bundle_js_file_path(bundle_name)
111111

112112
private_class_method def self.server_bundle?(bundle_name)
113113
config = ReactOnRails.configuration
114-
bundle_name == config.server_bundle_js_file ||
115-
bundle_name == config.rsc_bundle_js_file ||
116-
bundle_name == config.react_server_client_manifest_file
114+
return true if bundle_name == config.server_bundle_js_file
115+
116+
# Check Pro configurations if Pro is available
117+
if react_on_rails_pro?
118+
pro_config = ReactOnRailsPro.configuration
119+
return true if bundle_name == pro_config.rsc_bundle_js_file ||
120+
bundle_name == pro_config.react_server_client_manifest_file
121+
end
122+
123+
false
117124
end
118125

119126
private_class_method def self.handle_missing_manifest_entry(bundle_name, is_server_bundle)

react_on_rails_pro/lib/react_on_rails_pro/configuration.rb

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ def self.configuration
2929
profile_server_rendering_js_code: Configuration::DEFAULT_PROFILE_SERVER_RENDERING_JS_CODE,
3030
raise_non_shell_server_rendering_errors: Configuration::DEFAULT_RAISE_NON_SHELL_SERVER_RENDERING_ERRORS,
3131
enable_rsc_support: Configuration::DEFAULT_ENABLE_RSC_SUPPORT,
32-
rsc_payload_generation_url_path: Configuration::DEFAULT_RSC_PAYLOAD_GENERATION_URL_PATH
32+
rsc_payload_generation_url_path: Configuration::DEFAULT_RSC_PAYLOAD_GENERATION_URL_PATH,
33+
rsc_bundle_js_file: Configuration::DEFAULT_RSC_BUNDLE_JS_FILE,
34+
react_client_manifest_file: Configuration::DEFAULT_REACT_CLIENT_MANIFEST_FILE,
35+
react_server_client_manifest_file: Configuration::DEFAULT_REACT_SERVER_CLIENT_MANIFEST_FILE
3336
)
3437
end
3538

@@ -53,6 +56,9 @@ class Configuration # rubocop:disable Metrics/ClassLength
5356
DEFAULT_RAISE_NON_SHELL_SERVER_RENDERING_ERRORS = false
5457
DEFAULT_ENABLE_RSC_SUPPORT = false
5558
DEFAULT_RSC_PAYLOAD_GENERATION_URL_PATH = "rsc_payload/"
59+
DEFAULT_RSC_BUNDLE_JS_FILE = "rsc-bundle.js"
60+
DEFAULT_REACT_CLIENT_MANIFEST_FILE = "react-client-manifest.json"
61+
DEFAULT_REACT_SERVER_CLIENT_MANIFEST_FILE = "react-server-client-manifest.json"
5662

5763
attr_accessor :renderer_url, :renderer_password, :tracing,
5864
:server_renderer, :renderer_use_fallback_exec_js, :prerender_caching,
@@ -61,7 +67,8 @@ class Configuration # rubocop:disable Metrics/ClassLength
6167
:remote_bundle_cache_adapter, :ssr_pre_hook_js, :assets_to_copy,
6268
:renderer_request_retry_limit, :throw_js_errors, :ssr_timeout,
6369
:profile_server_rendering_js_code, :raise_non_shell_server_rendering_errors, :enable_rsc_support,
64-
:rsc_payload_generation_url_path
70+
:rsc_payload_generation_url_path, :rsc_bundle_js_file, :react_client_manifest_file,
71+
:react_server_client_manifest_file
6572

6673
def initialize(renderer_url: nil, renderer_password: nil, server_renderer: nil, # rubocop:disable Metrics/AbcSize
6774
renderer_use_fallback_exec_js: nil, prerender_caching: nil,
@@ -71,7 +78,8 @@ def initialize(renderer_url: nil, renderer_password: nil, server_renderer: nil,
7178
remote_bundle_cache_adapter: nil, ssr_pre_hook_js: nil, assets_to_copy: nil,
7279
renderer_request_retry_limit: nil, throw_js_errors: nil, ssr_timeout: nil,
7380
profile_server_rendering_js_code: nil, raise_non_shell_server_rendering_errors: nil,
74-
enable_rsc_support: nil, rsc_payload_generation_url_path: nil)
81+
enable_rsc_support: nil, rsc_payload_generation_url_path: nil,
82+
rsc_bundle_js_file: nil, react_client_manifest_file: nil, react_server_client_manifest_file: nil)
7583
self.renderer_url = renderer_url
7684
self.renderer_password = renderer_password
7785
self.server_renderer = server_renderer
@@ -94,6 +102,9 @@ def initialize(renderer_url: nil, renderer_password: nil, server_renderer: nil,
94102
self.raise_non_shell_server_rendering_errors = raise_non_shell_server_rendering_errors
95103
self.enable_rsc_support = enable_rsc_support
96104
self.rsc_payload_generation_url_path = rsc_payload_generation_url_path
105+
self.rsc_bundle_js_file = rsc_bundle_js_file
106+
self.react_client_manifest_file = react_client_manifest_file
107+
self.react_server_client_manifest_file = react_server_client_manifest_file
97108
end
98109

99110
def setup_config_values

react_on_rails_pro/spec/dummy/config/initializers/react_on_rails.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ def self.adjust_props_for_client_side_hydration(_component_name, props)
2727

2828
ReactOnRails.configure do |config|
2929
config.server_bundle_js_file = "server-bundle.js"
30-
config.rsc_bundle_js_file = "rsc-bundle.js"
3130
config.random_dom_id = false # default is true
3231

3332
# Next 2 lines are commented out because we've set test.compile to true

react_on_rails_pro/spec/dummy/config/initializers/react_on_rails_pro.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
config.rendering_returns_promises = true
99

10+
# RSC bundle configuration (moved from ReactOnRails.configure)
11+
config.rsc_bundle_js_file = "rsc-bundle.js"
12+
1013
config.server_renderer = "NodeRenderer"
1114
# If you want Honeybadger or Sentry on the Node renderer side to report rendering errors
1215
config.throw_js_errors = false

react_on_rails_pro/spec/react_on_rails_pro/configuration_spec.rb

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,5 +198,65 @@ def self.fetch(*)
198198
/ExecJS profiler only supports Node.js \(V8\) or V8 runtimes./)
199199
end
200200
end
201+
202+
describe "RSC configuration options" do
203+
it "has default values for RSC bundle and manifest files" do
204+
ReactOnRailsPro.configure {} # rubocop:disable Lint/EmptyBlock
205+
206+
expect(ReactOnRailsPro.configuration.rsc_bundle_js_file).to eq("rsc-bundle.js")
207+
expect(ReactOnRailsPro.configuration.react_client_manifest_file).to eq("react-client-manifest.json")
208+
expect(ReactOnRailsPro.configuration.react_server_client_manifest_file).to eq("react-server-client-manifest.json")
209+
end
210+
211+
it "allows setting rsc_bundle_js_file" do
212+
ReactOnRailsPro.configure do |config|
213+
config.rsc_bundle_js_file = "custom-rsc-bundle.js"
214+
end
215+
216+
expect(ReactOnRailsPro.configuration.rsc_bundle_js_file).to eq("custom-rsc-bundle.js")
217+
end
218+
219+
it "allows setting react_client_manifest_file" do
220+
ReactOnRailsPro.configure do |config|
221+
config.react_client_manifest_file = "custom-client-manifest.json"
222+
end
223+
224+
expect(ReactOnRailsPro.configuration.react_client_manifest_file).to eq("custom-client-manifest.json")
225+
end
226+
227+
it "allows setting react_server_client_manifest_file" do
228+
ReactOnRailsPro.configure do |config|
229+
config.react_server_client_manifest_file = "custom-server-client-manifest.json"
230+
end
231+
232+
expect(ReactOnRailsPro.configuration.react_server_client_manifest_file).to eq("custom-server-client-manifest.json")
233+
end
234+
235+
it "allows nil values for RSC configuration options" do
236+
ReactOnRailsPro.configure do |config|
237+
config.rsc_bundle_js_file = nil
238+
config.react_client_manifest_file = nil
239+
config.react_server_client_manifest_file = nil
240+
end
241+
242+
expect(ReactOnRailsPro.configuration.rsc_bundle_js_file).to be_nil
243+
expect(ReactOnRailsPro.configuration.react_client_manifest_file).to be_nil
244+
expect(ReactOnRailsPro.configuration.react_server_client_manifest_file).to be_nil
245+
end
246+
247+
it "configures all RSC options together for a typical RSC setup" do
248+
ReactOnRailsPro.configure do |config|
249+
config.enable_rsc_support = true
250+
config.rsc_bundle_js_file = "rsc-bundle.js"
251+
config.react_client_manifest_file = "client-manifest.json"
252+
config.react_server_client_manifest_file = "server-client-manifest.json"
253+
end
254+
255+
expect(ReactOnRailsPro.configuration.enable_rsc_support).to be(true)
256+
expect(ReactOnRailsPro.configuration.rsc_bundle_js_file).to eq("rsc-bundle.js")
257+
expect(ReactOnRailsPro.configuration.react_client_manifest_file).to eq("client-manifest.json")
258+
expect(ReactOnRailsPro.configuration.react_server_client_manifest_file).to eq("server-client-manifest.json")
259+
end
260+
end
201261
end
202262
end

spec/react_on_rails/configuration_spec.rb

Lines changed: 0 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -190,109 +190,6 @@ module ReactOnRails
190190
end
191191
end
192192

193-
describe "RSC configuration options" do
194-
before do
195-
allow(ReactOnRails::PackerUtils).to receive_messages(
196-
supports_autobundling?: true,
197-
nested_entries?: true
198-
)
199-
end
200-
201-
it "has default values for RSC-related configuration options" do
202-
ReactOnRails.configure {} # rubocop:disable Lint/EmptyBlock
203-
204-
expect(ReactOnRails.configuration.rsc_bundle_js_file).to eq("")
205-
expect(ReactOnRails.configuration.react_client_manifest_file).to eq("react-client-manifest.json")
206-
expect(ReactOnRails.configuration.react_server_client_manifest_file).to eq("react-server-client-manifest.json")
207-
end
208-
209-
it "allows setting rsc_bundle_js_file" do
210-
ReactOnRails.configure do |config|
211-
config.rsc_bundle_js_file = "custom-rsc-bundle.js"
212-
end
213-
214-
expect(ReactOnRails.configuration.rsc_bundle_js_file).to eq("custom-rsc-bundle.js")
215-
end
216-
217-
it "allows setting react_client_manifest_file" do
218-
ReactOnRails.configure do |config|
219-
config.react_client_manifest_file = "custom-client-manifest.json"
220-
end
221-
222-
expect(ReactOnRails.configuration.react_client_manifest_file).to eq("custom-client-manifest.json")
223-
end
224-
225-
it "allows setting react_server_client_manifest_file" do
226-
ReactOnRails.configure do |config|
227-
config.react_server_client_manifest_file = "custom-server-client-manifest.json"
228-
end
229-
230-
expect(ReactOnRails.configuration.react_server_client_manifest_file).to eq("custom-server-client-manifest.json")
231-
end
232-
233-
it "includes rsc files in webpack_generated_files when not blank" do
234-
ReactOnRails.configure do |config|
235-
config.rsc_bundle_js_file = "rsc-bundle.js"
236-
config.webpack_generated_files = []
237-
end
238-
239-
expect(ReactOnRails.configuration.webpack_generated_files).to include("rsc-bundle.js")
240-
end
241-
242-
it "includes client manifest in webpack_generated_files" do
243-
ReactOnRails.configure do |config|
244-
config.react_client_manifest_file = "custom-client-manifest.json"
245-
config.webpack_generated_files = []
246-
end
247-
248-
expect(ReactOnRails.configuration.webpack_generated_files).to include("custom-client-manifest.json")
249-
end
250-
251-
it "includes server-client manifest in webpack_generated_files" do
252-
ReactOnRails.configure do |config|
253-
config.react_server_client_manifest_file = "custom-server-client-manifest.json"
254-
config.webpack_generated_files = []
255-
end
256-
257-
expect(ReactOnRails.configuration.webpack_generated_files).to include("custom-server-client-manifest.json")
258-
end
259-
260-
it "configures all RSC options together for a typical RSC setup" do
261-
ReactOnRails.configure do |config|
262-
config.rsc_bundle_js_file = "rsc-bundle.js"
263-
config.react_client_manifest_file = "client-manifest.json"
264-
config.react_server_client_manifest_file = "server-client-manifest.json"
265-
config.webpack_generated_files = []
266-
end
267-
268-
expect(ReactOnRails.configuration.rsc_bundle_js_file).to eq("rsc-bundle.js")
269-
expect(ReactOnRails.configuration.react_client_manifest_file).to eq("client-manifest.json")
270-
expect(ReactOnRails.configuration.react_server_client_manifest_file).to eq("server-client-manifest.json")
271-
272-
# All RSC files should be included in webpack_generated_files
273-
expect(ReactOnRails.configuration.webpack_generated_files).to include("rsc-bundle.js")
274-
expect(ReactOnRails.configuration.webpack_generated_files).to include("client-manifest.json")
275-
expect(ReactOnRails.configuration.webpack_generated_files).to include("server-client-manifest.json")
276-
end
277-
278-
it "allows nil values for RSC configuration options" do
279-
ReactOnRails.configure do |config|
280-
config.rsc_bundle_js_file = nil
281-
config.react_client_manifest_file = nil
282-
config.react_server_client_manifest_file = nil
283-
config.webpack_generated_files = []
284-
end
285-
286-
expect(ReactOnRails.configuration.rsc_bundle_js_file).to be_nil
287-
expect(ReactOnRails.configuration.react_client_manifest_file).to be_nil
288-
expect(ReactOnRails.configuration.react_server_client_manifest_file).to be_nil
289-
290-
# Nil values should not be included in webpack_generated_files
291-
expect(ReactOnRails.configuration.webpack_generated_files).not_to include(nil)
292-
# Only manifest.json should be in the list by default
293-
expect(ReactOnRails.configuration.webpack_generated_files).to eq(["manifest.json"])
294-
end
295-
end
296193

297194
it "changes the configuration of the gem, such as setting the prerender option to false" do
298195
test_path = File.expand_path("public/webpack/test")

0 commit comments

Comments
 (0)