Skip to content

Commit 87a5ad8

Browse files
Return script_content from Pro enhance methods for future extensibility
Updated both enhance_component_script_data and enhance_store_script_data to return script_content in addition to script_attrs and additional_scripts. Currently returns unchanged content, but this enables future modifications like wrapping or transforming the script content. Core gem now uses the returned script_content from Pro methods. Updated all test stubs to match the new signature. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 797601e commit 87a5ad8

File tree

4 files changed

+24
-12
lines changed

4 files changed

+24
-12
lines changed

lib/react_on_rails/helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,7 @@ def generate_component_script(render_options)
819819
render_options: render_options
820820
)
821821
script_attrs = result[:script_attrs]
822+
script_content = result[:script_content]
822823
additional_scripts = result[:additional_scripts]
823824
end
824825

@@ -846,6 +847,7 @@ def generate_store_script(redux_store_data)
846847
redux_store_data: redux_store_data
847848
)
848849
script_attrs = result[:script_attrs]
850+
script_content = result[:script_content]
849851
additional_scripts = result[:additional_scripts]
850852
end
851853

react_on_rails_pro/lib/react_on_rails_pro/helper.rb

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ module Helper
2323

2424
# Enhances component script data with immediate hydration support
2525
# @param script_attrs [Hash] Base script tag attributes
26-
# @param script_content [String] Script content (not used in current implementation)
26+
# @param script_content [String] Script content
2727
# @param render_options [ReactOnRails::ReactComponent::RenderOptions] Render options
28-
# @return [Hash] Enhanced script attributes and additional scripts
28+
# @return [Hash] Enhanced script attributes, script content, and additional scripts
2929
def self.enhance_component_script_data(script_attrs:, script_content:, render_options:)
30-
_ = script_content # Mark as intentionally unused
30+
# NOTE: Currently returns script_content unchanged, but this allows for future
31+
# modifications to the script content if needed (e.g., wrapping, transforming, etc.)
32+
3133
if render_options.immediate_hydration
3234
# Add data attribute for immediate hydration
3335
script_attrs["data-immediate-hydration"] = true
@@ -40,20 +42,23 @@ def self.enhance_component_script_data(script_attrs:, script_content:, render_op
4042

4143
return {
4244
script_attrs: script_attrs,
45+
script_content: script_content,
4346
additional_scripts: [immediate_script]
4447
}
4548
end
4649

47-
{ script_attrs: script_attrs, additional_scripts: [] }
50+
{ script_attrs: script_attrs, script_content: script_content, additional_scripts: [] }
4851
end
4952

5053
# Enhances store script data with immediate hydration support
5154
# @param script_attrs [Hash] Base script tag attributes
52-
# @param script_content [String] Script content (not used in current implementation)
55+
# @param script_content [String] Script content
5356
# @param redux_store_data [Hash] Redux store data including store_name and props
54-
# @return [Hash] Enhanced script attributes and additional scripts
57+
# @return [Hash] Enhanced script attributes, script content, and additional scripts
5558
def self.enhance_store_script_data(script_attrs:, script_content:, redux_store_data:)
56-
_ = script_content # Mark as intentionally unused
59+
# NOTE: Currently returns script_content unchanged, but this allows for future
60+
# modifications to the script content if needed (e.g., wrapping, transforming, etc.)
61+
5762
if redux_store_data[:immediate_hydration]
5863
# Add data attribute for immediate hydration
5964
script_attrs["data-immediate-hydration"] = true
@@ -66,11 +71,12 @@ def self.enhance_store_script_data(script_attrs:, script_content:, redux_store_d
6671

6772
return {
6873
script_attrs: script_attrs,
74+
script_content: script_content,
6975
additional_scripts: [immediate_script]
7076
}
7177
end
7278

73-
{ script_attrs: script_attrs, additional_scripts: [] }
79+
{ script_attrs: script_attrs, script_content: script_content, additional_scripts: [] }
7480
end
7581
end
7682
end

spec/dummy/spec/helpers/react_on_rails_helper_spec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,11 @@ def self.enhance_component_script_data(args)
4545
"ReactOnRails.reactOnRailsComponentLoaded('#{dom_id}');\n </script>"
4646
{
4747
script_attrs: args[:script_attrs].merge("data-immediate-hydration" => true),
48+
script_content: args[:script_content],
4849
additional_scripts: [script_tag]
4950
}
5051
else
51-
{ script_attrs: args[:script_attrs], additional_scripts: [] }
52+
{ script_attrs: args[:script_attrs], script_content: args[:script_content], additional_scripts: [] }
5253
end
5354
end
5455

@@ -59,10 +60,11 @@ def self.enhance_store_script_data(args)
5960
"ReactOnRails.reactOnRailsStoreLoaded('#{store_name}');\n </script>"
6061
{
6162
script_attrs: args[:script_attrs].merge("data-immediate-hydration" => true),
63+
script_content: args[:script_content],
6264
additional_scripts: [script_tag]
6365
}
6466
else
65-
{ script_attrs: args[:script_attrs], additional_scripts: [] }
67+
{ script_attrs: args[:script_attrs], script_content: args[:script_content], additional_scripts: [] }
6668
end
6769
end
6870
end)

spec/dummy/spec/system/integration_spec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,11 @@ def self.enhance_component_script_data(args)
107107
"ReactOnRails.reactOnRailsComponentLoaded('#{dom_id}');\n </script>"
108108
{
109109
script_attrs: args[:script_attrs].merge("data-immediate-hydration" => true),
110+
script_content: args[:script_content],
110111
additional_scripts: [script_tag]
111112
}
112113
else
113-
{ script_attrs: args[:script_attrs], additional_scripts: [] }
114+
{ script_attrs: args[:script_attrs], script_content: args[:script_content], additional_scripts: [] }
114115
end
115116
end
116117

@@ -121,10 +122,11 @@ def self.enhance_store_script_data(args)
121122
"ReactOnRails.reactOnRailsStoreLoaded('#{store_name}');\n </script>"
122123
{
123124
script_attrs: args[:script_attrs].merge("data-immediate-hydration" => true),
125+
script_content: args[:script_content],
124126
additional_scripts: [script_tag]
125127
}
126128
else
127-
{ script_attrs: args[:script_attrs], additional_scripts: [] }
129+
{ script_attrs: args[:script_attrs], script_content: args[:script_content], additional_scripts: [] }
128130
end
129131
end
130132
end)

0 commit comments

Comments
 (0)