Skip to content

StimulusReflex is not compatible with the standalone ActionCable server #666

Open
@marcoroth

Description

@marcoroth

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:

store = reflex.request.session.instance_variable_get(:@by)

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions