hotwired / hotwire-rails

Use Hotwire in your Ruby on Rails app
https://hotwired.dev
MIT License
971 stars 27 forks source link

Resolve undefined method error with eager loading enabled #4

Closed pbyrne closed 3 years ago

pbyrne commented 3 years ago

Because:

The following error happened when deploying a Rails 6.1 app to staging, which had config.eager_load = true, but which didn't happen in local development:

gems/railties-6.1.0/lib/rails/application/finisher.rb:134:in `each': undefined method `eager_load!' for Hotwire:Module (NoMethodError)
from gems/railties-6.1.0/lib/rails/application/finisher.rb:134:in `block in <module:Finisher>'

Solution:

This is effectively the same as https://github.com/hotwired/stimulus-rails/pull/7.

fxn commented 3 years ago

The Hotwire module does not implement eager_load!. That makes sense, there is nothing to eager load.

Deleting the line

config.eager_load_namespaces << Hotwire

would be the most exact thing to do. If you are not eager loadable, just do not configure yourself as eager loadable.

Alternatively, we could apply this patch just in case in the future you'd like to use AS::Autoload macros somewhere in this module. Personally, I am not a big fan of "just in case"s, but that is @dhh's choice :).

dhh commented 3 years ago

Let's just remove. Don't like just in case either 👍

dhh commented 3 years ago

Fixed via beddd7b873bcab386d4bc60353652b4343f3c558 and 5b8a4e1ec0a15ba86109e72acd68fd1f31338eb4