fix: more lightweight replaceChildren polyfill

This commit is contained in:
Nolan Lawson 2023-12-17 12:01:05 -08:00
parent 472a27bc24
commit ea25409acb
1 changed files with 3 additions and 7 deletions

View File

@ -17,13 +17,9 @@ function replaceChildren (parentNode, newChildren) {
/* istanbul ignore else */
if (hasReplaceChildren) {
parentNode.replaceChildren(...newChildren)
} else { // polyfill Element.prototype.replaceChildren
while (parentNode.lastChild) {
parentNode.removeChild(parentNode.lastChild)
}
for (const child of newChildren) {
parentNode.appendChild(child)
}
} else { // minimal polyfill for Element.prototype.replaceChildren
parentNode.innerHTML = ''
parentNode.append(...newChildren)
}
}