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

2.66 forces ActionView to load too soon #1507

Closed
jdelStrother opened this issue Sep 2, 2022 · 2 comments
Closed

2.66 forces ActionView to load too soon #1507

jdelStrother opened this issue Sep 2, 2022 · 2 comments

Comments

@jdelStrother
Copy link
Contributor

Steps to reproduce

Add ViewComponent >= 2.66 to Gemfile, boot rails (eg rails console).

Expected behavior

ActionView::Base shouldn't be loaded during the initialization process.
Rails does a poor job of making this explicit, IMO - there's a suggestion that you shouldn't load frameworks (ActiveRecord::Base, ActionView::Base etc) during boot here: https://edgeguides.rubyonrails.org/engines.html#load-and-configuration-hooks, since it slows the boot process.
More concretely, loading those frameworks too soon can mean that they ignore configuration - eg setting config.active_record.belongs_to_required_by_default in config/initializers/new_framework_defaults.rb is ignored if ActiveRecord::Base has already been loaded.
As it happens, ActionView::Base doesn't have the same problem because most of its settings are propagated to, eg, ActionView::Helpers::TagHelper in after_initialize, rather than being set directly on ActionView:Base, but that seems a fragile thing to rely on.

Actual behavior

ActionView::Base loads as soon as view_component is required, here:

GEMS/actionview-7.0.3.1/lib/action_view/base.rb:276:in `<class:Base>'
GEMS/actionview-7.0.3.1/lib/action_view/base.rb:141:in `<module:ActionView>'
GEMS/actionview-7.0.3.1/lib/action_view/base.rb:12:in `<main>'
GEMS/view_component-2.66.0/lib/view_component/base.rb:16:in `<module:ViewComponent>'
GEMS/view_component-2.66.0/lib/view_component/base.rb:15:in `<main>'
GEMS/view_component-2.66.0/lib/view_component/engine.rb:4:in `<main>'
GEMS/view_component-2.66.0/lib/view_component.rb:31:in `<main>'
GEMS/bundler-2.3.14/lib/bundler/runtime.rb:60:in `block (2 levels) in require'
GEMS/bundler-2.3.14/lib/bundler/runtime.rb:55:in `each'
GEMS/bundler-2.3.14/lib/bundler/runtime.rb:55:in `block in require'
GEMS/bundler-2.3.14/lib/bundler/runtime.rb:44:in `each'
GEMS/bundler-2.3.14/lib/bundler/runtime.rb:44:in `require'
GEMS/bundler-2.3.14/lib/bundler.rb:176:in `require'
/Users/jon/Developer/web/config/application.rb:43:in `<main>'
GEMS/railties-7.0.3.1/lib/rails/command/actions.rb:22:in `require_application!'
GEMS/railties-7.0.3.1/lib/rails/command/actions.rb:14:in `require_application_and_environment!'
GEMS/railties-7.0.3.1/lib/rails/commands/console/console_command.rb:101:in `perform'
GEMS/thor-1.2.1/lib/thor/command.rb:27:in `run'
GEMS/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'
GEMS/thor-1.2.1/lib/thor.rb:392:in `dispatch'
GEMS/railties-7.0.3.1/lib/rails/command/base.rb:87:in `perform'
GEMS/railties-7.0.3.1/lib/rails/command.rb:48:in `invoke'
GEMS/railties-7.0.3.1/lib/rails/commands.rb:18:in `<main>'
bin/rails:6:in `<main>'

System configuration

Rails version: 7.0.3

Ruby version: 3.1.2

Gem version: 2.6.9

@joelhawksley
Copy link
Member

@jdelStrother thanks for filing this bug. Would you be interested in taking a crack at fixing it?

@jdelStrother
Copy link
Contributor Author

Sure, will take a look - it might be a week or so before I get chance though.

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

3 participants