Skip to content

Commit 958fb97

Browse files
justin808claude
andcommitted
Remove immediate_hydration validation (will be handled in PR 1997)
Focus this PR solely on validating that :async loading strategy requires Pro. immediate_hydration will be completely removed in PR 1997, so no need to validate it here. Changes: - Remove immediate_hydration from Pro-only feature validation - Simplify validate_pro_only_features to only check :async loading strategy - Remove immediate_hydration checks from doctor.rb - Update tests to only test :async Pro validation - Simplify error messages to focus on :async requirement 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent d465d5f commit 958fb97

File tree

4 files changed

+20
-144
lines changed

4 files changed

+20
-144
lines changed

lib/react_on_rails/configuration.rb

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -150,26 +150,18 @@ def setup_config_values
150150
def validate_pro_only_features
151151
return if defined?(ReactOnRailsPro)
152152

153-
pro_only_features = []
154-
155-
pro_only_features << "config.immediate_hydration = true" if immediate_hydration == true
156-
157153
# generated_component_packs_loading_strategy itself is NOT Pro-only
158154
# However, :async loading specifically requires React on Rails Pro
159-
if generated_component_packs_loading_strategy == :async
160-
pro_only_features << "config.generated_component_packs_loading_strategy = :async"
161-
end
162-
163-
return if pro_only_features.empty?
155+
return unless generated_component_packs_loading_strategy == :async
164156

165157
msg = <<~MSG
166-
**ERROR** ReactOnRails: You are using Pro-only features without React on Rails Pro:
158+
**ERROR** ReactOnRails: You are using a Pro-only feature without React on Rails Pro:
167159
168-
#{pro_only_features.map { |f| " - #{f}" }.join("\n")}
160+
- config.generated_component_packs_loading_strategy = :async
169161
170-
These features are only available with a React on Rails Pro license.
162+
Async loading is only available with a React on Rails Pro license.
171163
Please either:
172-
1. Remove these settings from your config/initializers/react_on_rails.rb
164+
1. Change to :defer or :sync loading strategy in your config/initializers/react_on_rails.rb
173165
2. Purchase a React on Rails Pro license at https://www.shakacode.com/react-on-rails-pro
174166
175167
For more information, see: https://www.shakacode.com/react-on-rails/docs/

lib/react_on_rails/doctor.rb

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,7 +1146,6 @@ def safe_display_config_value(label, config, method_name)
11461146
end
11471147
end
11481148

1149-
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
11501149
def check_async_usage
11511150
# When Pro is installed, async is fully supported and is the default behavior
11521151
# No need to check for async usage in this case
@@ -1171,24 +1170,13 @@ def check_async_usage
11711170
return if async_issues.empty?
11721171

11731172
# Report errors if async usage is found without Pro
1174-
# Note: immediate_hydration alone is not sufficient - Pro is required for safe async usage
1175-
immediate_hydration_enabled = check_immediate_hydration_enabled?
1176-
1177-
if immediate_hydration_enabled
1178-
checker.add_warning("⚠️ Using :async without React on Rails Pro may cause race conditions")
1179-
async_issues.each { |issue| checker.add_warning(" #{issue}") }
1180-
checker.add_info(" 💡 immediate_hydration is enabled but Pro gem is not installed")
1181-
checker.add_info(" 💡 For production-safe async loading, upgrade to React on Rails Pro")
1182-
else
1183-
checker.add_error("🚫 :async usage detected without proper configuration")
1184-
async_issues.each { |issue| checker.add_error(" #{issue}") }
1185-
checker.add_info(" 💡 :async can cause race conditions. Options:")
1186-
checker.add_info(" 1. Upgrade to React on Rails Pro (recommended for :async support)")
1187-
checker.add_info(" 2. Change to :defer or :sync loading strategy")
1188-
checker.add_info(" 📖 https://www.shakacode.com/react-on-rails/docs/guides/configuration/")
1189-
end
1173+
checker.add_error("🚫 :async usage detected without React on Rails Pro")
1174+
async_issues.each { |issue| checker.add_error(" #{issue}") }
1175+
checker.add_info(" 💡 :async can cause race conditions. Options:")
1176+
checker.add_info(" 1. Upgrade to React on Rails Pro (recommended for :async support)")
1177+
checker.add_info(" 2. Change to :defer or :sync loading strategy")
1178+
checker.add_info(" 📖 https://www.shakacode.com/react-on-rails/docs/guides/configuration/")
11901179
end
1191-
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity
11921180

11931181
def scan_view_files_for_async_pack_tag
11941182
files_with_async = []
@@ -1223,16 +1211,6 @@ def config_has_async_loading_strategy?
12231211
rescue StandardError
12241212
false
12251213
end
1226-
1227-
def check_immediate_hydration_enabled?
1228-
# Check if immediate_hydration is enabled in configuration
1229-
return false unless defined?(ReactOnRails)
1230-
1231-
config = ReactOnRails.configuration
1232-
config.immediate_hydration == true
1233-
rescue StandardError
1234-
false
1235-
end
12361214
end
12371215
# rubocop:enable Metrics/ClassLength
12381216
end

spec/lib/react_on_rails/doctor_spec.rb

Lines changed: 4 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,13 @@
224224
allow(File).to receive(:read).with("app/views/layouts/application.html.erb")
225225
.and_return('<%= javascript_pack_tag "application", :async %>')
226226
allow(File).to receive(:exist?).with("config/initializers/react_on_rails.rb").and_return(false)
227-
allow(doctor).to receive_messages(relativize_path: "app/views/layouts/application.html.erb",
228-
check_immediate_hydration_enabled?: false)
227+
allow(doctor).to receive(:relativize_path).with("app/views/layouts/application.html.erb")
228+
.and_return("app/views/layouts/application.html.erb")
229229
end
230230

231231
it "reports an error" do
232232
doctor.send(:check_async_usage)
233-
expect(checker).to have_received(:add_error).with("🚫 :async usage detected without proper configuration")
233+
expect(checker).to have_received(:add_error).with("🚫 :async usage detected without React on Rails Pro")
234234
expect(checker).to have_received(:add_error)
235235
.with(" javascript_pack_tag with :async found in view files:")
236236
end
@@ -241,39 +241,21 @@
241241
allow(File).to receive(:exist?).with("config/initializers/react_on_rails.rb").and_return(true)
242242
allow(File).to receive(:read).with("config/initializers/react_on_rails.rb")
243243
.and_return("config.generated_component_packs_loading_strategy = :async")
244-
allow(doctor).to receive(:check_immediate_hydration_enabled?).and_return(false)
245244
end
246245

247246
it "reports an error" do
248247
doctor.send(:check_async_usage)
249-
expect(checker).to have_received(:add_error).with("🚫 :async usage detected without proper configuration")
248+
expect(checker).to have_received(:add_error).with("🚫 :async usage detected without React on Rails Pro")
250249
expect(checker).to have_received(:add_error)
251250
.with(" config.generated_component_packs_loading_strategy = :async in initializer")
252251
end
253252
end
254253

255-
context "when immediate_hydration is enabled but Pro is not installed" do
256-
before do
257-
allow(File).to receive(:exist?).with("config/initializers/react_on_rails.rb").and_return(true)
258-
allow(File).to receive(:read).with("config/initializers/react_on_rails.rb")
259-
.and_return("config.generated_component_packs_loading_strategy = :async")
260-
allow(doctor).to receive(:check_immediate_hydration_enabled?).and_return(true)
261-
end
262-
263-
it "reports a warning instead of error" do
264-
doctor.send(:check_async_usage)
265-
expect(checker).to have_received(:add_warning)
266-
.with("⚠️ Using :async without React on Rails Pro may cause race conditions")
267-
expect(checker).not_to have_received(:add_error)
268-
end
269-
end
270-
271254
context "when no async usage is detected" do
272255
before do
273256
allow(File).to receive(:exist?).with("config/initializers/react_on_rails.rb").and_return(true)
274257
allow(File).to receive(:read).with("config/initializers/react_on_rails.rb")
275258
.and_return("config.generated_component_packs_loading_strategy = :defer")
276-
allow(doctor).to receive(:check_immediate_hydration_enabled?).and_return(false)
277259
end
278260

279261
it "does not report any issues" do
@@ -362,28 +344,4 @@
362344
end
363345
end
364346
end
365-
366-
describe "#check_immediate_hydration_enabled?" do
367-
context "when immediate_hydration is enabled" do
368-
before do
369-
config = instance_double(ReactOnRails::Configuration, immediate_hydration: true)
370-
allow(ReactOnRails).to receive(:configuration).and_return(config)
371-
end
372-
373-
it "returns true" do
374-
expect(doctor.send(:check_immediate_hydration_enabled?)).to be true
375-
end
376-
end
377-
378-
context "when immediate_hydration is disabled" do
379-
before do
380-
config = instance_double(ReactOnRails::Configuration, immediate_hydration: false)
381-
allow(ReactOnRails).to receive(:configuration).and_return(config)
382-
end
383-
384-
it "returns false" do
385-
expect(doctor.send(:check_immediate_hydration_enabled?)).to be false
386-
end
387-
end
388-
end
389347
end

spec/react_on_rails/configuration_spec.rb

Lines changed: 5 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ module ReactOnRails
406406
ReactOnRails.configure do |config|
407407
config.generated_component_packs_loading_strategy = :async
408408
end
409-
end.to raise_error(ReactOnRails::Error, /Pro-only features without React on Rails Pro/)
409+
end.to raise_error(ReactOnRails::Error, /Pro-only feature without React on Rails Pro/)
410410
end
411411
end
412412
end
@@ -467,7 +467,7 @@ module ReactOnRails
467467
end
468468
end
469469

470-
describe "Pro-only feature validation" do
470+
describe "Pro-only feature validation for :async loading strategy" do
471471
context "when ReactOnRailsPro is not defined" do
472472
before do
473473
# Ensure ReactOnRailsPro is not defined
@@ -476,36 +476,14 @@ module ReactOnRails
476476
allow(ReactOnRails::PackerUtils).to receive(:supports_async_loading?).and_return(true)
477477
end
478478

479-
context "when immediate_hydration is set to true" do
480-
it "raises error in non-production environments" do
481-
allow(Rails.env).to receive(:production?).and_return(false)
482-
expect do
483-
ReactOnRails.configure do |config|
484-
config.immediate_hydration = true
485-
end
486-
end.to raise_error(ReactOnRails::Error, /Pro-only features without React on Rails Pro/)
487-
end
488-
489-
it "logs error in production but does not raise" do
490-
allow(Rails.env).to receive(:production?).and_return(true)
491-
allow(Rails.logger).to receive(:error)
492-
expect do
493-
ReactOnRails.configure do |config|
494-
config.immediate_hydration = true
495-
end
496-
end.not_to raise_error
497-
expect(Rails.logger).to have_received(:error).with(/Pro-only features/)
498-
end
499-
end
500-
501479
context "when generated_component_packs_loading_strategy is set to :async" do
502480
it "raises error in non-production environments" do
503481
allow(Rails.env).to receive(:production?).and_return(false)
504482
expect do
505483
ReactOnRails.configure do |config|
506484
config.generated_component_packs_loading_strategy = :async
507485
end
508-
end.to raise_error(ReactOnRails::Error, /Pro-only features without React on Rails Pro/)
486+
end.to raise_error(ReactOnRails::Error, /Pro-only feature without React on Rails Pro/)
509487
end
510488

511489
it "logs error in production but does not raise" do
@@ -516,7 +494,7 @@ module ReactOnRails
516494
config.generated_component_packs_loading_strategy = :async
517495
end
518496
end.not_to raise_error
519-
expect(Rails.logger).to have_received(:error).with(/Pro-only features/)
497+
expect(Rails.logger).to have_received(:error).with(/Pro-only feature/)
520498
end
521499
end
522500

@@ -538,28 +516,6 @@ module ReactOnRails
538516
end
539517
end
540518

541-
context "when both Pro-only features are set" do
542-
it "lists both features in error message" do
543-
allow(Rails.env).to receive(:production?).and_return(false)
544-
expect do
545-
ReactOnRails.configure do |config|
546-
config.immediate_hydration = true
547-
config.generated_component_packs_loading_strategy = :async
548-
end
549-
end.to raise_error(ReactOnRails::Error, /immediate_hydration.*generated_component_packs_loading_strategy/m)
550-
end
551-
end
552-
553-
context "when immediate_hydration is set to false" do
554-
it "does not raise error" do
555-
expect do
556-
ReactOnRails.configure do |config|
557-
config.immediate_hydration = false
558-
end
559-
end.not_to raise_error
560-
end
561-
end
562-
563519
context "when no Pro-only features are set" do
564520
it "does not raise error" do
565521
expect do
@@ -576,15 +532,7 @@ module ReactOnRails
576532
allow(ReactOnRails::PackerUtils).to receive(:supports_async_loading?).and_return(true)
577533
end
578534

579-
it "allows immediate_hydration = true" do
580-
expect do
581-
ReactOnRails.configure do |config|
582-
config.immediate_hydration = true
583-
end
584-
end.not_to raise_error
585-
end
586-
587-
it "allows generated_component_packs_loading_strategy to be set" do
535+
it "allows generated_component_packs_loading_strategy = :async" do
588536
expect do
589537
ReactOnRails.configure do |config|
590538
config.generated_component_packs_loading_strategy = :async

0 commit comments

Comments
 (0)