mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-02-11 17:21:11 +08:00
[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:
@@ -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);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user