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

primer/form_helper (LoadError) with the latest version of Rails. (7.1.1) #2318

Closed
safeforge opened this issue Oct 19, 2023 · 3 comments · Fixed by #2336
Closed

primer/form_helper (LoadError) with the latest version of Rails. (7.1.1) #2318

safeforge opened this issue Oct 19, 2023 · 3 comments · Fixed by #2336
Assignees
Labels

Comments

@safeforge
Copy link
Contributor

I attempted to utilize the gem with the most recent version of Rails (7.1.1), but it appears there is an issue with files loading. Below, I outline the steps to replicate the issue:

rails new buggy --css postcss --js esbuild -d sqlite3;
bundle add primer_view_components;
echo 'require "view_component"\nrequire "primer/view_components/engine"' >> config/application.rb;

Running the application with the command rails s raises an error in the browser

Puma caught this error: cannot load such file -- primer/form_helper (LoadError)
@camertron
Copy link
Contributor

Hey @safeforge, thanks for bringing this to our attention. I followed the steps you posted to create a new Rails app and was able to reproduce the behavior you're seeing. Curiously, the same behavior does not appear in a new Rails 7.0 app. I've played around a bit trying to figure it out, and it looks like something changed in the way 7.1 adds to the Ruby load path. Even more curiously, the issue doesn't appear to happen in the github.com repo, which has been running 7.1 for months now. I'll try to get to the bottom of the issue today.

@safeforge
Copy link
Contributor Author

hey @camertron thank you for the prompt response. I have the same feeling, it's related to the load path upgrade introduced in Rails 7.1 and the new defaults. In fact, if you revert the defaults in the application from 7.1 to 7, it works correctly.

  class Application < Rails::Application
    # Initialize configuration defaults for originally generated Rails version.
    config.load_defaults 7.0
  end

I attempted to activate each feature individually listed in new_framework_defaults_7_1.rb, and the application still works properly. The issue only arises when the application starts with the 7.1 defaults.

@camertron camertron mentioned this issue Oct 26, 2023
3 tasks
@camertron
Copy link
Contributor

Ok, I think I've figured this out. Rails 7.1 no longer adds eager load paths to the Ruby load path, meaning you can no longer require files that have been added to Rails' eager load paths. Instead Zeitwerk autoloads the correct file whenever the corresponding constant is referenced. This has been possible for a long time in Rails, but 7.1 removed the ability to require at all. I have therefore removed the offending require. Here's the PR: #2336

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants