mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-02-04 14:33:47 +00:00
fix Node.replaceChild when of new child equals old
This commit is contained in:
@@ -37,4 +37,7 @@
|
|||||||
testing.expectEqual(null, c2.parentNode);
|
testing.expectEqual(null, c2.parentNode);
|
||||||
assertChildren([c3, c4], d1)
|
assertChildren([c3, c4], d1)
|
||||||
assertChildren([], d2)
|
assertChildren([], d2)
|
||||||
|
|
||||||
|
testing.expectEqual(c3, d1.replaceChild(c3, c3));
|
||||||
|
assertChildren([c3, c4], d1)
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -500,6 +500,21 @@ pub fn replaceChild(self: *Node, new_child: *Node, old_child: *Node, page: *Page
|
|||||||
|
|
||||||
try validateNodeInsertion(self, new_child);
|
try validateNodeInsertion(self, new_child);
|
||||||
|
|
||||||
|
// special case: we replace a node by itself
|
||||||
|
if (new_child == old_child) {
|
||||||
|
page.domChanged();
|
||||||
|
|
||||||
|
if (page.hasMutationObservers()) {
|
||||||
|
const parent = new_child._parent.?;
|
||||||
|
const previous_sibling = new_child.previousSibling();
|
||||||
|
const next_sibling = new_child.nextSibling();
|
||||||
|
const replaced = [_]*Node{new_child};
|
||||||
|
page.childListChange(parent, &replaced, &replaced, previous_sibling, next_sibling);
|
||||||
|
}
|
||||||
|
|
||||||
|
return old_child;
|
||||||
|
}
|
||||||
|
|
||||||
_ = try self.insertBefore(new_child, old_child, page);
|
_ = try self.insertBefore(new_child, old_child, page);
|
||||||
page.removeNode(self, old_child, .{ .will_be_reconnected = false });
|
page.removeNode(self, old_child, .{ .will_be_reconnected = false });
|
||||||
return old_child;
|
return old_child;
|
||||||
|
|||||||
Reference in New Issue
Block a user