Skip to content

Commit 920ed7c

Browse files
Refactor immediate hydration data attribute handling in Pro features
- Updated the `helper.rb` file to modify how the `data-immediate-hydration` attribute is added to script tags, ensuring it is correctly applied during immediate hydration. - Adjusted the test helper spec to correct the formatting of the immediate hydration script, enhancing clarity and functionality.
1 parent 297fa02 commit 920ed7c

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

lib/react_on_rails/pro_features/helper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def apply_immediate_hydration_if_supported(component_specification_tag, render_o
2828
return component_specification_tag unless render_options.immediate_hydration && support_pro_features?
2929

3030
# Add data attribute
31-
component_specification_tag.gsub!(/>\z/, ' data-immediate-hydration="true">')
31+
component_specification_tag.gsub!(/\<script /, '<script data-immediate-hydration="true" ')
3232

3333
# Add immediate invocation script
3434
component_specification_tag.concat(
@@ -43,7 +43,7 @@ def apply_store_immediate_hydration_if_supported(store_hydration_data, redux_sto
4343
return store_hydration_data unless redux_store_data[:immediate_hydration] && support_pro_features?
4444

4545
# Add data attribute
46-
store_hydration_data.gsub!(/>\z/, ' data-immediate-hydration="true">')
46+
store_hydration_data.gsub!(/\<script /, '<script data-immediate-hydration="true" ')
4747

4848
# Add immediate invocation script
4949
store_hydration_data.concat(

spec/dummy/spec/helpers/react_on_rails_helper_spec.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,7 @@ def helper.append_javascript_pack_tag(name, **options)
368368

369369
describe "'immediate_hydration' tag option" do
370370
let(:immediate_hydration_script) do
371-
%(
372-
typeof ReactOnRails === 'object' && ReactOnRails.reactOnRailsComponentLoaded('App-react-component-0');
373-
).html_safe
371+
%(typeof ReactOnRails === 'object' && ReactOnRails.reactOnRailsComponentLoaded('App-react-component-0');).html_safe
374372
end
375373

376374
context "with 'immediate_hydration' == false" do

0 commit comments

Comments
 (0)