* Returns the first (deepest) ancestor of a node which is rendered by this copy * of React.
(node)
| 10917 | * of React. |
| 10918 | */ |
| 10919 | function findFirstReactDOMImpl(node) { |
| 10920 | // This node might be from another React instance, so we make sure not to |
| 10921 | // examine the node cache here |
| 10922 | for (; node && node.parentNode !== node; node = node.parentNode) { |
| 10923 | if (node.nodeType !== 1) { |
| 10924 | // Not a DOMElement, therefore not a React component |
| 10925 | continue; |
| 10926 | } |
| 10927 | var nodeID = internalGetID(node); |
| 10928 | if (!nodeID) { |
| 10929 | continue; |
| 10930 | } |
| 10931 | var reactRootID = ReactInstanceHandles.getReactRootIDFromNodeID(nodeID); |
| 10932 | |
| 10933 | // If containersByReactRootID contains the container we find by crawling up |
| 10934 | // the tree, we know that this instance of React rendered the node. |
| 10935 | // nb. isValid's strategy (with containsNode) does not work because render |
| 10936 | // trees may be nested and we don't want a false positive in that case. |
| 10937 | var current = node; |
| 10938 | var lastID; |
| 10939 | do { |
| 10940 | lastID = internalGetID(current); |
| 10941 | current = current.parentNode; |
| 10942 | if (current == null) { |
| 10943 | // The passed-in node has been detached from the container it was |
| 10944 | // originally rendered into. |
| 10945 | return null; |
| 10946 | } |
| 10947 | } while (lastID !== reactRootID); |
| 10948 | |
| 10949 | if (current === containersByReactRootID[reactRootID]) { |
| 10950 | return node; |
| 10951 | } |
| 10952 | } |
| 10953 | return null; |
| 10954 | } |
| 10955 | |
| 10956 | /** |
| 10957 | * Temporary (?) hack so that we can store all top-level pending updates on |