diff --git a/src/renderers/dom/shared/ReactDOMComponentTree.js b/src/renderers/dom/shared/ReactDOMComponentTree.js index 8ff3260e8508e..d440446acec40 100644 --- a/src/renderers/dom/shared/ReactDOMComponentTree.js +++ b/src/renderers/dom/shared/ReactDOMComponentTree.js @@ -22,6 +22,18 @@ var Flags = ReactDOMComponentFlags; var internalInstanceKey = '__reactInternalInstance$' + Math.random().toString(36).slice(2); +/** + * Check if a given node should be cached. + */ +function shouldPrecacheNode(node, nodeID) { + return (node.nodeType === 1 && + node.getAttribute(ATTR_NAME) === String(nodeID)) || + (node.nodeType === 8 && + node.nodeValue === ' react-text: ' + nodeID + ' ') || + (node.nodeType === 8 && + node.nodeValue === ' react-empty: ' + nodeID + ' '); +} + /** * Drill down (through composites and empty components) until we get a host or * host text component. @@ -87,12 +99,7 @@ function precacheChildNodes(inst, node) { } // We assume the child nodes are in the same order as the child instances. for (; childNode !== null; childNode = childNode.nextSibling) { - if ((childNode.nodeType === 1 && - childNode.getAttribute(ATTR_NAME) === String(childID)) || - (childNode.nodeType === 8 && - childNode.nodeValue === ' react-text: ' + childID + ' ') || - (childNode.nodeType === 8 && - childNode.nodeValue === ' react-empty: ' + childID + ' ')) { + if (shouldPrecacheNode(childNode, childID)) { precacheNode(childInst, childNode); continue outer; }