Document data-turbo-stream attribute#103
Document data-turbo-stream attribute#103dhh merged 1 commit intohotwired:mainfrom kevinmcconnell:document-data-turbo-stream
data-turbo-stream attribute#103Conversation
✅ Deploy Preview for epic-fermat-9d85e9 ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
| * `data-turbo-cache="false"` removes the element before the document is cached, preventing it from reappearing on restoration Visits. | ||
| * `data-turbo-eval="false"` prevents inline `script` elements from being re-evaluated on Visits. | ||
| * `data-turbo-method` changes the link request type from the default `GET`. Ideally, non-`GET` requests should be triggered with forms, but `data-turbo-method` might be useful where a form is not possible. | ||
| * `data-turbo-stream="true"` specifies that a link or form should request a Turbo Streams response. Turbo [automatically requests stream responses](/handbook/streams#streaming-from-http-responses) for form submissions with non-`GET` methods; `data-turbo-stream` allows Turbo Streams to be used with `GET` requests as well. |
There was a problem hiding this comment.
Something that wasn't clear to me in hotwired/turbo#612... does it still also accept a HTML response? If yes, maybe this could be more clear:
| * `data-turbo-stream="true"` specifies that a link or form should request a Turbo Streams response. Turbo [automatically requests stream responses](/handbook/streams#streaming-from-http-responses) for form submissions with non-`GET` methods; `data-turbo-stream` allows Turbo Streams to be used with `GET` requests as well. | |
| * `data-turbo-stream="true"` specifies that a link or form can also accept a Turbo Streams response. Turbo [automatically requests stream responses](/handbook/streams#streaming-from-http-responses) for form submissions with non-`GET` methods; `data-turbo-stream` allows Turbo Streams to be used with `GET` requests as well. If the server returns a HTML response then navigation proceeds as normal; if the server returns a Turbo Stream response then it is processed as a Turbo Stream. |
There was a problem hiding this comment.
@ghiculescu thanks, that's a good point. I think your wording of "can accept" makes this clearer. I've updated the description to use that.
I've also added a note in the Handbook section that it references to explain in a bit more detail, which also should make this option easier to discover.
What do you think?
There was a problem hiding this comment.
@kevinmcconnell thanks a ton for this. It's extremely useful.
Just a bit confused by why an HTML request gets sent after the turbo stream request. Is there a way to prevent that if all we want is a turbo stream response?
There was a problem hiding this comment.
@jusko there should still only be one request. Adding data-turbo-stream means that request can accept either a stream response, or a regular HTML response.
There was a problem hiding this comment.
🤔 Forgive my ignorance @kevinmcconnell... I only glanced at the turbo code quickly, but using it in my client code produces the following:
The last two roundtrips relate to:
2. the turbo stream response after clicking a link with data-turbo-stream (working as expected)
3. a 406 response to a separate request (sent with Content-Type: text/html in the headers) also sent when clicking the link (the controller only responds to the turbo stream format).
I understand this isn't really the place to discuss this, but on the off chance anyone else experiences this, hopefully it's worth it. I will look into it more when there's time and update.
Thanks again for the new functionality. Extremely useful!
There was a problem hiding this comment.
@jusko oh interesting! That definitely sounds like a bug. I hadn’t seen that myself but I will also try to look into it when I get a chance. The intended behaviour is that a single request is sent. Thanks for bringing this up!
I wonder if this is related to the issue that’s being addressed by hotwired/turbo#645.
Also worth mentioning, we’ve discussed changing how data-turbo-stream works under the hood (see hotwired/turbo#641 (comment)), and I believe @seanpdoyle is planning to open a PR for that change. So once that’s ready it could be worth testing against that version as well.
Documents the `data-turbo-stream` attribute introduced in hotwired/turbo#612.

Documents the
data-turbo-streamattribute introduced in hotwired/turbo#612.