diff --git a/src/custom/utils/node.ts b/src/custom/utils/node.ts new file mode 100644 index 000000000..cf7c68990 --- /dev/null +++ b/src/custom/utils/node.ts @@ -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 (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 (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 + } + } +} diff --git a/src/index.tsx b/src/index.tsx index dbae61f86..c484c6bbc 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -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)