Skip to content

Commit 6a19cde

Browse files
justin808claude
andcommitted
Refactor immediate_hydration handling and add deprecation warnings
Address code review feedback: 1. Extract duplicated warning message to shared utility method - Add ReactOnRails::Utils.immediate_hydration_pro_license_warning helper - Replace inline warning messages in controller, helper, and render_options 2. Add deprecation warning for config.immediate_hydration - Add getter/setter methods that log deprecation warnings - Direct users to remove the deprecated config from initializers - Maintains backward compatibility while guiding migration 3. Fix inconsistent nil handling in render_options.rb - Simplify immediate_hydration method logic - Use consistent pattern: explicit value first, then default to Pro status - Remove confusing mix of hash access methods All changes maintain backward compatibility while improving code maintainability and providing better user guidance. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 5b0f1f7 commit 6a19cde

File tree

5 files changed

+34
-18
lines changed

5 files changed

+34
-18
lines changed

lib/react_on_rails/configuration.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,26 @@ class Configuration
6666
:component_registry_timeout,
6767
:server_bundle_output_path, :enforce_private_server_bundles
6868

69+
# Deprecated: immediate_hydration configuration has been removed
70+
def immediate_hydration=(value)
71+
Rails.logger.warn <<~WARNING
72+
[REACT ON RAILS] The 'config.immediate_hydration' configuration option is deprecated and no longer used.
73+
Immediate hydration is now automatically enabled for React on Rails Pro users.
74+
Please remove 'config.immediate_hydration = #{value}' from your config/initializers/react_on_rails.rb file.
75+
See CHANGELOG.md for migration instructions.
76+
WARNING
77+
end
78+
79+
def immediate_hydration
80+
Rails.logger.warn <<~WARNING
81+
[REACT ON RAILS] The 'config.immediate_hydration' configuration option is deprecated and no longer used.
82+
Immediate hydration is now automatically enabled for React on Rails Pro users.
83+
Please remove any references to 'config.immediate_hydration' from your config/initializers/react_on_rails.rb file.
84+
See CHANGELOG.md for migration instructions.
85+
WARNING
86+
nil
87+
end
88+
6989
# rubocop:disable Metrics/AbcSize
7090
def initialize(node_modules_location: nil, server_bundle_js_file: nil, prerender: nil,
7191
replay_console: nil, make_generated_server_bundle_the_entrypoint: nil,

lib/react_on_rails/controller.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@ module Controller
1717
def redux_store(store_name, props: {}, immediate_hydration: nil)
1818
# If non-Pro user explicitly sets immediate_hydration: true, warn and override to false
1919
if immediate_hydration == true && !ReactOnRails::Utils.react_on_rails_pro?
20-
Rails.logger.warn <<~WARNING
21-
[REACT ON RAILS] Warning: immediate_hydration: true requires a React on Rails Pro license.
22-
Store '#{store_name}' will fall back to standard hydration behavior.
23-
Visit https://www.shakacode.com/react-on-rails-pro/ for licensing information.
24-
WARNING
20+
Rails.logger.warn ReactOnRails::Utils.immediate_hydration_pro_license_warning(store_name, "Store")
2521
immediate_hydration = false
2622
elsif immediate_hydration.nil?
2723
immediate_hydration = ReactOnRails::Utils.react_on_rails_pro?

lib/react_on_rails/helper.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,7 @@ def react_component_hash(component_name, options = {})
160160
def redux_store(store_name, props: {}, defer: false, immediate_hydration: nil)
161161
# If non-Pro user explicitly sets immediate_hydration: true, warn and override to false
162162
if immediate_hydration == true && !ReactOnRails::Utils.react_on_rails_pro?
163-
Rails.logger.warn <<~WARNING
164-
[REACT ON RAILS] Warning: immediate_hydration: true requires a React on Rails Pro license.
165-
Store '#{store_name}' will fall back to standard hydration behavior.
166-
Visit https://www.shakacode.com/react-on-rails-pro/ for licensing information.
167-
WARNING
163+
Rails.logger.warn ReactOnRails::Utils.immediate_hydration_pro_license_warning(store_name, "Store")
168164
immediate_hydration = false
169165
elsif immediate_hydration.nil?
170166
immediate_hydration = ReactOnRails::Utils.react_on_rails_pro?

lib/react_on_rails/react_component/render_options.rb

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,15 @@ def immediate_hydration
100100

101101
# If non-Pro user explicitly sets immediate_hydration: true, warn and override to false
102102
if explicit_value == true && !ReactOnRails::Utils.react_on_rails_pro?
103-
Rails.logger.warn <<~WARNING
104-
[REACT ON RAILS] Warning: immediate_hydration: true requires a React on Rails Pro license.
105-
Component '#{react_component_name}' will fall back to standard hydration behavior.
106-
Visit https://www.shakacode.com/react-on-rails-pro/ for licensing information.
107-
WARNING
103+
warning = ReactOnRails::Utils.immediate_hydration_pro_license_warning(react_component_name, "Component")
104+
Rails.logger.warn warning
108105
return false # Force fallback to standard hydration
109106
end
110107

111-
options.fetch(:immediate_hydration) do
112-
ReactOnRails::Utils.react_on_rails_pro?
113-
end
108+
# Return explicit value if provided, otherwise default based on Pro license
109+
return explicit_value unless explicit_value.nil?
110+
111+
ReactOnRails::Utils.react_on_rails_pro?
114112
end
115113

116114
def to_s

lib/react_on_rails/utils.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ module Utils
1414
Rainbow('To see the full output, set FULL_TEXT_ERRORS=true.').red
1515
} ...\n".freeze
1616

17+
def self.immediate_hydration_pro_license_warning(name, type = "Component")
18+
"[REACT ON RAILS] Warning: immediate_hydration: true requires a React on Rails Pro license.\n" \
19+
"#{type} '#{name}' will fall back to standard hydration behavior.\n" \
20+
"Visit https://www.shakacode.com/react-on-rails-pro/ for licensing information."
21+
end
22+
1723
# https://forum.shakacode.com/t/yak-of-the-week-ruby-2-4-pathname-empty-changed-to-look-at-file-size/901
1824
# return object if truthy, else return nil
1925
def self.truthy_presence(obj)

0 commit comments

Comments
 (0)