Skip to content

Commit e36b220

Browse files
justin808claude
andcommitted
Inline immediate_hydration_enabled? method
Remove the intermediate immediate_hydration_enabled? helper method from ProUtils and directly use ReactOnRails::Utils.react_on_rails_pro? instead. This simplifies the code by removing an unnecessary layer of indirection. The immediate_hydration_enabled? method was just a wrapper that called support_pro_features?, which itself just calls react_on_rails_pro?. Changes: - Remove immediate_hydration_enabled? method from ProUtils - Update all callers to use ReactOnRails::Utils.react_on_rails_pro? directly: - render_options.rb: immediate_hydration method - helper.rb: redux_store method - controller.rb: redux_store method - Update test mocks to stub react_on_rails_pro? instead of immediate_hydration_enabled? - Remove unnecessary test stubs in render_options_spec.rb 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 6b69abd commit e36b220

File tree

7 files changed

+7
-16
lines changed

7 files changed

+7
-16
lines changed

lib/react_on_rails/controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module Controller
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::ProUtils.immediate_hydration_enabled? if immediate_hydration.nil?
18+
immediate_hydration = ReactOnRails::Utils.react_on_rails_pro? 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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def react_component_hash(component_name, options = {})
158158
# immediate_hydration: nil -- React on Rails Pro (licensed) feature. When nil (default), Pro users
159159
# 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::ProUtils.immediate_hydration_enabled? if immediate_hydration.nil?
161+
immediate_hydration = ReactOnRails::Utils.react_on_rails_pro? 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: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,5 @@ module ProUtils
77
def self.support_pro_features?
88
ReactOnRails::Utils.react_on_rails_pro?
99
end
10-
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?
16-
end
1710
end
1811
end

lib/react_on_rails/react_component/render_options.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def immediate_hydration
109109
end
110110

111111
options.fetch(:immediate_hydration) do
112-
ReactOnRails::ProUtils.immediate_hydration_enabled?
112+
ReactOnRails::Utils.react_on_rails_pro?
113113
end
114114
end
115115

spec/dummy/spec/helpers/react_on_rails_helper_spec.rb

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

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)
41+
# Stub react_on_rails_pro? to return true for tests since they expect that behavior
42+
allow(ReactOnRails::Utils).to receive(:react_on_rails_pro?).and_return(true)
4343
end
4444

4545
let(:hash) do

spec/dummy/spec/system/integration_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ def self.pro_attribution_comment
105105
stub_const("ReactOnRailsPro", pro_module)
106106
stub_const("ReactOnRailsPro::Utils", utils_module)
107107

108-
# Stub immediate_hydration_enabled? to return true for tests since they expect that behavior
109-
allow(ReactOnRails::ProUtils).to receive(:immediate_hydration_enabled?).and_return(true)
108+
# Stub react_on_rails_pro? to return true for tests since they expect that behavior
109+
allow(ReactOnRails::Utils).to receive(:react_on_rails_pro?).and_return(true)
110110
end
111111
end
112112

spec/react_on_rails/react_component/render_options_spec.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ def the_attrs(react_component_name: "App", options: {})
194194

195195
context "without immediate_hydration option" do
196196
it "returns true (Pro default)" do
197-
allow(ReactOnRails::ProUtils).to receive(:immediate_hydration_enabled?).and_return(true)
198197
attrs = the_attrs
199198

200199
opts = described_class.new(**attrs)
@@ -235,7 +234,6 @@ def the_attrs(react_component_name: "App", options: {})
235234

236235
context "without immediate_hydration option" do
237236
it "returns false (non-Pro default)" do
238-
allow(ReactOnRails::ProUtils).to receive(:immediate_hydration_enabled?).and_return(false)
239237
attrs = the_attrs
240238

241239
opts = described_class.new(**attrs)

0 commit comments

Comments
 (0)