77 * of patent rights can be found in the PATENTS file in the same directory.
88 *
99 * @providesModule findDOMNode
10+ * @flow
1011 */
1112
12- 'use strict' ;
13-
1413var ReactCurrentOwner = require ( 'ReactCurrentOwner' ) ;
15- var ReactDOMComponentTree = require ( 'ReactDOMComponentTree' ) ;
1614var ReactInstanceMap = require ( 'ReactInstanceMap' ) ;
1715
18- var getHostComponentFromComposite = require ( 'getHostComponentFromComposite ' ) ;
16+ var getComponentName = require ( 'getComponentName ' ) ;
1917var invariant = require ( 'invariant' ) ;
2018var warning = require ( 'warning' ) ;
2119
22- /**
23- * Returns the DOM node rendered by this element.
24- *
25- * See https://facebook.github.io/react/docs/react-dom.html#finddomnode
26- *
27- * @param {ReactComponent|DOMElement } componentOrElement
28- * @return {?DOMElement } The root node of this element.
29- */
30- function findDOMNode ( componentOrElement ) {
20+ let findFiber = function ( arg ) {
21+ invariant ( false , 'Missing injection for fiber findDOMNode' ) ;
22+ } ;
23+ let findStack = function ( arg ) {
24+ invariant ( false , 'Missing injection for stack findDOMNode' ) ;
25+ } ;
26+
27+ const findDOMNode = function ( componentOrElement : Element | ?ReactComponent < any , any , any > ) : null | Element | Text {
3128 if ( __DEV__ ) {
3229 var owner = ReactCurrentOwner . current ;
33- if ( owner !== null ) {
30+ if ( owner !== null && '_warnedAboutRefsInRender' in owner ) {
3431 warning (
35- owner . _warnedAboutRefsInRender ,
32+ ( owner : any ) . _warnedAboutRefsInRender ,
3633 '%s is accessing findDOMNode inside its render(). ' +
3734 'render() should be a pure function of props and state. It should ' +
3835 'never access something that requires stale data from the previous ' +
3936 'render, such as refs. Move this logic to componentDidMount and ' +
4037 'componentDidUpdate instead.' ,
41- owner . getName ( ) || 'A component'
38+ getComponentName ( owner ) || 'A component'
4239 ) ;
43- owner . _warnedAboutRefsInRender = true ;
40+ ( owner : any ) . _warnedAboutRefsInRender = true ;
4441 }
4542 }
4643 if ( componentOrElement == null ) {
4744 return null ;
4845 }
49- if ( componentOrElement . nodeType === 1 ) {
50- return componentOrElement ;
46+ if ( ( componentOrElement : any ) . nodeType === 1 ) {
47+ return ( componentOrElement : any ) ;
5148 }
5249
5350 var inst = ReactInstanceMap . get ( componentOrElement ) ;
5451 if ( inst ) {
55- inst = getHostComponentFromComposite ( inst ) ;
56- return inst ? ReactDOMComponentTree . getNodeFromInstance ( inst ) : null ;
52+ if ( typeof inst . tag === 'number' ) {
53+ return findFiber ( inst ) ;
54+ } else {
55+ return findStack ( inst ) ;
56+ }
5757 }
5858
5959 if ( typeof componentOrElement . render === 'function' ) {
6060 invariant (
6161 false ,
62- 'findDOMNode was called on an unmounted component.'
62+ 'Unable to find node on an unmounted component.'
6363 ) ;
6464 } else {
6565 invariant (
@@ -68,6 +68,13 @@ function findDOMNode(componentOrElement) {
6868 Object . keys ( componentOrElement )
6969 ) ;
7070 }
71- }
71+ } ;
72+
73+ findDOMNode . _injectFiber = function ( fn ) {
74+ findFiber = fn ;
75+ } ;
76+ findDOMNode . _injectStack = function ( fn ) {
77+ findStack = fn ;
78+ } ;
7279
7380module . exports = findDOMNode ;
0 commit comments