diff --git a/native/navigation/overlay-navigator.react.js b/native/navigation/overlay-navigator.react.js --- a/native/navigation/overlay-navigator.react.js +++ b/native/navigation/overlay-navigator.react.js @@ -286,27 +286,29 @@ const newVisibleOverlays = curVisibleOverlays.filter( overlay => overlay.routeKey !== key, ); - invariant( - newVisibleOverlays.length < curVisibleOverlays.length, - `could not find ${key} in visibleOverlays`, - ); - visibleOverlaysRef.current = newVisibleOverlays; - setSceneData(curSceneData => { - const newSceneData = {}; - for (const sceneKey in curSceneData) { - if (sceneKey === key) { - continue; + if (newVisibleOverlays.length < curVisibleOverlays.length) { + invariant( + newVisibleOverlays.length < curVisibleOverlays.length, + `could not find ${key} in visibleOverlays`, + ); + visibleOverlaysRef.current = newVisibleOverlays; + setSceneData(curSceneData => { + const newSceneData = {}; + for (const sceneKey in curSceneData) { + if (sceneKey === key) { + continue; + } + newSceneData[sceneKey] = { + ...curSceneData[sceneKey], + context: { + ...curSceneData[sceneKey].context, + visibleOverlays: newVisibleOverlays, + }, + }; } - newSceneData[sceneKey] = { - ...curSceneData[sceneKey], - context: { - ...curSceneData[sceneKey].context, - visibleOverlays: newVisibleOverlays, - }, - }; - } - return newSceneData; - }); + return newSceneData; + }); + } }), ), ],