Skip to content

Commit

Permalink
Revise how to disable eager loading app/channels (#601)
Browse files Browse the repository at this point in the history
  • Loading branch information
fxn authored Mar 11, 2024
1 parent ab9c87e commit a167573
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion lib/turbo/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,25 @@ class Engine < Rails::Engine
#{root}/app/jobs
)

# If the parent application does not use Action Cable, app/channels cannot
# be eager loaded, because it references the ActionCable constant.
#
# When turbo-rails depends on Rails 7 or above, the entire block can be
# reduced to
#
# unless defined?(ActionCable)
# Rails.autoloaders.once.do_not_eager_load("#{root}/app/channels")
# end
#
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
# This else branch only runs in Rails 6.x + classic mode.
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),
Expand Down

0 comments on commit a167573

Please sign in to comment.