Solving the double append problem

In the intro video on, DHH runs into the double append problem when he introduces stream updates over ActionCable (websocket): the user who posts in chat see their new message twice since it’s appended once through the form submission response and once over the websocket.

He solves the problem by removing the append from the form submission response.

This means that if the user who posts in chat isn’t connected to the websocket, they won’t see their new message at all.

Have you found any general solution to this problem that doesn’t have the same drawback?

1 Like

I’ve been taking a crack at this in [RFC] Add remove_if_present to append and prepend (avoids double-insert) by jeromecornet · Pull Request #153 · hotwired/turbo-rails · GitHub

Feel free to chime in on this approach