Skip to content

Commit dbc5920

Browse files
justin808claude
andcommitted
Restore server bundle support and fix failing tests
- Add back server bundle logic that respects server_bundle_output_path configuration - Server bundles with configured output path skip manifest lookup for better performance - Server bundles without configured path use fallback logic like client bundles - Fix test mocking to properly test fallback behavior when server_bundle_output_path is nil - All utils tests now pass (53/53) This integrates the simpler remote approach while preserving the essential server bundle functionality that the configuration and tests expect. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 62e9f01 commit dbc5920

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

lib/react_on_rails/utils.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,17 @@ def self.server_bundle_path_is_http?
7171
end
7272

7373
def self.bundle_js_file_path(bundle_name)
74+
# Check if this is a server bundle with configured output path - skip manifest lookup
75+
if server_bundle?(bundle_name)
76+
config = ReactOnRails.configuration
77+
root_path = Rails.root || "."
78+
79+
# Use configured server_bundle_output_path if present
80+
if config.server_bundle_output_path.present?
81+
return File.expand_path(File.join(root_path, config.server_bundle_output_path, bundle_name))
82+
end
83+
end
84+
7485
# Either:
7586
# 1. Using same bundle for both server and client, so server bundle will be hashed in manifest
7687
# 2. Using a different bundle (different Webpack config), so file is not hashed, and
@@ -117,6 +128,12 @@ def self.bundle_js_file_path(bundle_name)
117128
File.expand_path(fallback_locations.first)
118129
end
119130

131+
private_class_method def self.server_bundle?(bundle_name)
132+
config = ReactOnRails.configuration
133+
bundle_name == config.server_bundle_js_file ||
134+
bundle_name == config.rsc_bundle_js_file
135+
end
136+
120137
def self.server_bundle_js_file_path
121138
return @server_bundle_path if @server_bundle_path && !Rails.env.development?
122139

spec/react_on_rails/utils_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,9 @@ def mock_dev_server_running
244244
it "returns the standard location path" do
245245
server_bundle_name = "server-bundle.js"
246246
mock_bundle_configs(server_bundle_name: server_bundle_name)
247+
# Override server_bundle_output_path to test fallback behavior
248+
allow(ReactOnRails).to receive_message_chain("configuration.server_bundle_output_path")
249+
.and_return(nil)
247250
mock_missing_manifest_entry(server_bundle_name)
248251

249252
# Mock File.exist? to return false for environment-specific path but true for standard path
@@ -264,6 +267,9 @@ def mock_dev_server_running
264267
it "returns the environment-specific path as final fallback" do
265268
server_bundle_name = "server-bundle.js"
266269
mock_bundle_configs(server_bundle_name: server_bundle_name)
270+
# Override server_bundle_output_path to test fallback behavior
271+
allow(ReactOnRails).to receive_message_chain("configuration.server_bundle_output_path")
272+
.and_return(nil)
267273
mock_missing_manifest_entry(server_bundle_name)
268274

269275
# Mock File.exist? to return false for all paths

0 commit comments

Comments
 (0)