Consumer.js should be installed by default if ActionCable framework present

:studio_microphone: Is this thing still on?

Over the past 24 hours I’ve finally come to understand that all ActionCable channels which import consumer.js share the same connection to the server. This is a critical first step towards building a scalable AC-powered solution. The alternative is to call createConsumer directly and increase connection overhead linearly. I urge you to directly call out this insight in the Guide; it’s non-obvious that consumer is a memoized instance of a consumer until you’re forced to become an expert.

With apologies for burying the lede, I believe that if the ActionCable framework is present (not-skipped) during rails new, the app/javascript/channels folder should be created automatically. It should contain consumer.js and index.js. import 'channels' should be added to the application.js pack.

These files don’t exist until someone runs rails generate channel test for the first time, and since it’s easily possible to productively import and use createConsumer() in a Stimulus controller without ever running a generator, that means that there’s no consumer.js floating around for all of these consumers to import.

I propose that running a channel generator should only generate the test_channel.rb and test_channel.js, not the infrastructure for using ActionCable in a resource-effective way.

I think we already do all of this in Rails master. Here’s an example Rails app recently generated from master. It has, despite my not having generated any channels:

1 Like

As for the docs, PRs to improve them are very welcome.

1 Like

… of course they are. Thanks, @georgeclaghorn. Not sure how I got turned around on that point.

Now to figure out why some of our users don’t have these files.