lhs icon indicating copy to clipboard operation
lhs copied to clipboard

Deprecation warnings when using Rails 6+ with Zeitwerk

Open wollistik opened this issue 3 years ago • 1 comments

Hi, I encountered an issue when I upgrade our app to Rails 6 with Zeitwerk mode enabled. On startup I get a deprecation warning:

DEPRECATION WARNING: Initialization autoloaded the constants Remote, ActionText::ContentHelper, Remote::OnCallGroup, PrinterTemplate, Remote::AuthenticatedPrinting, Remote::Printer, and Remote::PrinterJob.

Being able to do this is deprecated. Autoloading during initialization is going
to be an error condition in future versions of Rails.

Reloading does not reboot the application, and therefore code executed during
initialization does not run again. So, if you reload Remote, for example,
the expected changes won't be reflected in that stale Module object.

These autoloaded constants have been unloaded.

Please, check the "Autoloading and Reloading Constants" guide for solutions.

While I could figure out this is caused by initializers loading application classes, I managed to get rid of most of them. But unfortunately the last ones still causing this warning are LHS Subclasses (all the ones with Remote* in above output). When digging deeper I found the autoload_records.rb initializer from LHS, which is causing the issue.

This should be fixed in order to be safe for future Rails versions.

wollistik avatar Mar 11 '21 09:03 wollistik

With Rails 7 on the horizon, this will no longer work:

https://weblog.rubyonrails.org/2021/9/3/autoloading-in-rails-7-get-ready/

wollistik avatar Sep 07 '21 06:09 wollistik