4

I have a Turbo Stream which is not updating the view and I'm not sure why. I have two other broadcasts setup in a similar configuration which are working fine.

Everything looks like it should be working from what I can see, I'm just not getting the update on the front end. Am I missing something obvious?

# partial
<%= turbo_stream_from 'team_players' %>
<div id="players_<%= dom_id(team)%>"
    <% team.players.each do |player| %>
        <%= render player %>
    <% end %>
</div>
# player model
class Player < ApplicationRecord
belongs_to :team

    after_create_commit  do
        broadcast_prepend_to(
            'team_players',
            target: "players_team_#{team.id}",
            locals: { player: self }
        )

    end
end
# server log
Started GET "/cable" for 127.0.0.1 at 2022-02-16 11:45:13 +0000
Started GET "/cable/" [WebSocket] for 127.0.0.1 at 2022-02-16 11:45:13 +0000
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 team_players

# console log after manually creating a player for team 9 (exert)
...
 Rendered players/_player.html.erb (Duration: 0.3ms | Allocations: 99)
[ActionCable] Broadcasting to team_players: "<turbo-stream action=\"prepend\" target=\"players_team_9\"><template><div id=\"player_1885\">\n  <p>\n    <strong>ID:</strong>\n    1885\n  </p>\n\n  <p>\n    <strong>User:</strong>\n    3820748f-d9d3-400e-ac90-6149800a0e68\n  </p>\n\n  <p>\n    <strong>Team:</strong>\n    9\n  </p>\n\n  <p>\n   ...
=> 
#<Player:0x00007fba5fa12568
...

Any help or pointers are appreciated!

Phil-6
  • 552
  • 6
  • 16

1 Answers1

8

It looks as though I had missed Step 4 in the turbo-rails installation process: https://github.com/hotwired/turbo-rails#installation

After running: ./bin/rails turbo:install:redis everything worked from the command line.

Without that step, things still worked from a separate browser session.

Thanks to David Colby on Twitter for finding the fix.

Phil-6
  • 552
  • 6
  • 16
  • indeed "The Async adapter does not support Turbo Stream broadcasting", thank you! – user1519240 Jun 19 '23 at 17:17
  • Just had similar. I hadn't specified the redis url in config/cable.yml for development. The OP, after seeing the broadcasting message in the console, should have seen a line appear in the server log: Turbo::StreamsChannel transmitting " – jnicho02 Jun 23 '23 at 08:42
  • Just got got by this. Is there an error message that we're supposed to have caught to see that something isn't properly configured? as far as i can tell it's a totally silent failure – aidan Jul 11 '23 at 18:41