Fix handling of document fragments in renderer

This commit is contained in:
Talia 2024-07-31 09:30:17 +02:00
parent 6bd29f05dc
commit e763312f06

View file

@ -173,6 +173,8 @@ export class DomRenderer extends Renderer {
element.append(child) element.append(child)
else if (typeof arg == "function") else if (typeof arg == "function")
this.apply(element, arg(element) || empty) this.apply(element, arg(element) || empty)
else if (arg instanceof DocumentFragment)
element.append(arg)
else if (arg && typeof(arg)=="object") else if (arg && typeof(arg)=="object")
for (const key in arg) for (const key in arg)
if (element instanceof Element) if (element instanceof Element)
@ -225,6 +227,9 @@ export class DomRenderer extends Renderer {
* @return {Element|Text} * @return {Element|Text}
*/ */
static toReactiveElement(observable) { static toReactiveElement(observable) {
if (observable.value instanceof DocumentFragment) {
throw "Failed to create reactive element: Document fragments cannot be replaced dynamically"
}
const element = this.toElement(observable.value) const element = this.toElement(observable.value)
untilDeathDoThemPart(element, observable) untilDeathDoThemPart(element, observable)
let ref = new WeakRef(element) let ref = new WeakRef(element)