Skip to content

Commit 5c18ac9

Browse files
justin808claude
andcommitted
Make generated_component_packs_loading_strategy default based on Pro license
- Pro users (Shakapacker >= 8.2.0): defaults to :async for optimal performance - Non-Pro users (Shakapacker >= 8.2.0): defaults to :defer for compatibility - Older Shakapacker versions: continues to default to :sync (unchanged) This aligns with the immediate_hydration behavior where Pro features are automatically enabled based on license detection, providing the best default experience for each user type. Updated tests to verify Pro/non-Pro default behaviors separately while maintaining tests for explicit value overrides. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 0d8552b commit 5c18ac9

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ Changes since the last non-beta release.
5353

5454
- **`immediate_hydration` now automatically enabled for Pro users**: The `config.immediate_hydration` configuration option has been removed. Immediate hydration is now automatically enabled for React on Rails Pro users and disabled for non-Pro users, simplifying configuration while providing optimal performance by default. Component-level overrides are still supported via the `immediate_hydration` parameter on `react_component`, `redux_store`, and `stream_react_component` helpers. [PR 1997](https://github.com/shakacode/react_on_rails/pull/1997) by [AbanoubGhadban](https://github.com/AbanoubGhadban).
5555

56+
- **`generated_component_packs_loading_strategy` now defaults based on Pro license**: When using Shakapacker >= 8.2.0, the default loading strategy is now `:async` for Pro users and `:defer` for non-Pro users. This provides optimal performance for Pro users while maintaining compatibility for non-Pro users. You can still explicitly set the strategy in your configuration. [PR #1993](https://github.com/shakacode/react_on_rails/pull/1993) by [AbanoubGhadban](https://github.com/AbanoubGhadban).
57+
5658
#### Bug Fixes
5759

5860
- **Use as Git dependency**: All packages can now be installed as Git dependencies. This is useful for development and testing purposes. See [CONTRIBUTING.md](./CONTRIBUTING.md#git-dependencies) for documentation. [PR #1873](https://github.com/shakacode/react_on_rails/pull/1873) by [alexeyr-ci2](https://github.com/alexeyr-ci2).

lib/react_on_rails/configuration.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,8 @@ def validate_generated_component_packs_loading_strategy
219219
2. Upgrade to Shakapacker v8.2.0 or above to enable async script loading
220220
MSG
221221
if PackerUtils.supports_async_loading?
222-
self.generated_component_packs_loading_strategy ||= :async
222+
# Default based on Pro license: Pro users get :async, non-Pro users get :defer
223+
self.generated_component_packs_loading_strategy ||= (Utils.react_on_rails_pro? ? :async : :defer)
223224
elsif generated_component_packs_loading_strategy.nil?
224225
Rails.logger.warn("**WARNING** #{msg}")
225226
self.generated_component_packs_loading_strategy = :sync

spec/react_on_rails/configuration_spec.rb

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,26 @@ module ReactOnRails
284284
.with("8.2.0").and_return(true)
285285
end
286286

287-
it "defaults to :async" do
288-
ReactOnRails.configure {} # rubocop:disable Lint/EmptyBlock
289-
expect(ReactOnRails.configuration.generated_component_packs_loading_strategy).to eq(:async)
287+
context "with Pro license" do
288+
before do
289+
allow(ReactOnRails::Utils).to receive(:react_on_rails_pro?).and_return(true)
290+
end
291+
292+
it "defaults to :async" do
293+
ReactOnRails.configure {} # rubocop:disable Lint/EmptyBlock
294+
expect(ReactOnRails.configuration.generated_component_packs_loading_strategy).to eq(:async)
295+
end
296+
end
297+
298+
context "without Pro license" do
299+
before do
300+
allow(ReactOnRails::Utils).to receive(:react_on_rails_pro?).and_return(false)
301+
end
302+
303+
it "defaults to :defer" do
304+
ReactOnRails.configure {} # rubocop:disable Lint/EmptyBlock
305+
expect(ReactOnRails.configuration.generated_component_packs_loading_strategy).to eq(:defer)
306+
end
290307
end
291308

292309
it "accepts :async value" do

0 commit comments

Comments
 (0)