From 139c77053b76de70bf0382b951aa0ef058a1534a Mon Sep 17 00:00:00 2001 From: Jon Rohan Date: Wed, 11 Jan 2023 15:34:19 -0800 Subject: [PATCH] Revert "Avoid loading ActionView::Base during initialization (#1528)" (#1626) * Revert "Avoid loading ActionView::Base during initialization (#1528)" This reverts commit 22dbe8f648b44cc73d9663082a3e5024345b28ee. * Put back changelog * Adding changelog for revert --- docs/CHANGELOG.md | 4 ++++ lib/view_component/base.rb | 2 +- lib/view_component/engine.rb | 9 +++++---- test/sandbox/config/application.rb | 18 ------------------ .../zzz_complete_initialization.rb | 9 --------- 5 files changed, 10 insertions(+), 32 deletions(-) delete mode 100644 test/sandbox/config/initializers/zzz_complete_initialization.rb diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index eee45b6c46..ae82ae2170 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -10,6 +10,10 @@ nav_order: 5 ## main +* Revert "Avoid loading ActionView::Base during initialization (#1528)" + + *Jon Rohan* + * Fix tests using `with_rendered_component_path` with custom layouts. *Ian Hollander* diff --git a/lib/view_component/base.rb b/lib/view_component/base.rb index c5898f5fd8..c1e73001f1 100644 --- a/lib/view_component/base.rb +++ b/lib/view_component/base.rb @@ -23,7 +23,7 @@ class << self # # @return [ViewComponent::Config] def config - @config ||= ActiveSupport::OrderedOptions.new + @config ||= ViewComponent::Config.defaults end # Replaces the entire config. You shouldn't need to use this directly diff --git a/lib/view_component/engine.rb b/lib/view_component/engine.rb index 3b98073cb9..b7828009dd 100644 --- a/lib/view_component/engine.rb +++ b/lib/view_component/engine.rb @@ -1,11 +1,11 @@ # frozen_string_literal: true require "rails" -require "view_component/config" +require "view_component/base" 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" @@ -14,6 +14,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? @@ -36,8 +39,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: ViewComponent::Base.prepend(ViewComponent::Instrumentation) diff --git a/test/sandbox/config/application.rb b/test/sandbox/config/application.rb index fe11963dab..fec3a890a3 100644 --- a/test/sandbox/config/application.rb +++ b/test/sandbox/config/application.rb @@ -8,24 +8,6 @@ require "action_view/railtie" require "sprockets/railtie" -# Track when different Rails frameworks get loaded. -# Ideally, none of them should be loaded until after initialization is complete. -# See config/initializers/zzz_complete_initialization.rb for the other half of this. -RAILS_FRAMEWORKS = [ - :action_cable, - :action_controller, - :action_mailer, - :action_view, - :active_job, - :active_record -] -FRAMEWORK_LOAD_POINTS = {} -RAILS_FRAMEWORKS.each do |feature| - ActiveSupport.on_load(feature) do - FRAMEWORK_LOAD_POINTS[feature] = caller - end -end - require "view_component" require "haml" diff --git a/test/sandbox/config/initializers/zzz_complete_initialization.rb b/test/sandbox/config/initializers/zzz_complete_initialization.rb deleted file mode 100644 index 0e29db1995..0000000000 --- a/test/sandbox/config/initializers/zzz_complete_initialization.rb +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -# FRAMEWORK_LOAD_POINTS ought to be empty - we shouldn't have -# autoloaded ActionView::Base during initialization, for example. -FRAMEWORK_LOAD_POINTS.each do |framework, caller| - warn "#{framework} loaded too soon, from:" - warn caller - exit 1 -end