From afc00cf810ffcd8aca24efc2a30b57af5359b01e Mon Sep 17 00:00:00 2001 From: Brent Vatne Date: Thu, 19 Jul 2018 13:16:38 -0700 Subject: [PATCH] Cleanup unused descriptors and handle the case where we might expect to have a descriptor but do not (#4723) --- .../src/views/ScenesReducer.js | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/react-navigation/src/views/ScenesReducer.js b/packages/react-navigation/src/views/ScenesReducer.js index e7f69a61..95f6f0cd 100644 --- a/packages/react-navigation/src/views/ScenesReducer.js +++ b/packages/react-navigation/src/views/ScenesReducer.js @@ -133,23 +133,23 @@ export default function ScenesReducer( // We can get into a weird place where we have a queued transition and then clobber // that transition without ever actually rendering the scene, in which case - // there is no lastScene and so we need to grab the descriptor from elsewhere. - // Warning: changes to descriptor caching may break this, and in that case - // we may be better off just not adding it to stale scenes at all. + // there is no lastScene. If the descriptor is not available on the lastScene + // or the descriptors prop then we just skip adding it to stale scenes and it's + // not ever rendered. const descriptor = lastScene ? lastScene.descriptor : descriptors[route.key]; - invariant(descriptor, 'Cannot add stale scene with no descriptor'); - - staleScenes.set(key, { - index, - isActive: false, - isStale: true, - key, - route, - descriptor, - }); + if (descriptor) { + staleScenes.set(key, { + index, + isActive: false, + isStale: true, + key, + route, + descriptor, + }); + } }); }