Skip to content

Commit 27c7033

Browse files
committed
simplify logic
1 parent 233d9a6 commit 27c7033

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

lib/react_on_rails/configuration.rb

+23-20
Original file line numberDiff line numberDiff line change
@@ -154,32 +154,35 @@ def check_component_registry_timeout
154154
raise ReactOnRails::Error, "component_registry_timeout must be a positive integer"
155155
end
156156

157-
# rubocop:disable Metrics/CyclomaticComplexity
157+
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
158158
def validate_generated_component_packs_loading_strategy
159-
# rubocop:enable Metrics/CyclomaticComplexity
159+
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
160+
161+
if defer_generated_component_packs
162+
if %i[async sync].include?(generated_component_packs_loading_strategy)
163+
Rails.logger.warn "**WARNING** ReactOnRails: config.defer_generated_component_packs is " \
164+
"superseded by config.generated_component_packs_loading_strategy"
165+
else
166+
Rails.logger.warn "[DEPRECATION] ReactOnRails: Use config." \
167+
"generated_component_packs_loading_strategy = :defer rather than " \
168+
"defer_generated_component_packs"
169+
self.generated_component_packs_loading_strategy ||= :defer
170+
end
171+
end
172+
173+
msg = <<~MSG
174+
ReactOnRails: Your current version of #{ReactOnRails::PackerUtils.packer_type.upcase_first} \
175+
does not support async script loading, which may cause performance issues. Please either:
176+
1. Use :sync or :defer loading strategy instead of :async
177+
2. Upgrade to Shakapacker v8.2.0 or above to enable async script loading
178+
MSG
160179
if PackerUtils.shakapacker_version_requirement_met?([8, 2, 0])
161180
self.generated_component_packs_loading_strategy ||= :async
162-
elsif defer_generated_component_packs
163-
generated_component_packs_loading_strategy ||= :defer
164-
Rails.logger.warn "[DEPRECATION] ReactOnRails: Use config." \
165-
"generated_component_packs_loading_strategy = :defer rather than " \
166-
"defer_generated_component_packs"
167181
elsif generated_component_packs_loading_strategy.nil?
168-
msg = <<~MSG
169-
**WARNING** ReactOnRails: Your current version of #{ReactOnRails::PackerUtils.packer_type.upcase_first} \
170-
does not support async script loading which may cause performance issues. Please upgrade to Shakapacker v8.2.0 \
171-
or above to enable async script loading for better performance.
172-
MSG
173-
Rails.logger.warn(msg)
182+
Rails.logger.warn("**WARNING** #{msg}")
174183
self.generated_component_packs_loading_strategy = :sync
175184
elsif generated_component_packs_loading_strategy == :async
176-
msg = <<~MSG
177-
**ERROR** ReactOnRails: Your current version of #{ReactOnRails::PackerUtils.packer_type.upcase_first} \
178-
does not support async script loading. Please either:
179-
1. Use :sync or :defer loading strategy instead of :async
180-
2. Upgrade to Shakapacker v8.2.0 or above to enable async script loading
181-
MSG
182-
raise ReactOnRails::Error, msg
185+
raise ReactOnRails::Error, "**ERROR** #{msg}"
183186
end
184187

185188
return if %i[async defer sync].include?(generated_component_packs_loading_strategy)

0 commit comments

Comments
 (0)