diff --git a/lib/view_component/base.rb b/lib/view_component/base.rb index fc33619e6..ff68fa95c 100644 --- a/lib/view_component/base.rb +++ b/lib/view_component/base.rb @@ -456,7 +456,7 @@ def short_identifier def inherited(child) # Compile so child will inherit compiled `call_*` template methods that # `compile` defines - compile + compile(frozen_string_literal: ViewComponent::Base.config.frozen_string_literal) # Give the child its own personal #render_template_for to protect against the case when # eager loading is disabled and the parent component is rendered before the child. In diff --git a/lib/view_component/engine.rb b/lib/view_component/engine.rb index 7d33ec5cc..fa2d9aad3 100644 --- a/lib/view_component/engine.rb +++ b/lib/view_component/engine.rb @@ -74,9 +74,13 @@ class Engine < Rails::Engine # :nodoc: end end - initializer "view_component.eager_load_actions" do + initializer "view_component.eager_load_actions" do |app| ActiveSupport.on_load(:after_initialize) do - ViewComponent::Base.descendants.each(&:compile) if Rails.application.config.eager_load + if Rails.application.config.eager_load + ViewComponent::Base.descendants.each do |descendant| + descendant.compile(frozen_string_literal: app.config.view_component.frozen_string_literal) + end + end end end