Skip to content

Commit 81bb42a

Browse files
AbanoubGhadbanjustin808
authored andcommitted
Remove immediate_hydration config - Pro always hydrates immediately (#1997)
Why Simplify configuration for pro users. Still allows override at react_component level. Summary Removed visual warning badges for Pro features, made immediate hydration automatic for Pro users, and removed global config option. Key improvements - Automatic immediate hydration for Pro users (no config needed) - Rails logger warnings replace visual badges for better UX - Component-level overrides still supported via helper parameters Impact - Existing: Pro users unchanged; immediate hydration auto-enabled - New: Simpler config; non-Pro get warnings in logs, not UI Risks Breaking: config.immediate_hydration removed from initializers (see CHANGELOG migration steps). Security: None.
1 parent 117fb1f commit 81bb42a

File tree

12 files changed

+130
-59
lines changed

12 files changed

+130
-59
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,26 @@ Changes since the last non-beta release.
5151

5252
- **Removed Pro Warning Badge**: Removed the visual warning badge that appeared when non-Pro users attempted to enable Pro-only features like `immediate_hydration`. Pro features are now silently disabled when a Pro license is not available, providing a cleaner user experience without intrusive warning banners. [PR 1993](https://github.com/shakacode/react_on_rails/pull/1993) by [AbanoubGhadban](https://github.com/AbanoubGhadban).
5353

54+
- **`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).
55+
5456
#### Bug Fixes
5557

5658
- **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).
5759

5860
#### Breaking Changes
5961

62+
- **`config.immediate_hydration` configuration removed**: The `config.immediate_hydration` setting in `config/initializers/react_on_rails.rb` has been removed. Immediate hydration is now automatically enabled for React on Rails Pro users and automatically disabled for non-Pro users.
63+
64+
**Migration steps:**
65+
66+
- Remove any `config.immediate_hydration = true` or `config.immediate_hydration = false` lines from your `config/initializers/react_on_rails.rb` file
67+
- Pro users: No action needed - immediate hydration is now enabled automatically for optimal performance
68+
- Non-Pro users: No action needed - standard hydration behavior continues to work as before
69+
- Component-level overrides: You can still override behavior per-component using `react_component("MyComponent", immediate_hydration: false)` or `redux_store("MyStore", immediate_hydration: true)`
70+
- If a non-Pro user explicitly sets `immediate_hydration: true` on a component, a warning will be logged and the component will fall back to standard hydration
71+
72+
[PR 1997](https://github.com/shakacode/react_on_rails/pull/1997) by [AbanoubGhadban](https://github.com/AbanoubGhadban).
73+
6074
- **React on Rails Core Package**: Several Pro-only methods have been removed from the core package and are now exclusively available in the `react-on-rails-pro` package. If you're using any of the following methods, you'll need to migrate to React on Rails Pro:
6175
- `getOrWaitForComponent()`
6276
- `getOrWaitForStore()`

lib/react_on_rails/configuration.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ def self.configuration
4141
components_subdirectory: nil,
4242
make_generated_server_bundle_the_entrypoint: false,
4343
defer_generated_component_packs: false,
44-
# React on Rails Pro (licensed) feature - enables immediate hydration of React components
45-
immediate_hydration: false,
4644
# Maximum time in milliseconds to wait for client-side component registration after page load.
4745
# If exceeded, an error will be thrown for server-side rendered components not registered on the client.
4846
# Set to 0 to disable the timeout and wait indefinitely for component registration.
@@ -64,7 +62,7 @@ class Configuration
6462
:server_render_method, :random_dom_id, :auto_load_bundle,
6563
:same_bundle_for_client_and_server, :rendering_props_extension,
6664
:make_generated_server_bundle_the_entrypoint,
67-
:generated_component_packs_loading_strategy, :immediate_hydration,
65+
:generated_component_packs_loading_strategy,
6866
:component_registry_timeout,
6967
:server_bundle_output_path, :enforce_private_server_bundles
7068

@@ -81,7 +79,7 @@ def initialize(node_modules_location: nil, server_bundle_js_file: nil, prerender
8179
same_bundle_for_client_and_server: nil,
8280
i18n_dir: nil, i18n_yml_dir: nil, i18n_output_format: nil, i18n_yml_safe_load_options: nil,
8381
random_dom_id: nil, server_render_method: nil, rendering_props_extension: nil,
84-
components_subdirectory: nil, auto_load_bundle: nil, immediate_hydration: nil,
82+
components_subdirectory: nil, auto_load_bundle: nil,
8583
component_registry_timeout: nil, server_bundle_output_path: nil, enforce_private_server_bundles: nil)
8684
self.node_modules_location = node_modules_location.present? ? node_modules_location : Rails.root
8785
self.generated_assets_dirs = generated_assets_dirs
@@ -122,7 +120,6 @@ def initialize(node_modules_location: nil, server_bundle_js_file: nil, prerender
122120
self.auto_load_bundle = auto_load_bundle
123121
self.make_generated_server_bundle_the_entrypoint = make_generated_server_bundle_the_entrypoint
124122
self.defer_generated_component_packs = defer_generated_component_packs
125-
self.immediate_hydration = immediate_hydration
126123
self.generated_component_packs_loading_strategy = generated_component_packs_loading_strategy
127124
self.server_bundle_output_path = server_bundle_output_path
128125
self.enforce_private_server_bundles = enforce_private_server_bundles

lib/react_on_rails/controller.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ module Controller
99
# JavaScript code.
1010
# props: Named parameter props which is a Ruby Hash or JSON string which contains the properties
1111
# to pass to the redux store.
12-
# immediate_hydration: React on Rails Pro (licensed) feature. Pass as true if you wish to hydrate this
13-
# store immediately instead of waiting for the page to load.
12+
# immediate_hydration: React on Rails Pro (licensed) feature. When nil (default), Pro users get
13+
# immediate hydration, non-Pro users don't. Can be explicitly overridden.
1414
#
1515
# Be sure to include view helper `redux_store_hydration_data` at the end of your layout or view
1616
# or else there will be no client side hydration of your stores.
1717
def redux_store(store_name, props: {}, immediate_hydration: nil)
18-
immediate_hydration = ReactOnRails.configuration.immediate_hydration if immediate_hydration.nil?
18+
immediate_hydration = ReactOnRails::ProUtils.immediate_hydration_enabled? if immediate_hydration.nil?
1919
redux_store_data = { store_name: store_name,
2020
props: props,
2121
immediate_hydration: immediate_hydration }

lib/react_on_rails/doctor.rb

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ def analyze_server_rendering_config(content)
701701
end
702702
# rubocop:enable Metrics/AbcSize
703703

704-
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
704+
# rubocop:disable Metrics/CyclomaticComplexity
705705
def analyze_performance_config(content)
706706
checker.add_info("\n⚡ Performance & Loading:")
707707

@@ -732,19 +732,13 @@ def analyze_performance_config(content)
732732
auto_load_match = content.match(/config\.auto_load_bundle\s*=\s*([^\s\n,]+)/)
733733
checker.add_info(" auto_load_bundle: #{auto_load_match[1]}") if auto_load_match
734734

735-
# Immediate hydration (Pro feature)
736-
immediate_hydration_match = content.match(/config\.immediate_hydration\s*=\s*([^\s\n,]+)/)
737-
if immediate_hydration_match
738-
checker.add_info(" immediate_hydration: #{immediate_hydration_match[1]} (React on Rails Pro)")
739-
end
740-
741735
# Component registry timeout
742736
timeout_match = content.match(/config\.component_registry_timeout\s*=\s*([^\s\n,]+)/)
743737
return unless timeout_match
744738

745739
checker.add_info(" component_registry_timeout: #{timeout_match[1]}ms")
746740
end
747-
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity
741+
# rubocop:enable Metrics/CyclomaticComplexity
748742

749743
# rubocop:disable Metrics/AbcSize
750744
def analyze_development_config(content)

lib/react_on_rails/helper.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,10 @@ def react_component_hash(component_name, options = {})
155155
# props: Ruby Hash or JSON string which contains the properties to pass to the redux store.
156156
# Options
157157
# defer: false -- pass as true if you wish to render this below your component.
158-
# immediate_hydration: false -- React on Rails Pro (licensed) feature. Pass as true if you wish to
159-
# hydrate this store immediately instead of waiting for the page to load.
158+
# immediate_hydration: nil -- React on Rails Pro (licensed) feature. When nil (default), Pro users
159+
# get immediate hydration, non-Pro users don't. Can be explicitly overridden.
160160
def redux_store(store_name, props: {}, defer: false, immediate_hydration: nil)
161-
immediate_hydration = ReactOnRails.configuration.immediate_hydration if immediate_hydration.nil?
161+
immediate_hydration = ReactOnRails::ProUtils.immediate_hydration_enabled? if immediate_hydration.nil?
162162

163163
redux_store_data = { store_name: store_name,
164164
props: props,

lib/react_on_rails/pro_helper.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ def generate_component_script(render_options)
3838
# Generates the complete store hydration script tag.
3939
# Handles both immediate hydration (Pro feature) and standard cases.
4040
def generate_store_script(redux_store_data)
41-
redux_store_data = ReactOnRails::ProUtils.disable_pro_render_options_if_not_licensed(redux_store_data)
42-
4341
store_hydration_data = content_tag(:script,
4442
json_safe_and_pretty(redux_store_data[:props]).html_safe,
4543
type: "application/json",

lib/react_on_rails/pro_utils.rb

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,17 @@
22

33
module ReactOnRails
44
module ProUtils
5-
PRO_ONLY_OPTIONS = %i[immediate_hydration].freeze
6-
75
# Checks if React on Rails Pro features are available
86
# @return [Boolean] true if Pro is installed and licensed, false otherwise
97
def self.support_pro_features?
108
ReactOnRails::Utils.react_on_rails_pro?
119
end
1210

13-
def self.disable_pro_render_options_if_not_licensed(raw_options)
14-
return raw_options if support_pro_features?
15-
16-
raw_options_after_disable = raw_options.dup
17-
18-
PRO_ONLY_OPTIONS.each do |option|
19-
# Determine if this option is enabled (either explicitly or via global config)
20-
option_enabled = if raw_options[option].nil?
21-
ReactOnRails.configuration.send(option)
22-
else
23-
raw_options[option]
24-
end
25-
26-
# Silently disable the option if it's enabled but Pro is not available
27-
raw_options_after_disable[option] = false if option_enabled
28-
end
29-
30-
raw_options_after_disable
11+
# Returns whether immediate hydration should be enabled
12+
# Pro users always get immediate hydration, non-Pro users never do
13+
# @return [Boolean] true if Pro is available, false otherwise
14+
def self.immediate_hydration_enabled?
15+
support_pro_features?
3116
end
3217
end
3318
end

lib/react_on_rails/react_component/render_options.rb

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class RenderOptions
1515
# TODO: remove the required for named params
1616
def initialize(react_component_name: required("react_component_name"), options: required("options"))
1717
@react_component_name = react_component_name.camelize
18-
@options = ReactOnRails::ProUtils.disable_pro_render_options_if_not_licensed(options)
18+
@options = options
1919
end
2020

2121
attr_reader :react_component_name
@@ -97,7 +97,20 @@ def logging_on_server
9797
end
9898

9999
def immediate_hydration
100-
retrieve_configuration_value_for(:immediate_hydration)
100+
explicit_value = options[:immediate_hydration]
101+
102+
# Warn if non-Pro user explicitly sets immediate_hydration: true
103+
if explicit_value == true && !ReactOnRails::Utils.react_on_rails_pro?
104+
Rails.logger.warn <<~WARNING
105+
[REACT ON RAILS] Warning: immediate_hydration: true requires a React on Rails Pro license.
106+
Component '#{react_component_name}' will fall back to standard hydration behavior.
107+
Visit https://www.shakacode.com/react-on-rails-pro/ for licensing information.
108+
WARNING
109+
end
110+
111+
options.fetch(:immediate_hydration) do
112+
ReactOnRails::ProUtils.immediate_hydration_enabled?
113+
end
101114
end
102115

103116
def to_s

spec/dummy/config/initializers/react_on_rails.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,5 @@ def self.adjust_props_for_client_side_hydration(component_name, props)
4141
config.rendering_props_extension = RenderingPropsExtension
4242
config.components_subdirectory = "startup"
4343
config.auto_load_bundle = true
44-
config.immediate_hydration = false
4544
config.generated_component_packs_loading_strategy = :defer
4645
end

spec/dummy/spec/helpers/react_on_rails_helper_spec.rb

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,8 @@ def self.pro_attribution_comment
3838
stub_const("ReactOnRailsPro", pro_module)
3939
stub_const("ReactOnRailsPro::Utils", utils_module)
4040

41-
# Configure immediate_hydration to true for tests since they expect that behavior
42-
ReactOnRails.configure do |config|
43-
config.immediate_hydration = true
44-
end
45-
end
46-
47-
after do
48-
# Reset to default - avoid validation issues by setting directly
49-
ReactOnRails.configuration.immediate_hydration = false
41+
# Stub immediate_hydration_enabled? to return true for tests since they expect that behavior
42+
allow(ReactOnRails::ProUtils).to receive(:immediate_hydration_enabled?).and_return(true)
5043
end
5144

5245
let(:hash) do

0 commit comments

Comments
 (0)