@override Node? replaceChild(Node newNode, Node oldNode) { if (documentElement == oldNode) { documentElement = newNode is Element ? newNode : null; } return super.replaceChild(newNode, oldNode); }