* Given a DOM node, return the closest ReactDOMComponent or * ReactDOMTextComponent instance ancestor.
(node)
| 2475 | * ReactDOMTextComponent instance ancestor. |
| 2476 | */ |
| 2477 | function getClosestInstanceFromNode(node) { |
| 2478 | if (node[internalInstanceKey]) { |
| 2479 | return node[internalInstanceKey]; |
| 2480 | } |
| 2481 | |
| 2482 | while (!node[internalInstanceKey]) { |
| 2483 | if (node.parentNode) { |
| 2484 | node = node.parentNode; |
| 2485 | } else { |
| 2486 | // Top of the tree. This node must not be part of a React tree (or is |
| 2487 | // unmounted, potentially). |
| 2488 | return null; |
| 2489 | } |
| 2490 | } |
| 2491 | |
| 2492 | var inst = node[internalInstanceKey]; |
| 2493 | if (inst.tag === HostComponent || inst.tag === HostText) { |
| 2494 | // In Fiber, this will always be the deepest root. |
| 2495 | return inst; |
| 2496 | } |
| 2497 | |
| 2498 | return null; |
| 2499 | } |
| 2500 | |
| 2501 | /** |
| 2502 | * Given a DOM node, return the ReactDOMComponent or ReactDOMTextComponent |
no outgoing calls
no test coverage detected