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 |
|
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.templateElementproperty 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 afirstElementChildthatis not a
<template>element will continue to raise an exception.When called without any child elements,
StreamElement.templateElementwill create and append a<template>element.
Since listeners to the
turbo:before-stream-renderevent now haveaccess to the
StreamElementcreating, appending, and returning a<template>element will provide them with an opportunity to manipulatethe element from their event listener if they choose to.