@@ -151,10 +151,16 @@ function runHooks(hooks, callback) {
151
151
}
152
152
153
153
function 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 ] ;
155
157
match . component = refs . __activeRoute__ ;
158
+
159
+ if ( match . component == null )
160
+ break ; // End of the tree.
161
+
156
162
refs = match . component . refs ;
157
- } ) ;
163
+ }
158
164
}
159
165
160
166
function returnNull ( ) {
@@ -195,9 +201,16 @@ var Routes = React.createClass({
195
201
} ,
196
202
197
203
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 ;
201
214
}
202
215
} ,
203
216
@@ -243,26 +256,19 @@ var Routes = React.createClass({
243
256
} else if ( abortReason ) {
244
257
this . goBack ( ) ;
245
258
} 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
+ } ,
248
264
249
- this . updateScroll ( path , actionType ) ;
265
+ handleStateChange : function ( path , actionType ) {
266
+ updateMatchComponents ( this . state . matches , this . refs ) ;
250
267
251
- if ( this . props . onChange )
252
- this . props . onChange . call ( this ) ;
253
- } . bind ( this ) ;
268
+ this . updateScroll ( path , actionType ) ;
254
269
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 ) ;
266
272
} ,
267
273
268
274
/**
0 commit comments