I have a challenge that I suspect more people encounter. I have a form where a user creates a
Vehicle. After you successfully post that form you are redirected back to the index with all your vehicles.
Now comes the issue; in the background, an ActionStream is enqueued to Sidekiq, if that job takes a while it could arrive after the user is already looking at the dashboard with the new record on it. If this happens you see two divs with the same content.
Is there a way for Turbo to make sure it doesn’t insert the same
id if it already exists on the page? I could solve this with a Stimulus controller, but doesn’t seem ideal.
My ruby code is super simple:
class Vehicle < ApplicationRecord broadcasts_to :account end
And I listed to changed like this:
<%= turbo_stream_from current_account %>
Hope someone has a suggestion on how to combat this race condition.