diff --git a/.changeset/lovely-toys-reflect.md b/.changeset/lovely-toys-reflect.md new file mode 100644 index 00000000..3558c855 --- /dev/null +++ b/.changeset/lovely-toys-reflect.md @@ -0,0 +1,5 @@ +--- +"@chialab/dna": patch +--- + +Fix render cycle cleanup. diff --git a/src/render.ts b/src/render.ts index 77eb8492..a5a7cd71 100644 --- a/src/render.ts +++ b/src/render.ts @@ -670,7 +670,11 @@ export const internalRender = ( } while (currentIndex <= --end) { - context.node.removeChild(contextChildren.splice(end, 1)[0].node); + const [child] = contextChildren.splice(end, 1); + const parentNode = child.node.parentNode; + if (parentNode === context.node || (realm?.open && parentNode === realm.node && realm.root === context.node)) { + context.node.removeChild(child.node); + } } return contextChildren;