This repository has been archived by the owner on Jun 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1385 from gnosis/hotfix/removeChild-crash
Hotfix 🔥 - 1.1.1 [removeChild Node crash]
- Loading branch information
Showing
2 changed files
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* eslint-disable prefer-rest-params */ | ||
export function nodeRemoveChildFix() { | ||
if (typeof Node === 'function' && Node.prototype) { | ||
const originalRemoveChild = Node.prototype.removeChild | ||
Node.prototype.removeChild = function <T extends Node>(child: T): T { | ||
if (child.parentNode !== this) { | ||
if (console) { | ||
console.error('Cannot remove a child from a different parent', child, this) | ||
} | ||
return child | ||
} | ||
return originalRemoveChild.apply(this, arguments as unknown as [child: Node]) as T | ||
} | ||
|
||
const originalInsertBefore = Node.prototype.insertBefore | ||
Node.prototype.insertBefore = function <T extends Node>(newNode: T, referenceNode: Node | null): T { | ||
if (referenceNode && referenceNode.parentNode !== this) { | ||
if (console) { | ||
console.error('Cannot insert before a reference node from a different parent', referenceNode, this) | ||
} | ||
return newNode | ||
} | ||
return originalInsertBefore.apply(this, arguments as unknown as [node: Node, child: Node | null]) as T | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters