@@ -18,9 +18,28 @@ class Engine < ::Rails::Engine
1818 end
1919
2020 # Determine if version validation should be skipped
21+ #
22+ # This method checks multiple conditions to determine if package version validation
23+ # should be skipped. Validation is skipped during setup scenarios where the npm
24+ # package isn't installed yet (e.g., during generator execution).
25+ #
2126 # @return [Boolean] true if validation should be skipped
27+ #
28+ # @note Thread Safety: ENV variables are process-global. In practice, Rails generators
29+ # run in a single process, so concurrent execution is not a concern. If running
30+ # generators concurrently (e.g., in parallel tests), ensure tests run in separate
31+ # processes to avoid ENV variable conflicts.
32+ #
33+ # @note Manual ENV Setting: While this ENV variable is designed to be set by generators,
34+ # users can manually set it (e.g., `REACT_ON_RAILS_SKIP_VALIDATION=true rails server`)
35+ # to bypass validation. This should only be done temporarily during debugging or
36+ # setup scenarios. The validation helps catch version mismatches early, so bypassing
37+ # it in production is not recommended.
2238 def self . skip_version_validation?
2339 # Skip if explicitly disabled via environment variable (set by generators)
40+ # Using ENV variable instead of ARGV because Rails can modify/clear ARGV during
41+ # initialization, making ARGV unreliable for detecting generator context. The ENV
42+ # variable persists through the entire Rails initialization process.
2443 if ENV [ "REACT_ON_RAILS_SKIP_VALIDATION" ] == "true"
2544 Rails . logger . debug "[React on Rails] Skipping validation - disabled via environment variable"
2645 return true
@@ -33,6 +52,7 @@ def self.skip_version_validation?
3352 end
3453
3554 # Skip during generator runtime since packages are installed during execution
55+ # This is a fallback check in case ENV wasn't set, though ENV is the primary mechanism
3656 if running_generator?
3757 Rails . logger . debug "[React on Rails] Skipping validation during generator runtime"
3858 return true
0 commit comments