Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ConfusedVorlon opened this issue Apr 11, 2024 · 1 comment · May be fixed by #615
Open

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

ConfusedVorlon opened this issue Apr 11, 2024 · 1 comment · May be fixed by #615

Comments

@ConfusedVorlon
Copy link

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....

seanpdoyle added a commit to seanpdoyle/turbo-rails that referenced this issue Apr 12, 2024
Closes [hotwired#614][]

When broadcasting, ignore `""` and `nil` values, especially when they
are the only values when generating the streamable channel name and
content.

[hotwired#614]: hotwired#614
@seanpdoyle seanpdoyle linked a pull request Apr 12, 2024 that will close this issue
@seanpdoyle
Copy link
Contributor

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.

seanpdoyle added a commit to seanpdoyle/turbo-rails that referenced this issue Apr 12, 2024
Closes [hotwired#614][]

When broadcasting, ignore `""` and `nil` values, especially when they
are the only values when generating the streamable channel name and
content.

[hotwired#614]: hotwired#614
seanpdoyle added a commit to seanpdoyle/turbo-rails that referenced this issue Apr 12, 2024
Closes [hotwired#614][]

When broadcasting, ignore `""` and `nil` values, especially when they
are the only values when generating the streamable channel name and
content.

[hotwired#614]: hotwired#614
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants