Skip to content

Commit 6fd73e7

Browse files
Add null check for ReactOnRails global object in component and store loading scripts
1 parent aec0357 commit 6fd73e7

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

lib/react_on_rails/helper.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ def internal_react_component(react_component_name, options = {})
644644
if render_options.force_load
645645
component_specification_tag.concat(
646646
content_tag(:script, %(
647-
ReactOnRails.reactOnRailsComponentLoaded('#{render_options.dom_id}');
647+
typeof ReactOnRails === 'object' && ReactOnRails.reactOnRailsComponentLoaded('#{render_options.dom_id}');
648648
).html_safe)
649649
)
650650
end
@@ -670,7 +670,7 @@ def render_redux_store_data(redux_store_data)
670670
if redux_store_data[:force_load]
671671
store_hydration_data.concat(
672672
content_tag(:script, <<~JS.strip_heredoc.html_safe
673-
ReactOnRails.reactOnRailsStoreLoaded('#{redux_store_data[:store_name]}');
673+
typeof ReactOnRails === 'object' && ReactOnRails.reactOnRailsStoreLoaded('#{redux_store_data[:store_name]}');
674674
JS
675675
)
676676
)

spec/dummy/spec/helpers/react_on_rails_helper_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ class PlainReactOnRailsHelper
304304
describe "'force_load' tag option" do
305305
let(:force_load_script) do
306306
%(
307-
ReactOnRails.reactOnRailsComponentLoaded('App-react-component-0');
307+
typeof ReactOnRails === 'object' && ReactOnRails.reactOnRailsComponentLoaded('App-react-component-0');
308308
).html_safe
309309
end
310310

0 commit comments

Comments
 (0)