Broadcast from model only updates one page when multiple are listening

I was under the impression that broadcasting would allow me to display updates to everyone who is listening to the corresponding stream. I’m trying to broadcast an update from a model while having the relevant pages open in two different browsers while logged in as two separate users in my application. However, only one page actually gets updated, and the other remains the same. What’s worse is that I’m fairly sure that yesterday the same actions have led me to getting both pages updated, but today when I opened the project again, only one page gets updated…

I have a partial that contains the following element:

<div id="counter">
  <%= @user.counter %>
</div>

I render this partial in two separate views, index.html.erb and user/show.html.erb.

In this partial, I subscribe to a turbo stream:

<%= turbo_stream_from "counter_stream_#{@user.id}" %>

I broadcast to this stream from a certain model (not User, if that’s relevant):

after_destroy { broadcast_update_to "counter_stream_#{user.id}", target: "counter", html: "#{user.counter}" }

Let’s say that I opened the index page in one browser, and then on the index page I ended up doing something that triggered after_destroy.

I’ll get the following in the console:

[ActionCable] Broadcasting to counter_stream_1: "<turbo-stream action=\"update\" target=\"counter\"><template>1</template></turbo-stream>"

where 1 is the correct value.

And then I’ll find the following in the console:

Turbo::StreamsChannel transmitting "<turbo-stream action=\"update\" target=\"counter\"><template>1</template></turbo-stream>" (via streamed from counter_stream_1)

And the value on the page will be updated. Great.

Now let’s say I logged in as another user (as a precaution; not sure it’s relevant at all) and opened /users/1 which renders the same partial. I’ll do something on the index page in the first browser that calls after_destroy again.

I’ll get the same messages in the console, and there will be only one message that reads Turbo::StreamsChannel transmitting, and the counter will update on only one of those pages (whichever one, seems to be random). The updated HTML that’s being broadcast is correct, only it doesn’t seem to reach one of the pages.

I suspect this might be due to the fact that every time I load/reload either of the two pages, I get the following in the console:

Finished "/cable" [WebSocket] for 127.0.0.1 at 2024-04-23 11:47:59 +0200
Turbo::StreamsChannel stopped streaming from counter_stream_1

.........

Started GET "/cable" for 127.0.0.1 at 2024-04-23 11:47:59 +0200
Started GET "/cable" [WebSocket] for 127.0.0.1 at 2024-04-23 11:47:59 +0200
Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: keep-alive, Upgrade, HTTP_UPGRADE: websocket)
Turbo::StreamsChannel is transmitting the subscription confirmation
Turbo::StreamsChannel is streaming from counter_stream_1

So, I guess, the stream stops working on one page and only works on the other one? How do I make it… not do that and work on both pages?

Rails 7.0.4, no redis (based on what I’ve found, this might be somewhat relevant?).