1212
1313'use strict' ;
1414
15+ var { ELEMENT_NODE } = require ( 'HTMLNodeType' ) ;
1516import type { Fiber } from 'ReactFiber' ;
1617import type { ReactInstance } from 'ReactInstanceType' ;
1718
@@ -23,6 +24,9 @@ type ValueTracker = {
2324type WrapperState = { _wrapperState : { valueTracker : ?ValueTracker } } ;
2425type ElementWithWrapperState = Element & WrapperState ;
2526type InstanceWithWrapperState = ReactInstance & WrapperState ;
27+ type SubjectWithWrapperState =
28+ | InstanceWithWrapperState
29+ | ElementWithWrapperState ;
2630
2731var ReactDOMComponentTree = require ( 'ReactDOMComponentTree' ) ;
2832
@@ -43,15 +47,11 @@ function getTracker(inst: any) {
4347 return inst . _wrapperState . valueTracker ;
4448}
4549
46- function attachTracker ( inst : InstanceWithWrapperState , tracker : ? ValueTracker ) {
47- inst . _wrapperState . valueTracker = tracker ;
50+ function detachTracker ( subject : SubjectWithWrapperState ) {
51+ subject . _wrapperState . valueTracker = null ;
4852}
4953
50- function detachTracker ( inst : InstanceWithWrapperState ) {
51- delete inst . _wrapperState . valueTracker ;
52- }
53-
54- function getValueFromNode ( node ) {
54+ function getValueFromNode ( node : any ) {
5555 var value ;
5656 if ( node ) {
5757 value = isCheckable ( node ) ? '' + node . checked : node . value ;
@@ -113,40 +113,46 @@ var inputValueTracking = {
113113 return getTracker ( ReactDOMComponentTree . getInstanceFromNode ( node ) ) ;
114114 } ,
115115
116- trackNode : function ( node : ElementWithWrapperState ) {
117- if ( node . _wrapperState . valueTracker ) {
116+ trackNode ( node : ElementWithWrapperState ) {
117+ if ( getTracker ( node ) ) {
118118 return ;
119119 }
120120 node . _wrapperState . valueTracker = trackValueOnNode ( node , node ) ;
121121 } ,
122122
123- track : function ( inst : InstanceWithWrapperState ) {
123+ track ( inst : InstanceWithWrapperState ) {
124124 if ( getTracker ( inst ) ) {
125125 return ;
126126 }
127127 var node = ReactDOMComponentTree . getNodeFromInstance ( inst ) ;
128- attachTracker ( inst , trackValueOnNode ( node , inst ) ) ;
128+ inst . _wrapperState . valueTracker = trackValueOnNode ( node , inst ) ;
129129 } ,
130130
131- updateValueIfChanged ( inst : InstanceWithWrapperState | Fiber ) {
132- if ( ! inst ) {
131+ updateValueIfChanged ( subject : SubjectWithWrapperState | Fiber ) {
132+ if ( ! subject ) {
133133 return false ;
134134 }
135- var tracker = getTracker ( inst ) ;
135+ var tracker = getTracker ( subject ) ;
136136
137137 if ( ! tracker ) {
138- if ( typeof ( inst : any ) . tag === 'number' ) {
139- inputValueTracking . trackNode ( ( inst : any ) . stateNode ) ;
138+ if ( typeof ( subject : any ) . tag === 'number' ) {
139+ inputValueTracking . trackNode ( ( subject : any ) . stateNode ) ;
140140 } else {
141- inputValueTracking . track ( ( inst : any ) ) ;
141+ inputValueTracking . track ( ( subject : any ) ) ;
142142 }
143143 return true ;
144144 }
145145
146146 var lastValue = tracker . getValue ( ) ;
147- var nextValue = getValueFromNode (
148- ReactDOMComponentTree . getNodeFromInstance ( inst ) ,
149- ) ;
147+
148+ var node = subject ;
149+
150+ // TODO: remove check when the Stack renderer is retired
151+ if ( ( subject : any ) . nodeType !== ELEMENT_NODE ) {
152+ node = ReactDOMComponentTree . getNodeFromInstance ( subject ) ;
153+ }
154+
155+ var nextValue = getValueFromNode ( node ) ;
150156
151157 if ( nextValue !== lastValue ) {
152158 tracker . setValue ( nextValue ) ;
0 commit comments