// Safeguard React DOM reconciliation against external node mutations if (typeof Node === 'function' && Node.prototype) { const origRemoveChild = Node.prototype.removeChild; Node.prototype.removeChild = function (child) { if (child && child.parentNode !== this) { if (console && console.warn) console.warn('Protected from removeChild error: node is not child of parent.', child, this); return child; } return origRemoveChild.apply(this, arguments); }; const origInsertBefore = Node.prototype.insertBefore; Node.prototype.insertBefore = function (newNode, refNode) { if (refNode && refNode.parentNode !== this) { if (console && console.warn) console.warn('Protected from insertBefore error: refNode is not child of parent.', refNode, this); return this.appendChild(newNode); } return origInsertBefore.apply(this, arguments); }; }