Only interact with ActionController::API on load#157
Open
ghiculescu wants to merge 1 commit into
Open
Conversation
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>'
```
There was a problem hiding this comment.
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 anActiveSupport.on_load(:action_controller_api)hook. - Ensure
ActionController::APIinstrumentation 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes this