Skip to content

Only interact with ActionController::API on load#157

Open
ghiculescu wants to merge 1 commit into
basecamp:masterfrom
ghiculescu:patch-2
Open

Only interact with ActionController::API on load#157
ghiculescu wants to merge 1 commit into
basecamp:masterfrom
ghiculescu:patch-2

Conversation

@ghiculescu

Copy link
Copy Markdown

Fixes this

:action_controller_api was loaded before application initialization.
Prematurely executing load hooks will slow down your boot time
and could cause conflicts with the load order of your application.
Please wrap your code with an on_load hook:

  ActiveSupport.on_load(:action_controller_api) do
    # your code here
  end


Called from:
ruby/3.4.0/bundler/gems/rails-0e53474dd25b/activesupport/lib/active_support/lazy_load_hooks.rb:97:in 'Module#class_eval'
ruby/3.4.0/bundler/gems/rails-0e53474dd25b/activesupport/lib/active_support/lazy_load_hooks.rb:97:in 'block in ActiveSupport::LazyLoadHooks#execute_hook'
ruby/3.4.0/bundler/gems/rails-0e53474dd25b/activesupport/lib/active_support/lazy_load_hooks.rb:87:in 'ActiveSupport::LazyLoadHooks#with_execution_control'
ruby/3.4.0/bundler/gems/rails-0e53474dd25b/activesupport/lib/active_support/lazy_load_hooks.rb:92:in 'ActiveSupport::LazyLoadHooks#execute_hook'
ruby/3.4.0/bundler/gems/rails-0e53474dd25b/activesupport/lib/active_support/lazy_load_hooks.rb:78:in 'block in ActiveSupport::LazyLoadHooks#run_load_hooks'
ruby/3.4.0/bundler/gems/rails-0e53474dd25b/activesupport/lib/active_support/lazy_load_hooks.rb:77:in 'Array#each'
ruby/3.4.0/bundler/gems/rails-0e53474dd25b/activesupport/lib/active_support/lazy_load_hooks.rb:77:in 'ActiveSupport::LazyLoadHooks#run_load_hooks'
ruby/3.4.0/bundler/gems/rails-0e53474dd25b/actionpack/lib/action_controller/api.rb:153:in '<class:API>'
ruby/3.4.0/bundler/gems/rails-0e53474dd25b/actionpack/lib/action_controller/api.rb:93:in '<module:ActionController>'
ruby/3.4.0/bundler/gems/rails-0e53474dd25b/actionpack/lib/action_controller/api.rb:10:in '<main>'
/usr/local/lib/ruby/3.4.0/bundled_gems.rb:82:in 'Kernel.require'
/usr/local/lib/ruby/3.4.0/bundled_gems.rb:82:in 'block (2 levels) in Kernel#replace_require'
ruby/3.4.0/gems/bootsnap-1.18.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in 'Kernel#require'
ruby/3.4.0/gems/zeitwerk-2.6.8/lib/zeitwerk/kernel.rb:38:in 'Kernel#require'
ruby/3.4.0/gems/marginalia-1.11.1/lib/marginalia/railtie.rb:44:in 'Marginalia::Railtie.insert_into_action_controller'
ruby/3.4.0/gems/marginalia-1.11.1/lib/marginalia/railtie.rb:12:in 'block (2 levels) in <class:Railtie>'

Fixes this

```
:action_controller_api was loaded before application initialization.
Prematurely executing load hooks will slow down your boot time
and could cause conflicts with the load order of your application.
Please wrap your code with an on_load hook:

  ActiveSupport.on_load(:action_controller_api) do
    # your code here
  end


Called from:
ruby/3.4.0/bundler/gems/rails-0e53474dd25b/activesupport/lib/active_support/lazy_load_hooks.rb:97:in 'Module#class_eval'
ruby/3.4.0/bundler/gems/rails-0e53474dd25b/activesupport/lib/active_support/lazy_load_hooks.rb:97:in 'block in ActiveSupport::LazyLoadHooks#execute_hook'
ruby/3.4.0/bundler/gems/rails-0e53474dd25b/activesupport/lib/active_support/lazy_load_hooks.rb:87:in 'ActiveSupport::LazyLoadHooks#with_execution_control'
ruby/3.4.0/bundler/gems/rails-0e53474dd25b/activesupport/lib/active_support/lazy_load_hooks.rb:92:in 'ActiveSupport::LazyLoadHooks#execute_hook'
ruby/3.4.0/bundler/gems/rails-0e53474dd25b/activesupport/lib/active_support/lazy_load_hooks.rb:78:in 'block in ActiveSupport::LazyLoadHooks#run_load_hooks'
ruby/3.4.0/bundler/gems/rails-0e53474dd25b/activesupport/lib/active_support/lazy_load_hooks.rb:77:in 'Array#each'
ruby/3.4.0/bundler/gems/rails-0e53474dd25b/activesupport/lib/active_support/lazy_load_hooks.rb:77:in 'ActiveSupport::LazyLoadHooks#run_load_hooks'
ruby/3.4.0/bundler/gems/rails-0e53474dd25b/actionpack/lib/action_controller/api.rb:153:in '<class:API>'
ruby/3.4.0/bundler/gems/rails-0e53474dd25b/actionpack/lib/action_controller/api.rb:93:in '<module:ActionController>'
ruby/3.4.0/bundler/gems/rails-0e53474dd25b/actionpack/lib/action_controller/api.rb:10:in '<main>'
/usr/local/lib/ruby/3.4.0/bundled_gems.rb:82:in 'Kernel.require'
/usr/local/lib/ruby/3.4.0/bundled_gems.rb:82:in 'block (2 levels) in Kernel#replace_require'
ruby/3.4.0/gems/bootsnap-1.18.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in 'Kernel#require'
ruby/3.4.0/gems/zeitwerk-2.6.8/lib/zeitwerk/kernel.rb:38:in 'Kernel#require'
ruby/3.4.0/gems/marginalia-1.11.1/lib/marginalia/railtie.rb:44:in 'Marginalia::Railtie.insert_into_action_controller'
ruby/3.4.0/gems/marginalia-1.11.1/lib/marginalia/railtie.rb:12:in 'block (2 levels) in <class:Railtie>'
```
Copilot AI review requested due to automatic review settings April 30, 2026 01:50

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts Marginalia’s Rails Railtie integration to avoid prematurely interacting with ActionController::API during boot, addressing Rails’ warning about :action_controller_api being loaded before application initialization.

Changes:

  • Replace the defined?(ActionController::API) check (which can trigger autoload) with an ActiveSupport.on_load(:action_controller_api) hook.
  • Ensure ActionController::API instrumentation is only applied once the API framework component is actually loaded.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

Successfully merging this pull request may close these issues.

2 participants