You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add configurable loading strategy for generated component packs (#1712)
* Add configurable loading strategy for generated component packs
- Replace `defer_generated_component_packs` with more flexible `generated_component_packs_loading_strategy`
- Add support for `:async`, `:defer`, and `:sync` loading strategies
- Validate loading strategy based on Shakapacker version
- Update helper to support new loading strategy configuration
- Add comprehensive specs for the new configuration option
* Update CHANGELOG and release notes of v15.0.0
* Update generated component pack loading strategy test for CI compatibility
* Add force_load option to redux_store method at ReactOnRails::Controller
* Add packer version environment variable to CI workflows
* Refactor CI packer version environment variable handling in workflows
---------
Co-authored-by: Alexey Romanov <alexey.romanov+ci5@shakacode.com>
Co-authored-by: Judah Meek <judah.meek@gmail.com>
Copy file name to clipboardExpand all lines: CHANGELOG.md
+8Lines changed: 8 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,6 +23,14 @@ After a release, please make sure to run `bundle exec rake update_changelog`. Th
23
23
24
24
Changes since the last non-beta release.
25
25
26
+
#### Added
27
+
28
+
- Configuration option `generated_component_packs_loading_strategy` to control how generated component packs are loaded. It supports `sync`, `async`, and `defer` strategies. [PR 1712](https://github.com/shakacode/react_on_rails/pull/1712) by [AbanoubGhadban](https://github.com/AbanoubGhadban).
29
+
30
+
### Removed (Breaking Changes)
31
+
32
+
- Deprecated `defer_generated_component_packs` configuration option. You should use `generated_component_packs_loading_strategy` instead. [PR 1712](https://github.com/shakacode/react_on_rails/pull/1712) by [AbanoubGhadban](https://github.com/AbanoubGhadban).
33
+
26
34
### [15.0.0-alpha.2] - 2025-03-07
27
35
28
36
See [Release Notes](docs/release-notes/15.0.0.md) for full details.
Copy file name to clipboardExpand all lines: docs/release-notes/15.0.0.md
+20-2Lines changed: 20 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,15 +21,27 @@ Major improvements to component and store hydration:
21
21
- Can use `async` scripts in the page with no fear of race condition
22
22
- No need to use `defer` anymore
23
23
24
+
### Enhanced Script Loading Strategies
25
+
26
+
- New configuration option `generated_component_packs_loading_strategy` replaces `defer_generated_component_packs`
27
+
- Supports three loading strategies:
28
+
-`:async` - Loads scripts asynchronously (default for Shakapacker ≥ 8.2.0)
29
+
-`:defer` - Defers script execution until after page load (doesn't work well with Streamed HTML as it will wait for the full page load before hydrating the components)
30
+
-`:sync` - Loads scripts synchronously (default for Shakapacker < 8.2.0) (better to upgrade to Shakapacker 8.2.0 and use `:async` strategy)
31
+
- Improves page performance by optimizing how component packs are loaded
32
+
24
33
## Breaking Changes
25
34
26
35
### Component Hydration Changes
27
36
28
-
- The `defer_generated_component_packs` and `force_load` configurations now default to `false` and `true` respectively. This means components will hydrate early without waiting for the full page load. This improves performance by eliminating unnecessary delays in hydration.
37
+
- The `defer_generated_component_packs` configuration has been deprecated. Use `generated_component_packs_loading_strategy` instead.
38
+
- The `generated_component_packs_loading_strategy` defaults to `:async` for Shakapacker ≥ 8.2.0 and `:sync` for Shakapacker < 8.2.0.
39
+
- The `force_load` configuration now defaults to `true`.
40
+
- The new default values of `generated_component_packs_loading_strategy: :async` and `force_load: true` work together to optimize component hydration. Components now hydrate as soon as their code and server-rendered HTML are available, without waiting for the full page to load. This parallel processing significantly improves time-to-interactive by eliminating the traditional waterfall of waiting for page load before beginning hydration (It's critical for streamed HTML).
29
41
30
42
- The previous need for deferring scripts to prevent race conditions has been eliminated due to improved hydration handling. Making scripts not defer is critical to execute the hydration scripts early before the page is fully loaded.
31
43
- The `force_load` configuration makes `react-on-rails` hydrate components immediately as soon as their server-rendered HTML reaches the client, without waiting for the full page load.
32
-
- If you want to keep the previous behavior, you can set `defer_generated_component_packs: true` or `force_load: false` in your `config/initializers/react_on_rails.rb` file.
44
+
- If you want to keep the previous behavior, you can set `generated_component_packs_loading_strategy: :defer` or `force_load: false` in your `config/initializers/react_on_rails.rb` file.
33
45
- You can also keep it for individual components by passing `force_load: false` to `react_component` or `stream_react_component`.
34
46
- Redux store now supports `force_load` option, which defaults to `config.force_load` (and so to `true` if that isn't set). If `true`, the Redux store will hydrate immediately as soon as its server-side data reaches the client.
35
47
- You can override this behavior for individual Redux stores by calling the `redux_store` helper with `force_load: false`, same as `react_component`.
@@ -50,6 +62,12 @@ Major improvements to component and store hydration:
50
62
51
63
- If you call it in a `turbolinks:load` listener to work around the issue documented in [Turbolinks](https://www.shakacode.com/react-on-rails/docs/rails/turbolinks/#async-script-loading), the listener can be safely removed.
52
64
65
+
### Script Loading Strategy Migration
66
+
67
+
- If you were previously using `defer_generated_component_packs: true`, use `generated_component_packs_loading_strategy: :defer` instead
68
+
- If you were previously using `defer_generated_component_packs: false`, use `generated_component_packs_loading_strategy: :sync` instead
69
+
- For optimal performancewith Shakapacker ≥ 8.2.0, consider using `generated_component_packs_loading_strategy: :async`
70
+
53
71
## Store Dependencies for Components
54
72
55
73
When using Redux stores with multiple components, you need to explicitly declare store dependencies to optimize hydration. Here's how:
0 commit comments