-
Notifications
You must be signed in to change notification settings - Fork 434
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
The documentation does not mention that Stream Action tags can be rendered inside any HTML #1258
The documentation does not mention that Stream Action tags can be rendered inside any HTML #1258
Comments
I've personally relied on the behavior that you've described. For example, you can nest a <script>
addEventListener("click", ({ target }) => {
const button = target.closest("button")
const template = button.querySelector("template")
document.body.append(template.content.cloneNode(true))
})
</script>
<button type="button" id="call-to-action">
<span>Click me to insert the template's contents after this button!</span>
<template>
<turbo-stream action="after" target="call-to-action">
<template><p>You clicked the button!</p></template>
</turbo-stream>
</template>
</button> |
Glad to hear that. :) I've used, in production, stream tags inside frame response (for extra side-effects) and inside the initial page load HTML (for interacting with some legacy JS). |
I think outlining these possibilities at a high level in the Streams Handbook section and in greater detail in Streams Reference section would be a big improvement! |
Great, I'll prepare something soon. 👍 |
@seanpdoyle I've opened two PRs to address this. One to extend the documentation: hotwired/turbo-site#192 And one to add a test ensuring no regressions of this functionality: #1263 Happy to iterate on both based on feedback. :) |
The way Turbo is currently implemented, stream tags will be processed and executed when they are rendered anywhere in HTML.
Here is a minimal example with a static HTML page:
This will work anywhere where stream tags are rendered into the page DOM:
Not all of those are smart ways to use it but I was surprised that the documentation makes no mention of the feature. At least I couldn't find any mention anywhere in the documentation or old release notes.
I am guessing that the reason is that this is a side-effect of how
StreamElements
are implemented: They are defined as customElements with the stream tag execution being triggered by theconnectedCallback
implementation of theStreamElement
class.Perhaps it's just me and most other people find this clear without being mentioned but I think it would still be worth adding a few sentences and a documentation and a test to cover it. This can be a very useful feature in some cases.
I'd be very happy to mention this in the documentation but wanted to first check if there is something I am missing?
Can someone confirm that this is an intentional Turbo feature that should be mentioned explicitly in the documentation? If not, can we make it an official feature. Considering how it's implemented, one would have to do add explicit hacks just to stop it from working.
The text was updated successfully, but these errors were encountered: