turbo-rails: Can't load turbo-rails without Action Cable starting in Rails 7.1.2

I’m not sure whether to report this bug here, or in Rails. Let me know if I should move it.

With today’s release of Rails 7.1.2, it is no longer possible to use turbo-rails without Action Cable. I get the following error when eager loading is enabled:

NameError: uninitialized constant ActionCable (NameError)

class Turbo::StreamsChannel < ActionCable::Channel::Base
                                                  ^^^^^^
Did you mean?  Rational
/Users/mbrictson/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/turbo-rails-1.5.0/app/channels/turbo/streams_channel.rb:34:in `<main>'

This check in the turbo-rails engine is supposed to automatically remove app/channels from the eager-load paths when Action Cable is not present:

https://github.com/hotwired/turbo-rails/blob/e44b6a98a77a0a2cc927f986a67517d73c4c9246/lib/turbo/engine.rb#L18-L20

However, starting with Rails 7.1.2, this technique apparently no longer works.

There were changes in Rails 7.1.2 regarding auto/eager loading of paths in engines (see https://github.com/rails/rails/pull/49636), so this could be a new bug Rails, or it could mean that turbo-rails needs to be changed to accommodate the new behavior.

Edit: I confirmed that rolling back https://github.com/rails/rails/pull/49636 fixes the problem.

About this issue

  • Original URL
  • State: closed
  • Created 8 months ago
  • Reactions: 9
  • Comments: 16 (7 by maintainers)

Commits related to this issue

Most upvoted comments

Not urgent! Let me know if there is anything I can do to help.

For now, I am working around the issue by loading Action Cable:

# config/application.rb

require "action_cable/engine"

I had this on the CI but not in the local environment

@xymbol this is because, by default, Rails enables eager loading in CI test environments, but not local test environments. See config/environments/test.rb:

config.eager_load = ENV["CI"].present?

https://github.com/rails/rails/blob/v7.1.2/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt#L14-L18

ACK. This gem supports Rails 6.0, need to think about a patch that works for both autoloaders.

The root problem here is an inconsistency between the config.* endpoints for paths that has been there since Rails 3. That delete call worked by pure chance, it wouldn’t have worked for config.autoload_paths because that API is not really designed to support this.

In case it helps urgently, in Rails 7.1 you can throw this in an application initializer:

Rails.autoloaders.once.do_not_eager_load("#{Turbo::Engine.root}/app/channels")

off the top of my head.

It’s near 1 AM over here.

@dorianmariecom totally forgot about this ticket, I’ll write back!