Skip to content

Feature Request: Connection status tracking #865

@mbell697

Description

@mbell697

It can be very useful to know when a stimulus controller has connected, particularly in automated testing environments. While possible to work around this externally, Stimulus is aware of all the needed information, it's just not communicated externally at the moment.

What I would propose is:

  1. For each controller element, automatically add a connected attribute after the completion of connect() for the given controller. This is analogous to how action cable indicates connection, or inversely how busy state is communicated in Hotwire. Since this won't be a custom element, some more thought is warranted here on the final name of the attribute.

  2. Manage a fully-connected (name?) attribute on the html element indicating that all controller elements on the page are connected. This isn't required, but would be nice to have since Stimulus is already listening to all the events/mutations needed to handle this. It would also be very nice to have callbacks/events fired here.

Either or both of these would make is easier and faster for test suites to wait to interact with the page until controllers are connected.

If either of these ideas are acceptable, I'm happy to provide a PR.

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