Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Tracked by #4121
mattbrictson opened this issue Nov 10, 2023 · 16 comments · Fixed by #601
Closed
Tracked by #4121

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

mattbrictson opened this issue Nov 10, 2023 · 16 comments · Fixed by #601

Comments

@mattbrictson
Copy link

mattbrictson commented Nov 10, 2023

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:

initializer "turbo.no_action_cable", before: :set_eager_load_paths do
config.eager_load_paths.delete("#{root}/app/channels") unless defined?(ActionCable)
end

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 rails/rails#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 rails/rails#49636 fixes the problem.

@dhh
Copy link
Member

dhh commented Nov 10, 2023

cc @fxn

@fxn
Copy link
Contributor

fxn commented Nov 10, 2023

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.

@mattbrictson
Copy link
Author

mattbrictson commented Nov 11, 2023

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"

@zarqman
Copy link
Contributor

zarqman commented Nov 11, 2023

dupe

@fxn
Copy link
Contributor

fxn commented Nov 11, 2023

@zarqman actually, shared a one-liner above that is a bit simpler.

@zarqman
Copy link
Contributor

zarqman commented Nov 11, 2023

@fxn, ack, missed that! Thanks!

@xymbol
Copy link

xymbol commented Nov 13, 2023

@fxn I ran into this issue, too, and I confirm that your workaround above works. Thank you!

I'm curious. I had this on the CI but not in the local environment, running on identical versions. Can these loading issues be architecture-dependent?

@mattbrictson
Copy link
Author

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

@xymbol
Copy link

xymbol commented Nov 13, 2023

@mattbrictson TIL, thank you.

sascha-karnatz added a commit to sascha-karnatz/alchemy_cms that referenced this issue Nov 14, 2023
The CI test pipeline breaks for Rails 7.1. The eager loading results into a Zeitwerk error in the turbo-rails gem. The current solution is to include actioncable if the application is running in a Github Action until this bug fixed.

Ref: hotwired/turbo-rails#512
sascha-karnatz added a commit to sascha-karnatz/alchemy_cms that referenced this issue Nov 14, 2023
The CI test pipeline breaks for Rails 7.1. The eager loading results into a Zeitwerk error in the turbo-rails gem. The current solution is to include actioncable if the application is running in a Github Action until this bug is fixed.

Ref: hotwired/turbo-rails#512
sascha-karnatz added a commit to sascha-karnatz/alchemy_cms that referenced this issue Nov 14, 2023
The CI test pipeline breaks for Rails 7.1. The eager loading results into a Zeitwerk error in the turbo-rails gem. The current solution is to include actioncable if the application is running in a Github Action until this bug is fixed.

Ref: hotwired/turbo-rails#512
alchemycms-bot pushed a commit to AlchemyCMS/alchemy_cms that referenced this issue Nov 15, 2023
The CI test pipeline breaks for Rails 7.1. The eager loading results into a Zeitwerk error in the turbo-rails gem. The current solution is to include actioncable if the application is running in a Github Action until this bug is fixed.

Ref: hotwired/turbo-rails#512
(cherry picked from commit 8fe1bb3)
littleforest added a commit to ApprenticeshipStandardsDotOrg/ApprenticeshipStandardsDotOrg that referenced this issue Nov 15, 2023
mvz added a commit to mvz/playdate that referenced this issue Nov 19, 2023
littleforest added a commit to ApprenticeshipStandardsDotOrg/ApprenticeshipStandardsDotOrg that referenced this issue Nov 20, 2023
littleforest added a commit to ApprenticeshipStandardsDotOrg/ApprenticeshipStandardsDotOrg that referenced this issue Nov 21, 2023
mishina2228 added a commit to mishina2228/youtube-api-trial that referenced this issue Nov 25, 2023
littleforest added a commit to ApprenticeshipStandardsDotOrg/ApprenticeshipStandardsDotOrg that referenced this issue Nov 28, 2023
* Upgrade Rails gem to 7.1.2

* Updates to configuration files

* Add new migrations

* Update turbo-rails dependencies

* Require action_cable/engine
hotwired/turbo-rails#512 (comment)

* Remove ActiveStorageAttachment factory and modify specs

* Source_file must have an active_storage_attachment so
remove specs that imply otherwise

* Remove duplicate key for national_standards_type in occupation_standard index

* Fix request specs related to admin routing

* Add spec to confirm source_file is persisted

* Use more concise fixture_file_upload

* Move creating of source_files to standards import model

* Remove unneeded active_storage_blobs factory;
minor change to source_file factory

* Remove sample Stimulus hello_controller
razumau added a commit to maii-chgk/rating-ui that referenced this issue Dec 16, 2023
turbo-rails (for now) does not work in Rails 7.1 without Action Cable loaded: hotwired/turbo-rails#512
dennmart added a commit to dennmart/airport_gap that referenced this issue Jan 4, 2024
This can be reverted when the following issue is fixed:
hotwired/turbo-rails#512
EmilioCristalli added a commit to cedarcode/mi_carrera that referenced this issue Jan 22, 2024
jcoyne added a commit to projectblacklight/blacklight_range_limit that referenced this issue Feb 2, 2024
jcoyne added a commit to projectblacklight/blacklight_range_limit that referenced this issue Feb 2, 2024
It is required by turbo-rails. See hotwired/turbo-rails#512
jcoyne added a commit to projectblacklight/spotlight that referenced this issue Feb 29, 2024
it is a test dependency of turbo-rails. See hotwired/turbo-rails#512
EmilioCristalli added a commit to cedarcode/mi_carrera that referenced this issue Mar 4, 2024
@dorianmariecom
Copy link

What's the status of this? Do we still need the workaround?

@fxn
Copy link
Contributor

fxn commented Mar 6, 2024

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

@dorianmariecom
Copy link

/home/runner/work/haymakers-for-hope-web/haymakers-for-hope-web/vendor/bundle/ruby/3.3.0/gems/turbo-rails-2.0.4/app/channels/turbo/streams_channel.rb:34:in `<main>': uninitialized constant ActionCable (NameError)

class Turbo::StreamsChannel < ActionCable::Channel::Base
                              ^^^^^^^^^^^
Did you mean?  ActionMailer
	from /opt/hostedtoolcache/Ruby/3.3.0/x64/lib/ruby/3.3.0/bundled_gems.rb:74:in `require'
	from /opt/hostedtoolcache/Ruby/3.3.0/x64/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require'
	from /home/runner/work/haymakers-for-hope-web/haymakers-for-hope-web/vendor/bundle/ruby/3.3.0/gems/bootsnap-1.18.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
	from /home/runner/work/haymakers-for-hope-web/haymakers-for-hope-web/vendor/bundle/ruby/3.3.0/gems/zeitwerk-2.6.13/lib/zeitwerk/kernel.rb:26:in `require'

The issue is still there in my CI probably because of config.eager_load = ENV["CI"].present?

@fxn
Copy link
Contributor

fxn commented Mar 10, 2024

@dorianmariecom The issue happens when eager loading is enabled, Action Cable is not loaded, and Rails is 7.1.2 or above.

I wrote a fix for this in November (#513), but in late January the PR was closed accidentally. I did a cleanup of repos and did not realize that was still not merged (I do not have commit bit in Hotwire).

I have created another PR with the fix (#601).

@dorianmariecom
Copy link

@fxn thx you rock, and yeah I was wondering why the previous pull request was closed

@dhh dhh closed this as completed in #601 Mar 11, 2024
@dorianmariecom
Copy link

Thanks @dhh <3

@EGiataganas
Copy link

@fxn Thanks a lot for the fix, I've just has the same error and realised that is because there is not any new release so I've created a PR. Hope this helps 🙏

mjbellantoni added a commit to mjbellantoni/greysky that referenced this issue Mar 16, 2024
Even if these aren't being used, it turns out that turbo-rails still
tries to autoload them in production. See:

  * hotwired/turbo-rails#478
  * hotwired/turbo-rails#512

There's a workaround for the ActionCable issue but not for the
ActiveJob one, so we just relent and require them.
mjbellantoni added a commit to mjbellantoni/greysky that referenced this issue Mar 16, 2024
Even if these aren't being used, it turns out that turbo-rails still
tries to autoload them in production. See:

  * hotwired/turbo-rails#478
  * hotwired/turbo-rails#512

There's a workaround for the ActionCable issue but not for the
ActiveJob one, so we just relent and require them.
jcoyne added a commit to projectblacklight/spotlight that referenced this issue Jun 21, 2024
it is a test dependency of turbo-rails. See hotwired/turbo-rails#512
corylown pushed a commit to projectblacklight/spotlight that referenced this issue Jun 28, 2024
it is a test dependency of turbo-rails. See hotwired/turbo-rails#512
corylown pushed a commit to projectblacklight/spotlight that referenced this issue Jul 1, 2024
it is a test dependency of turbo-rails. See hotwired/turbo-rails#512
clementf added a commit to clementf/velotrain that referenced this issue Jul 26, 2024
mishina2228 added a commit to mishina2228/youtube-api-trial that referenced this issue Aug 25, 2024
mishina2228 added a commit to mishina2228/youtube-api-trial that referenced this issue Aug 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
7 participants