Skip to content
This repository has been archived by the owner on Jun 24, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1385 from gnosis/hotfix/removeChild-crash
Browse files Browse the repository at this point in the history
Hotfix 🔥 - 1.1.1 [removeChild Node crash]
  • Loading branch information
W3stside authored Sep 3, 2021
2 parents d8cdf60 + f8aed4e commit 23bb5b4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/custom/utils/node.ts
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
}
}
}
5 changes: 5 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ import ThemeProvider, { FixedGlobalStyle, ThemedGlobalStyle } from 'theme'
import getLibrary from './utils/getLibrary'
import { analyticsId } from './custom/utils/analytics'
import AppziButton from 'components/AppziButton'
import { nodeRemoveChildFix } from 'utils/node'

// Node removeChild hackaround
// based on: https://github.com/facebook/react/issues/11538#issuecomment-417504600
nodeRemoveChildFix()

const Web3ProviderNetwork = createWeb3ReactRoot(NetworkContextName)

Expand Down

0 comments on commit 23bb5b4

Please sign in to comment.