@@ -151,10 +151,16 @@ function runHooks(hooks, callback) {
151151}
152152
153153function updateMatchComponents ( matches , refs ) {
154- matches . forEach ( function ( match ) {
154+ var match ;
155+ for ( var i = 0 , len = matches . length ; i < len ; ++ i ) {
156+ match = matches [ i ] ;
155157 match . component = refs . __activeRoute__ ;
158+
159+ if ( match . component == null )
160+ break ; // End of the tree.
161+
156162 refs = match . component . refs ;
157- } ) ;
163+ }
158164}
159165
160166function returnNull ( ) {
@@ -195,9 +201,16 @@ var Routes = React.createClass({
195201 } ,
196202
197203 componentDidMount : function ( ) {
198- if ( this . _initialSetStateCallback ) {
199- this . _initialSetStateCallback ( ) ;
200- delete this . _initialSetStateCallback ;
204+ if ( this . _handleStateChange ) {
205+ this . _handleStateChange ( ) ;
206+ delete this . _handleStateChange ;
207+ }
208+ } ,
209+
210+ componentDidUpdate : function ( ) {
211+ if ( this . _handleStateChange ) {
212+ this . _handleStateChange ( ) ;
213+ delete this . _handleStateChange ;
201214 }
202215 } ,
203216
@@ -243,26 +256,19 @@ var Routes = React.createClass({
243256 } else if ( abortReason ) {
244257 this . goBack ( ) ;
245258 } else {
246- var handleStateChange = function ( ) {
247- updateMatchComponents ( this . state . matches , this . refs ) ;
259+ this . _handleStateChange = this . handleStateChange . bind ( this , path , actionType ) ;
260+ this . setState ( nextState ) ;
261+ }
262+ } . bind ( this ) ) ;
263+ } ,
248264
249- this . updateScroll ( path , actionType ) ;
265+ handleStateChange : function ( path , actionType ) {
266+ updateMatchComponents ( this . state . matches , this . refs ) ;
250267
251- if ( this . props . onChange )
252- this . props . onChange . call ( this ) ;
253- } . bind ( this ) ;
268+ this . updateScroll ( path , actionType ) ;
254269
255- if ( this . isMounted ( ) ) {
256- this . setState ( nextState , handleStateChange ) ;
257- } else {
258- // React does not invoke setState callback if we're still mounting
259- // so we have to store it and invoke in componentDidMount.
260- // https://github.com/facebook/react/blob/3bbed150ab58a07b0c4faf64126b4c9349eecfea/src/core/ReactCompositeComponent.js#L900
261- this . _initialSetStateCallback = handleStateChange ;
262- this . setState ( nextState ) ;
263- }
264- }
265- } . bind ( this ) ) ;
270+ if ( this . props . onChange )
271+ this . props . onChange . call ( this ) ;
266272 } ,
267273
268274 /**
0 commit comments