Skip to content

Commit e329076

Browse files
committed
Add Bundler check to prevent false Pro gem detection in sibling structure
In the sibling gem structure, both react_on_rails and react_on_rails_pro gems are loaded from the root Gemfile, making both available via Gem.loaded_specs. This caused the base dummy app to incorrectly detect Pro as installed, leading to: - Package mismatch errors (base dummy has react-on-rails package, not Pro package) - Potential double-engine loading issues Solution: Check Bundler's actual dependencies to see if Pro is explicitly requested in the application's Gemfile, not just if it's available in the load path. This allows both gems to coexist in development while correctly identifying which gem the application is actually using.
1 parent 261244b commit e329076

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

lib/react_on_rails/utils.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,16 +248,29 @@ def self.gem_available?(name)
248248
end
249249
end
250250

251+
# Checks if react_on_rails_pro is in the current Bundler context
252+
# @return [Boolean] true if Pro gem is in the Gemfile
253+
def self.pro_gem_in_bundle?
254+
return true unless defined?(Bundler)
255+
256+
Bundler.locked_gems&.dependencies&.key?("react_on_rails_pro") ||
257+
Bundler.definition.dependencies.any? { |dep| dep.name == "react_on_rails_pro" }
258+
end
259+
251260
# Checks if React on Rails Pro is installed and licensed.
252261
# This method validates the license and will raise an exception if invalid.
253262
#
263+
# In a sibling gem structure, both gems may be loaded, but we should only
264+
# consider Pro as "active" if it's explicitly requested in the application's Gemfile.
265+
#
254266
# @return [Boolean] true if Pro is available with valid license
255267
# @raise [ReactOnRailsPro::Error] if license is invalid
256268
def self.react_on_rails_pro?
257269
return @react_on_rails_pro if defined?(@react_on_rails_pro)
258270

259271
@react_on_rails_pro = begin
260272
return false unless gem_available?("react_on_rails_pro")
273+
return false unless pro_gem_in_bundle?
261274

262275
# Guard against edge cases where constant exists but module isn't fully loaded
263276
require "react_on_rails_pro" unless defined?(ReactOnRailsPro)

0 commit comments

Comments
 (0)