Skip to content

Commit

Permalink
Only call remove/insert hooks for element parents
Browse files Browse the repository at this point in the history
  • Loading branch information
jakearchibald committed Sep 11, 2024
1 parent 65a7329 commit 7634d8f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/polyfill/source/ParentNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ export class ParentNode extends ChildNode {
}
}

this[HOOKS].removeChild?.(this as any, child as any, childNodesIndex);
if (this.nodeType === NodeType.ELEMENT_NODE) {
this[HOOKS].removeChild?.(this as any, child as any, childNodesIndex);
}
}

replaceChild(newChild: Node, oldChild: Node) {
Expand Down Expand Up @@ -162,12 +164,15 @@ export class ParentNode extends ChildNode {
if (isElement) this.children.push(child);
}

this[HOOKS].insertChild?.(this as any, child as any, insertIndex);
if (this[IS_CONNECTED]) {
for (const node of inclusiveDescendants(child)) {
node[IS_CONNECTED] = true;
(node as any).connectedCallback?.();
}
}

if (this.nodeType === NodeType.ELEMENT_NODE) {
this[HOOKS].insertChild?.(this as any, child as any, insertIndex);
}
}
}

0 comments on commit 7634d8f

Please sign in to comment.