From 38e0e7442c855c01eafe743c6209da3d52d14d1f Mon Sep 17 00:00:00 2001 From: Lam Hieu Date: Wed, 26 Dec 2018 11:01:10 +0700 Subject: [PATCH] Catch case causing `Permission denied error` error to appear on Firefox --- .../src/client/ReactDOMComponentTree.js | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/packages/react-dom/src/client/ReactDOMComponentTree.js b/packages/react-dom/src/client/ReactDOMComponentTree.js index a3b61d6e49e..1180769dde0 100644 --- a/packages/react-dom/src/client/ReactDOMComponentTree.js +++ b/packages/react-dom/src/client/ReactDOMComponentTree.js @@ -23,18 +23,28 @@ export function precacheFiberNode(hostInst, node) { * ReactDOMTextComponent instance ancestor. */ export function getClosestInstanceFromNode(node) { - if (node[internalInstanceKey]) { - return node[internalInstanceKey]; - } - - while (!node[internalInstanceKey]) { - if (node.parentNode) { - node = node.parentNode; - } else { - // Top of the tree. This node must not be part of a React tree (or is - // unmounted, potentially). - return null; + // In Firefox, anchorNode and focusNode can be "anonymous divs", e.g. the + // up/down buttons on an . Anonymous divs do not seem to + // expose properties, triggering a "Permission denied error" if any of its + // properties are accessed. The only seemingly possible way to avoid erroring + // is to access a property that typically works for non-anonymous divs and + // catch any error that may otherwise arise. See + // https://bugzilla.mozilla.org/show_bug.cgi?id=208427 + try { + if (node[internalInstanceKey]) { + return node[internalInstanceKey]; + } + while (!node[internalInstanceKey]) { + if (node.parentNode) { + node = node.parentNode; + } else { + // Top of the tree. This node must not be part of a React tree (or is + // unmounted, potentially). + return null; + } } + } catch (e) { + return null; } let inst = node[internalInstanceKey];