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

Hotfix 🔥 - 1.1.1 [removeChild Node crash] #1385

Merged
merged 1 commit into from
Sep 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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