Skip to content

Commit 741c423

Browse files
committed
Make Pro always use immediate hydration
Simplifies immediate_hydration to be automatic based on Pro availability: - Pro users: Always get immediate hydration - Non-Pro users: Never get immediate hydration - Can still be explicitly overridden via method parameter Changes ProUtils to provide immediate_hydration_enabled? method that returns true for Pro, false for non-Pro. Updates helper.rb, controller.rb, and render_options.rb to use this method instead of checking configuration.
1 parent cd19364 commit 741c423

File tree

4 files changed

+14
-27
lines changed

4 files changed

+14
-27
lines changed

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/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_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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ def logging_on_server
9797
end
9898

9999
def immediate_hydration
100-
retrieve_configuration_value_for(:immediate_hydration)
100+
options.fetch(:immediate_hydration) do
101+
ReactOnRails::ProUtils.immediate_hydration_enabled?
102+
end
101103
end
102104

103105
def to_s

0 commit comments

Comments
 (0)