From 002e347ab4339b1e8384be2ffc1f5262820f383b Mon Sep 17 00:00:00 2001 From: Zee Spencer <50284+zspencer@users.noreply.github.com> Date: Sun, 2 Apr 2023 11:36:22 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=9B=A0=EF=B8=8F=20`Component`:=20`ButtonC?= =?UTF-8?q?omponent`=20supports=20`GET`=20Turbo=20Streams?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - https://github.com/zinc-collective/convene/issues/1187 - https://turbo.hotwired.dev/handbook/streams#streaming-from-http-responses It turns out that `Turbo` only does turbo-streams when `PUT`/`POST`/`DELETE` are the request methods. If we want to make `GET` requests use the `turbo-stream` request type, we need to specify it in the HTML output, i.e. `` I wasn't sure if this should be default behavior or not, so I leaned towards making it default to not 🤷 --- app/components/button_component.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/components/button_component.rb b/app/components/button_component.rb index 13442fb54..dff6268a0 100644 --- a/app/components/button_component.rb +++ b/app/components/button_component.rb @@ -8,7 +8,8 @@ def initialize( method: :put, confirm: nil, disabled: false, - classes: nil + classes: nil, + turbo_stream: nil ) @label = label @title = title @@ -17,6 +18,7 @@ def initialize( @confirm = confirm @disabled = disabled @classes = classes + @turbo_stream = turbo_stream end attr_accessor :classes @@ -25,6 +27,7 @@ def initialize( def data data = {turbo_method: @method, turbo: true} + data[:turbo_stream] = true if @turbo_stream if @confirm.present? data[:turbo_confirm] = @confirm data[:confirm] = @confirm