-
Notifications
You must be signed in to change notification settings - Fork 436
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
Make StreamElement.templateElement
more flexible
#665
Conversation
Prior to this commit, the `StreamElement.templateElement` property would raise an error if it were called without a `<template>` descendant. However, a `<turbo-stream action="remove">` element without a descendant `<template>` element is valid and supported. When called on a `<turbo-stream>` that has a `firstElementChild` that _is not_ a `<template>` element will continue to raise an exception. When called without _any_ child elements, `StreamElement.templateElement` will create and append a `<template>` element. Since listeners to the `turbo:before-stream-render` event now have access to the `StreamElement` creating, appending, and returning a `<template>` element will provide them with an opportunity to manipulate the element from their event listener if they choose to.
This fixes #664 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You rock @seanpdoyle!
Just ran into this as well. Any chance we could get a beta3 release with this? |
In the short-term, are you able to target https://github.com/hotwired/dev-builds/releases/tag/%40hotwired%2Fturbo%2Flatest or https://github.com/hotwired/dev-builds/releases/tag/%40hotwired%2Fturbo%2Fc4e0aba in your |
Sure can. 👍 |
@excid3 if you're using turbo-rails see this message https://discord.com/channels/988103760050012160/988104775079968849/1006524274540023808 ⬇️ (if you don't want to open discord)
|
Awesome, thanks @marcelolx 👍 |
Just as a note, if anyone is using importmaps and wants to target a version that includes this fix, I've done so using It turns out that targeting files directly on Github doesn't work however jdselivr.net provides a proxy. |
Prior to this commit, the
StreamElement.templateElement
property wouldraise an error if it were called without a
<template>
descendant.However, a
<turbo-stream action="remove">
element without a descendant<template>
element is valid and supported.When called on a
<turbo-stream>
that has afirstElementChild
thatis not a
<template>
element will continue to raise an exception.When called without any child elements,
StreamElement.templateElement
will create and append a<template>
element.
Since listeners to the
turbo:before-stream-render
event now haveaccess to the
StreamElement
creating, appending, and returning a<template>
element will provide them with an opportunity to manipulatethe element from their event listener if they choose to.