Let templates have plaintext as contents (fixes 2702) (#2708)

let templates have plaintext as contents (fixes 2702)
This commit is contained in:
Kuberdenis 2024-07-12 20:11:42 +03:00 committed by GitHub
parent d9eb6d74f8
commit 0f3b2b4a92
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1854,7 +1854,7 @@ var htmx = (function() {
findAndSwapOobElements(fragment, settleInfo)
forEach(findAll(fragment, 'template'), /** @param {HTMLTemplateElement} template */function(template) {
findAndSwapOobElements(template.content, settleInfo)
if (template.content.childElementCount === 0) {
if (template.content.childElementCount === 0 && template.content.textContent.trim() === '') {
// Avoid polluting the DOM with empty templates that were only used to encapsulate oob swap
template.remove()
}