Skip to content

Broadcast Updatable changes to String stream names (fixes record updates under AnyCable 1.5+) - #312

Open
yshmarov wants to merge 1 commit into
stimulusreflex:mainfrom
yshmarov:fix/updatable-string-broadcasting
Open

yshmarov wants to merge 1 commit into
stimulusreflex:mainfrom
yshmarov:fix/updatable-string-broadcasting

Conversation

@yshmarov

Copy link
Copy Markdown

Type of PR

Bug fix

Description

CableReady::Updatable#broadcast_updates passes the model class, and for record updates the record's GlobalID object, straight to ActionCable.server.broadcast (updatable.rb#L198, #L201; callers in model_updatable_callbacks.rb#L21-L29). Subscribers stream from compound(keys), a String built with to_global_id.to_s (view_helper.rb#L54-L57, compoundable.rb#L5-L9).

Stock Action Cable calls String(broadcasting) in broadcaster_for (Rails main; same in 7.2), so the two sides agree. Since anycable-rails 1.5 (anycable/anycable-rails@594f339), broadcaster_for runs non-String broadcastings through AnyCable::Rails.stream_name_from, i.e. try(:to_gid_param) || to_param (broadcast_options.rb#L14-L17, rails.rb#L64-L70).

GlobalID#to_param is base64, so record updates are published to Z2lkOi8v... while the cable_ready_updates_for(record) element listens on gid://.... Those updates are silently dropped. The extension is loaded by the railtie whatever adapter is configured, so this happens with the async and test adapters too.

This change builds the broadcasting with compound, the same helper the subscribe side uses, so ActionCable.server.broadcast always receives a String. On stock Action Cable the resulting name is the same as before (String(User) == "User", String(gid) == gid.to_s), so this is a no-op there.

Why should this be added

In apps running anycable-rails >= 1.5, cable_ready_updates_for(record) stops receiving updates. Class-level and collection-level updates are unaffected. Without this fix, the workaround is to override ActionCable::Server::Base#broadcaster_for app-wide, which also disables AnyCable's own handling of streamable broadcastings.

Tests

  • New test asserting that every broadcasting from a record update is a String equal to the subscriber's compound stream name. It fails without the fix.
  • Existing expectations updated from User / user.to_global_id to "User" / user.to_global_id.to_s.
  • bundle exec rake test: 89 runs, 0 failures.

Checklist

  • My code follows the style guidelines of this project
  • Checks (StandardRB & Prettier-Standard) are passing (no JS changed)

CableReady::Updatable passed the model class and the record's GlobalID
object to ActionCable.server.broadcast, while subscribers stream from
compound(keys), a String. Stock Action Cable calls String() on the
broadcasting, so the names matched, but servers that transform
non-String broadcastings (AnyCable 1.5+ uses to_gid_param/to_param,
which base64-encodes a GlobalID) publish record updates to a stream
nobody subscribes to.

Build the broadcasting with compound, like the subscribe side does.
@netlify

netlify Bot commented Nov 14, 2026

Copy link
Copy Markdown

👷 Deploy request for cableready pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 8774073

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant