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
Autoloading regression between Rails 7.0 and 7.1 #49629
Comments
Got it! This is actually unrelated to autoloading or Zeitwerk (though you could not know :). If you comment The fundamental issue has been in Rails for a long time, let me explain:
Note that We'll need to address this some way or another, because |
So, a minimal reproduction of the root issue in a Rails 7.0 application is this:
You'll see Now, order the lines the other way around: config.eager_load_paths << "#{Rails.root}/lib"
config.paths["app/helpers"] << "#{Rails.root}/vendor" and run the command again. You'll see Of course, from the point of view of the user, the order of those lines should make no difference. That is broken. I have not verified personally, but from reading the source code, I'd bet this has worked this way since Rails 3.0, where this implementation with memoizations was added. |
Fix coming soon. |
This is fixed Brad, thanks very much for such a great issue description and simple reproduction steps. |
I always learn a thing or two about the internals of Rails when I open a PR for you—thanks for the clear description of the problems and the fix! |
Steps to reproduce
Setup the Rails 7.1 project:
Then open http://localhost:3000. You should see the error. Refresh the page and you won't see the error.
Now open
./config/environments/development.rb
and changeconfig.eager_load
Reboot the server and you'll see the Zeitwerk error message.
The path for this helper is set at https://github.com/sitepress/sitepress/blob/main/sitepress-rails/lib/sitepress/engine.rb#L29 and it lives in the Rails app at https://github.com/bradgessler/rails-7-1-autoloading-regression/blob/main/app/content/helpers/page_helper.rb
To see the behavior in Rails 7.0, run:
Load the page with the
eager_load
setting to true, then false, and you'll see that it works.Expected behavior
I expect for the dev environment is one of the following:
Actual behavior
In my dev env, the helper is not initially loaded. When I refresh the page it's loaded.
Video of this behavior at https://objects.bradgessler.com/Screen-Recording-2023-10-13-at-12.09.03-PM.mov
System configuration
Rails version: 7.1.1
Ruby version: 3.2
The text was updated successfully, but these errors were encountered: