diff --git a/lib/generators/react_on_rails/install_generator.rb b/lib/generators/react_on_rails/install_generator.rb index 3a7e351202..e67916aa6b 100644 --- a/lib/generators/react_on_rails/install_generator.rb +++ b/lib/generators/react_on_rails/install_generator.rb @@ -74,6 +74,9 @@ def run_generators end ensure # Always clean up ENV variable, even if generator fails + # CRITICAL: ENV cleanup must come first to ensure it executes even if + # print_generator_messages raises an exception. This prevents ENV pollution + # that could affect subsequent processes. ENV.delete("REACT_ON_RAILS_SKIP_VALIDATION") print_generator_messages end diff --git a/lib/react_on_rails/engine.rb b/lib/react_on_rails/engine.rb index a7abdd4a77..d04354c4a3 100644 --- a/lib/react_on_rails/engine.rb +++ b/lib/react_on_rails/engine.rb @@ -30,6 +30,12 @@ class Engine < ::Rails::Engine # generators concurrently (e.g., in parallel tests), ensure tests run in separate # processes to avoid ENV variable conflicts. # + # @example Testing with parallel processes + # # In RSpec configuration: + # config.before(:each) do |example| + # ENV.delete("REACT_ON_RAILS_SKIP_VALIDATION") + # end + # # @note Manual ENV Setting: While this ENV variable is designed to be set by generators, # users can manually set it (e.g., `REACT_ON_RAILS_SKIP_VALIDATION=true rails server`) # to bypass validation. This should only be done temporarily during debugging or diff --git a/spec/react_on_rails/engine_spec.rb b/spec/react_on_rails/engine_spec.rb index 069bf53c5e..b3b2b917fd 100644 --- a/spec/react_on_rails/engine_spec.rb +++ b/spec/react_on_rails/engine_spec.rb @@ -50,6 +50,11 @@ module ReactOnRails expect(Rails.logger).not_to have_received(:debug) .with("[React on Rails] Skipping validation during generator runtime") end + + it "short-circuits before checking File.exist?" do + described_class.skip_version_validation? + expect(File).not_to have_received(:exist?) + end end context "when package.json is missing" do