Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Override paths being loaded multiple times #234

Open
pelargir opened this issue Oct 20, 2022 · 0 comments
Open

Override paths being loaded multiple times #234

pelargir opened this issue Oct 20, 2022 · 0 comments

Comments

@pelargir
Copy link

TLDR: When a gem in the Gemfile has no Railtie defined (dotenv for example), Rails defaults the railtie.root value to the application's root directory. This causes Deface to load the application's root directory as an override path twice when Rails.application.config.cache_classes is false.

This bit of code is to blame:

# check all railties / engines / extensions / application for overrides
app.railties._all.dup.push(app).each do |railtie|
  next unless railtie.respond_to? :root
  load_overrides(railtie)
end

Appending Rails.application to the list of Railties works fine when no other gems are using the default railtie.root path which is identical to the Rails.application.root path. This results in the overrides being loaded twice, leading to "already initialized constant" warnings when the app boots in development mode (cache_classes = false).

One possible solution would be to append each Railtie root to an array before loading, and return early if the Railtie root already exists in the array. Something like this:

class Environment::Overrides
  def initialize
    @all = {}
    @loaded = []
  end

  def enumerate_and_load(paths, root)
    return if @loaded.include?(root)
    @loaded << root
    # ...
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant