Description
Bug Report
Describe the bug
Thanks to @javid-gulamaliyev, we were able to figure out that in the current version of StimulusReflex you can't use StimulusReflex and the Session Store if you are running ActionCable as a standalone server.
It fails to commit the session with:
Failed to commit session! undefined method `commit_session' for nil:NilClass
/usr/local/bundle/gems/stimulus_reflex-3.5.0.rc2/app/channels/stimulus_reflex/channel.rb:101
The issue is this part:
reflex.request.session
is just available in the web-server process and since this is executed in the context of the separate ActionCable server process it has no access to the session, which is also stated in the Rails docs.
> The WebSocket server doesn't have access to the session, but it has access to the cookies. [...]
So I'm not sure if we can actually support the standalone ActionCable server with StimulusReflex, but either we could improve the commit_session
method in channel.rb
to check if we actually have access to the session and if not show a more helpful warning or trying to detect if ActionCable is running in the standalone mode so we can print a warning and warn the user early.
To Reproduce
- Create new Rails app
- Run the StimulusReflex installer
- Configure the ActionCable standalone server
- Configure the
session_store
in your environmentRails.application.configure do config.cache_store = :redis_cache_store, { url: ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } } config.session_store :cache_store, key: "_sessions_development", compress: true, pool_size: 5, expire_after: 1.year end
Expected behavior
Either it should just work and start to commit to the session and don't show the error or it should catch the exception and warn the user that it might be caused by running the ActionCable server in standalone mode.
Versions
StimulusReflex
- Gem: 3.5.0.rc2
- Node package: 3.5.0-rc2
External tools
- Ruby: 3.2.2
- Rails: 7.0.4
- Node: 18.10.0