diff --git a/lib/react_on_rails/configuration.rb b/lib/react_on_rails/configuration.rb index b624da46f8..82f76bb76b 100644 --- a/lib/react_on_rails/configuration.rb +++ b/lib/react_on_rails/configuration.rb @@ -172,8 +172,8 @@ def validate_generated_component_packs_loading_strategy msg = <<~MSG ReactOnRails: Your current version of shakapacker \ - does not support async script loading, which may cause performance issues. Please either: - 1. Use :sync or :defer loading strategy instead of :async + does not support async script loading. Please either: + 1. Use :defer or :sync loading strategy instead of :async 2. Upgrade to Shakapacker v8.2.0 or above to enable async script loading MSG if generated_component_packs_loading_strategy.nil? diff --git a/spec/dummy/spec/helpers/react_on_rails_helper_spec.rb b/spec/dummy/spec/helpers/react_on_rails_helper_spec.rb index 1f3c944f74..1a691fdc38 100644 --- a/spec/dummy/spec/helpers/react_on_rails_helper_spec.rb +++ b/spec/dummy/spec/helpers/react_on_rails_helper_spec.rb @@ -77,6 +77,8 @@ def self.pro_attribution_comment allow(helper).to receive(:append_stylesheet_pack_tag) expect { helper.load_pack_for_generated_component("component_name", render_options) }.not_to raise_error + # Default loading strategy is now always :defer to prevent race conditions + # between component registration and hydration, regardless of async support expect(helper).to have_received(:append_javascript_pack_tag).with("generated/component_name", { defer: true }) expect(helper).to have_received(:append_stylesheet_pack_tag).with("generated/component_name") end