Skip to content

Commit

Permalink
Fix references after node removal (#472)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakearchibald authored Oct 29, 2024
1 parent 5f4ae17 commit 1473a3c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/serious-ladybugs-bow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@remote-dom/polyfill': patch
---

Fix removeChild so it clears parent/sibling references
5 changes: 5 additions & 0 deletions .changeset/warm-oranges-rest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@remote-dom/polyfill': patch
---

Add node.parentElement
8 changes: 8 additions & 0 deletions packages/polyfill/source/Node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ export class Node extends EventTarget {

set parentNode(_readonly) {}

get parentElement(): ParentNode | null {
const parent = this[PARENT];
if (!parent || parent.nodeType !== 1) return null;
return parent;
}

set parentElement(_readonly) {}

get previousSibling() {
return this[PREV];
}
Expand Down
4 changes: 4 additions & 0 deletions packages/polyfill/source/ParentNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ export class ParentNode extends ChildNode {
children.splice(children.indexOf(child), 1);
}

child[PARENT] = null;
child[NEXT] = null;
child[PREV] = null;

if (this[IS_CONNECTED]) {
for (const node of selfAndDescendants(child)) {
node[IS_CONNECTED] = false;
Expand Down

0 comments on commit 1473a3c

Please sign in to comment.