Skip to content

Morph refreshes strip connected from turbo-cable-stream-source #792

Closed

Description

@lucidstack

TurboCableStreamSourceElement sets connected itself once its subscription is up (#430), so the server-rendered turbo_stream_from tag never includes it. When Turbo morphs the page (turbo_refreshes_with method: :morph), idiomorph syncs the element's attributes from the new HTML and removes connected. The subscription itself carries on fine, but the element now looks disconnected.

That trips Turbo::SystemTestHelper: connect_turbo_cable_stream_sources (run after visit by default) and the :turbo_cable_stream_source, connected: true selector both rely on [connected], so after any morph refresh they wait on, or fail for, a stream that's actually live.

To reproduce:

  1. A page with turbo_refreshes_with method: :morph and turbo_stream_from @record.
  2. Visit it and wait for turbo-cable-stream-source[connected].
  3. Trigger @record.broadcast_refresh.
  4. turbo-cable-stream-source[connected] is gone, even though later broadcasts still arrive.

A fix could be for the element to cancel turbo:before-morph-attribute for connected on itself. We're working around it in our app with a document-level listener that does the same:

document.addEventListener("turbo:before-morph-attribute", (event) => {
  if (event.target.localName === "turbo-cable-stream-source" && event.detail.attributeName === "connected") {
    event.preventDefault()
  }
})

Happy to open a PR if that sounds like the right direction! 🙇

Activity

  1. seanpdoyle commented on Oct 30, 2026

    @seanpdoyle
    Contributor

    @lucidstack thank you for opening this issue. The solution that you've proposed sounds like a welcomed improvement. Please open a pull request.

  2. lucidstack commented on Nov 15, 2026

    @lucidstack
    ContributorAuthor

    @seanpdoyle thank you! I've opened #795 with the fix on the element itself, plus a test that connected survives a morph refresh 🙇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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