From 538944699660db6a9544e4e6abfa3d75044f085c Mon Sep 17 00:00:00 2001 From: Douglas Hall Date: Tue, 4 Jun 2019 14:42:43 -0400 Subject: [PATCH] Fix JS error possibly caused by browser plugins. --- src/index.jsx | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/index.jsx b/src/index.jsx index fd94553..f26201f 100755 --- a/src/index.jsx +++ b/src/index.jsx @@ -57,10 +57,30 @@ function configure() { }; } +/* + ARCH-904 + Attempts to protect against browser extension manipulation of the DOM which + causes React to break. See the following link: + https://github.com/facebook/react/issues/11538#issuecomment-417504600 +*/ +function monkeyPatchDOMManipulation() { + if (typeof Node === 'function' && Node.prototype) { + const originalInsertBefore = Node.prototype.insertBefore; + Node.prototype.insertBefore = function (newNode, referenceNode, ...args) { + if (referenceNode && referenceNode.parentNode !== this) { + NewRelicLoggingService.logError(`Cannot insert before a reference node from a different parent: ${referenceNode} ${this}`); + return newNode; + } + return originalInsertBefore.apply(this, [newNode, referenceNode, ...args]); + }; + } +} + apiClient.ensurePublicOrAuthenticationAndCookies( window.location.pathname, () => { const { store, history } = configure(); + monkeyPatchDOMManipulation(); ReactDOM.render(, document.getElementById('root'));