diff --git a/app/main.cjsx b/app/main.cjsx index c7b31595c8..5bc6d393aa 100644 --- a/app/main.cjsx +++ b/app/main.cjsx @@ -3,12 +3,14 @@ ReactDOM = require 'react-dom' apiClient = require 'panoptes-client/lib/api-client' { applyRouterMiddleware, Router, browserHistory } = require 'react-router' useScroll = require 'react-router-scroll/lib/useScroll' +require('./monkeypatchNode') { routes } = require './router' style = require '../css/main.styl' { Provider } = require('react-redux') initStore = require('./redux/init-store').default initSentry = require('./lib/init-sentry').default + # register locales `import counterpart from 'counterpart';` `import locales from './locales';` diff --git a/app/monkeypatchNode.js b/app/monkeypatchNode.js new file mode 100644 index 0000000000..77425ac800 --- /dev/null +++ b/app/monkeypatchNode.js @@ -0,0 +1,28 @@ +/* +Monkey-patch node.removeChild and node.insertBefore, +to work around a crashing bug with Google Translate. +https://github.com/facebook/react/issues/11538#issuecomment-417504600 +*/ +if (typeof Node === 'function' && Node.prototype) { + const originalRemoveChild = Node.prototype.removeChild; + Node.prototype.removeChild = function(child) { + 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); + } + + const originalInsertBefore = Node.prototype.insertBefore; + Node.prototype.insertBefore = function(newNode, referenceNode) { + 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); + } + }