Skip to content

Keep connected on turbo-cable-stream-source through morph refreshes - #795

Merged
brunoprietog merged 2 commits into
hotwired:mainfrom
lucidstack:ar/keep-connected-on-morph
Nov 22, 2026
Merged

brunoprietog merged 2 commits into
hotwired:mainfrom
lucidstack:ar/keep-connected-on-morph

Conversation

@lucidstack

Copy link
Copy Markdown
Contributor

Fixes #792

TurboCableStreamSourceElement sets connected on itself once its subscription is up, so the server-rendered turbo_stream_from tag never includes it. When a page refreshes with method: :morph, idiomorph syncs the element's attributes with the new HTML and removes connected — even though the subscription is still live. That makes connect_turbo_cable_stream_sources and the connected: true selector in Turbo::SystemTestHelper wait on (or fail for) a stream that's working just fine.

The element now cancels turbo:before-morph-attribute for its own connected attribute, so it keeps reflecting the subscription's state. The new system test morph-refreshes a message page with broadcast_refresh and checks the stream source is still connected afterwards; it fails without the change 👍

PS: I've included the rebuilt app/assets/javascripts files, as CI checks they're checked in.

@brunoprietog
brunoprietog marked this pull request as ready for review November 22, 2026 20:43
Copilot AI balanced review requested due to automatic review settings November 22, 2026 20:43

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues remain for the change preserving the subscription-managed connected attribute during morph refreshes.

No open issues 🎉

What changed in this PR

Addresses #792 by preserving the subscription-managed connected attribute on turbo-cable-stream-source during morph refreshes, keeping Turbo’s system-test connection checks accurate.

Changes:

  • Prevent morphing from changing the stream source’s own connected attribute.
  • Enable morph refreshes on the dummy message page and add a regression test.
  • Update the checked-in JavaScript bundles with the fix.
File Description
test/​system/​broadcasts_test.rb Tests that a stream source remains marked connected after a broadcast morph refresh.
test/​dummy/​app/​views/​messages/​show.html.erb Enables morph refreshes for the test page.
app/​javascript/​turbo/​cable_stream_source_element.js Cancels morph attribute changes targeting its own connected attribute.
app/​assets/​javascripts/​turbo.min.js Includes the fix in the minified bundle.
app/​assets/​javascripts/​turbo.js Includes the fix in the unminified bundle.

Review effort: Balanced

@brunoprietog brunoprietog left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @lucidstack!

@brunoprietog
brunoprietog merged commit dc0c076 into hotwired:main Nov 22, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants