[ReactNative] Fix Navigator resetTo race condition

Summary:
SetState can be somewhat racy. By the time the route state finishes, another resetTo has already happened, so the origional route is no longer in the stack. Hence the redbox invariant "Calling pop to route for a route that doesn't exist!"

This could also be fixed in product code by not calling resetTo rapidly, but the navigator should be resilient to such shenanigans

@public

Test Plan: Cannot get AdsManager crash t7031976
This commit is contained in:
Eric Vicenti 2015-05-13 12:19:32 -07:00
parent 1e42fea0af
commit 4b5385b2f0
1 changed files with 5 additions and 1 deletions

View File

@ -1173,7 +1173,11 @@ var Navigator = React.createClass({
resetTo: function(route) {
invariant(!!route, 'Must supply route to push');
this.replaceAtIndex(route, 0, () => {
this.popToRoute(route);
// Do not use popToRoute here, because race conditions could prevent the
// route from existing at this time. Instead, just go to index 0
if (this.state.presentedIndex > 0) {
this._popN(this.state.presentedIndex);
}
});
},