From f7c0aa48e6d624cff6f974e0801c498c12703c6e Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sat, 11 Nov 2023 13:57:39 +0100 Subject: [PATCH] Revise how to disable eager loading app/channels --- lib/turbo/engine.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/turbo/engine.rb b/lib/turbo/engine.rb index 487bf39b..085c83ac 100644 --- a/lib/turbo/engine.rb +++ b/lib/turbo/engine.rb @@ -16,7 +16,15 @@ class Engine < Rails::Engine ) initializer "turbo.no_action_cable", before: :set_eager_load_paths do - config.eager_load_paths.delete("#{root}/app/channels") unless defined?(ActionCable) + unless defined?(ActionCable) + if Rails.autoloaders.zeitwerk_enabled? + Rails.autoloaders.once.do_not_eager_load("#{root}/app/channels") + else + # The purpose of this else clause is to support the classic autoloader + # in Rails 6.x applications. Can be deleted if the gem dependency is upgraded to Rails 7 or above. + config.eager_load_paths.delete("#{root}/app/channels") + end + end end # If you don't want to precompile Turbo's assets (eg. because you're using webpack),