As connectedCallback/disconnectedCallback do not fire in an already disconnected tree, this results in inconsistent and buggy behavior.
Works as expected: parent2 contains all the children.
const parent1 = document.createElement("div")
parent1.style.background = "hsl(0 40% 60%)"
const parent2 = document.createElement("div")
parent2.style.background = "hsl(200 40% 60%)"
document.body.append(parent1, parent2)
const group = new Group
group.append("123", "456", "789")
parent1.append(group) // So far behaves exactly like `DocumentFragment`.
parent2.append(group) // The difference is that the nodes are actually moved.
group.append("000")
// document.body.append(parent1, parent2)
Does not work as expected: parent1 still contains all the children.
const parent1 = document.createElement("div")
parent1.style.background = "hsl(0 40% 60%)"
const parent2 = document.createElement("div")
parent2.style.background = "hsl(200 40% 60%)"
// document.body.append(parent1, parent2)
const group = new Group
group.append("123", "456", "789")
parent1.append(group) // So far behaves exactly like `DocumentFragment`.
parent2.append(group) // The difference is that the nodes are actually moved.
group.append("000")
document.body.append(parent1, parent2)
This can be partially mitigated if there is no separation between Group and GroupRelay, and instead there is a single custom element acting as the relay with all methods overridden.
It still would not work correctly in disconnected trees, in the sense that only the relay elements would exist without their contents, but at least it would behave correctly once attached.
As
connectedCallback/disconnectedCallbackdo not fire in an already disconnected tree, this results in inconsistent and buggy behavior.Works as expected:
parent2contains all the children.Does not work as expected:
parent1still contains all the children.This can be partially mitigated if there is no separation between
GroupandGroupRelay, and instead there is a single custom element acting as the relay with all methods overridden.It still would not work correctly in disconnected trees, in the sense that only the relay elements would exist without their contents, but at least it would behave correctly once attached.