From 4b5385b2f04d2a67a4954f3661ea7963881489f2 Mon Sep 17 00:00:00 2001 From: Eric Vicenti Date: Wed, 13 May 2015 12:19:32 -0700 Subject: [PATCH] [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 --- Libraries/CustomComponents/Navigator/Navigator.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Libraries/CustomComponents/Navigator/Navigator.js b/Libraries/CustomComponents/Navigator/Navigator.js index bc044f1b95..b8c019e32e 100644 --- a/Libraries/CustomComponents/Navigator/Navigator.js +++ b/Libraries/CustomComponents/Navigator/Navigator.js @@ -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); + } }); },