Skip to content

Commit

Permalink
Revert "Avoid loading ActionView::Base during initialization (#1659)"
Browse files Browse the repository at this point in the history
This reverts commit 01510f3.
  • Loading branch information
boardfish committed Jul 19, 2023
1 parent 095f76f commit 0dd2cf9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/view_component/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class << self
#
# @return [ActiveSupport::OrderedOptions]
def config
@config ||= ActiveSupport::OrderedOptions.new
@config ||= ViewComponent::Config.defaults
end

# Replaces the entire config. You shouldn't need to use this directly
Expand Down
7 changes: 4 additions & 3 deletions lib/view_component/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

module ViewComponent
class Engine < Rails::Engine # :nodoc:
config.view_component = ViewComponent::Config.defaults
config.view_component = ViewComponent::Base.config

rake_tasks do
load "view_component/rails/tasks/view_component.rake"
Expand All @@ -15,6 +15,9 @@ class Engine < Rails::Engine # :nodoc:
initializer "view_component.set_configs" do |app|
options = app.config.view_component

%i[generate preview_controller preview_route show_previews_source].each do |config_option|
options[config_option] ||= ViewComponent::Base.public_send(config_option)
end
options.instrumentation_enabled = false if options.instrumentation_enabled.nil?
options.render_monkey_patch_enabled = true if options.render_monkey_patch_enabled.nil?
options.show_previews = (Rails.env.development? || Rails.env.test?) if options.show_previews.nil?
Expand All @@ -37,8 +40,6 @@ class Engine < Rails::Engine # :nodoc:

initializer "view_component.enable_instrumentation" do |app|
ActiveSupport.on_load(:view_component) do
Base.config = app.config.view_component

if app.config.view_component.instrumentation_enabled.present?
# :nocov: Re-executing the below in tests duplicates initializers and causes order-dependent failures.
ViewComponent::Base.prepend(ViewComponent::Instrumentation)
Expand Down

0 comments on commit 0dd2cf9

Please sign in to comment.