Skip to content

Commit 1b750e9

Browse files
refactor: Use configuration-based approach for server bundle output path
- Set 'ssr-generated' as default value for server_bundle_output_path - Remove hard-coded paths from try_private_server_locations - Update handle_missing_manifest_entry to respect configuration - Maintain backwards compatibility with 'generated/server-bundles' fallback - Honor enforce_secure_server_bundles flag to prevent public fallbacks Co-authored-by: Abanoub Ghadban <AbanoubGhadban@users.noreply.github.com>
1 parent fbbd00e commit 1b750e9

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

lib/react_on_rails/configuration.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def self.configuration
5353
# Set to 0 to disable the timeout and wait indefinitely for component registration.
5454
component_registry_timeout: DEFAULT_COMPONENT_REGISTRY_TIMEOUT,
5555
generated_component_packs_loading_strategy: nil,
56-
server_bundle_output_path: nil,
56+
server_bundle_output_path: "ssr-generated",
5757
enforce_secure_server_bundles: false
5858
)
5959
end

lib/react_on_rails/utils.rb

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,23 +117,29 @@ def self.bundle_js_file_path(bundle_name)
117117

118118
private_class_method def self.try_private_server_locations(bundle_name)
119119
config = ReactOnRails.configuration
120-
121-
# Build candidate locations, including configured output path
122120
root_path = Rails.root || "."
121+
122+
# Primary location from configuration (now defaults to "ssr-generated")
123123
candidates = [
124-
File.join(root_path, "ssr-generated", bundle_name),
125-
File.join(root_path, "generated", "server-bundles", bundle_name)
124+
File.join(root_path, config.server_bundle_output_path, bundle_name)
126125
]
127126

128-
# Add configured server_bundle_output_path if present
129-
if config.server_bundle_output_path.present?
130-
candidates << File.join(root_path, config.server_bundle_output_path, bundle_name)
131-
end
127+
# Add legacy fallback for backwards compatibility
128+
candidates << File.join(root_path, "generated", "server-bundles", bundle_name)
132129

133130
find_first_existing_path(candidates)
134131
end
135132

136133
private_class_method def self.handle_missing_manifest_entry(bundle_name, is_server_bundle)
134+
config = ReactOnRails.configuration
135+
root_path = Rails.root || "."
136+
137+
# When enforcement is on for server bundles, only use private locations
138+
if is_server_bundle && enforce_secure_server_bundles?
139+
# Only try private locations, no public fallbacks
140+
return File.expand_path(File.join(root_path, config.server_bundle_output_path, bundle_name))
141+
end
142+
137143
# When manifest lookup fails, try multiple fallback locations:
138144
# 1. Environment-specific path (e.g., public/webpack/test)
139145
# 2. Standard Shakapacker location (public/packs)
@@ -150,8 +156,8 @@ def self.bundle_js_file_path(bundle_name)
150156

151157
# If none exist, return appropriate default based on bundle type
152158
if is_server_bundle
153-
# For server bundles, prefer private location as final fallback
154-
File.expand_path(File.join("ssr-generated", bundle_name))
159+
# For server bundles, use configured private location as final fallback
160+
File.expand_path(File.join(root_path, config.server_bundle_output_path, bundle_name))
155161
else
156162
# For client bundles, use environment-specific path (original behavior)
157163
File.expand_path(fallback_locations.first)

spec/react_on_rails/utils_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def mock_dev_server_running
185185
allow(ReactOnRails).to receive_message_chain("configuration.enforce_secure_server_bundles")
186186
.and_return(false)
187187
allow(ReactOnRails).to receive_message_chain("configuration.server_bundle_output_path")
188-
.and_return(nil)
188+
.and_return("ssr-generated")
189189
end
190190

191191
it "tries secure locations first for server bundles" do
@@ -225,7 +225,7 @@ def mock_dev_server_running
225225
allow(ReactOnRails).to receive_message_chain("configuration.enforce_secure_server_bundles")
226226
.and_return(false)
227227
allow(ReactOnRails).to receive_message_chain("configuration.server_bundle_output_path")
228-
.and_return(nil)
228+
.and_return("ssr-generated")
229229
end
230230

231231
it "treats RSC bundles as server bundles and tries secure locations first" do

0 commit comments

Comments
 (0)