hotwired/turbo-rails

Shouldn't broadcast refresh if streamables == [nil]

ConfusedVorlon opened this issue · 1 comments

In the case where my model has an optional association

class Booking < AccountRecord

  has_one :jump, dependent: :destroy
  broadcasts_refreshes_to :jump

end

if booking is edited, but jump is nil, then this ends up calling

#models/concerns/turbo/broadcastable.rb
broadcast_refresh_later_to(nil)

which ultimately calls

#app/channels/turbo/streams/broadcasts
  def broadcast_refresh_later_to(*streamables, request_id: Turbo.current_request_id, **opts)
    refresh_debouncer_for(*streamables, request_id: request_id).debounce do
     
      Turbo::Streams::BroadcastStreamJob.perform_later stream_name_from(streamables), content: turbo_stream_refresh_tag(request_id: request_id, **opts)
    end
  end

streamables is nil, so stream_name_from(streamables) is ""

Somewhere along the line, I assume TurboRails should just noop if the stream name is empty. I'm not exactly sure where...

perhaps???

#app/channels/turbo/streams/broadcasts
  def broadcast_refresh_later_to(*streamables, request_id: Turbo.current_request_id, **opts)
    refresh_debouncer_for(*streamables, request_id: request_id).debounce do
      stream_name = stream_name_from(streamables)
      unless stream_name.blank?  Turbo::Streams::BroadcastStreamJob.perform_later stream_name, content: turbo_stream_refresh_tag(request_id: request_id, **opts)
    end
  end

As an aside, the empty argument gives solid_queue a headache which is how I found this....

Thank you for opening this issue and its predecessor, as well as all the due diligence that went into investigating the root cause.

I've opened #615 to try and guard against these cases.