From 6ea500b4797f439482de2a828335bc5b46b2da4d Mon Sep 17 00:00:00 2001 From: Tomasz Misiukiewicz Date: Thu, 5 Mar 2026 08:34:33 +0100 Subject: [PATCH] Revert "Merge pull request #83887 from callstack-internal/perf/prevent-remounting-lhn" This reverts commit c90ee4169a5b452c8e97937607c35ee5a5b6630b, reversing changes made to 2e32c725d030c4d8247bdb69ea7e46a56b1f94ba. --- .../useCustomRootStackNavigatorState/index.ts | 12 +++++++++--- .../AppNavigator/usePreloadFullScreenNavigators.ts | 8 -------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/libs/Navigation/AppNavigator/createRootStackNavigator/useCustomRootStackNavigatorState/index.ts b/src/libs/Navigation/AppNavigator/createRootStackNavigator/useCustomRootStackNavigatorState/index.ts index 4f09f87a22e04..88a7135aa0b32 100644 --- a/src/libs/Navigation/AppNavigator/createRootStackNavigator/useCustomRootStackNavigatorState/index.ts +++ b/src/libs/Navigation/AppNavigator/createRootStackNavigator/useCustomRootStackNavigatorState/index.ts @@ -2,11 +2,17 @@ import {isFullScreenName} from '@libs/Navigation/helpers/isNavigatorName'; import type {CustomStateHookProps} from '@libs/Navigation/PlatformStackNavigation/types'; // This is an optimization to keep mounted only last few screens in the stack. -// We keep the last full screen and the one before it to avoid unmounting persistent screens -// (like ReportsSplitNavigator) which contain heavy component trees (e.g. LHN with thousands of items). export default function useCustomRootStackNavigatorState({state}: CustomStateHookProps) { const lastSplitIndex = state.routes.findLastIndex((route) => isFullScreenName(route.name)); - const indexToSlice = Math.max(0, lastSplitIndex - 1); + let indexToSlice = Math.max(0, lastSplitIndex); + const hasPrevRoute = lastSplitIndex > 0; + const isPrevFullScreen = isFullScreenName(state.routes.at(lastSplitIndex - 1)?.name); + + // If the route before the last full screen is e.g. RHP, we should leave it in the rendered routes, + // as there may be display issues (blank screen) when navigating back and recreating that route to render. + if (hasPrevRoute && !isPrevFullScreen) { + indexToSlice = lastSplitIndex - 1; + } const routesToRender = state.routes.slice(indexToSlice, state.routes.length); return {...state, routes: routesToRender, index: routesToRender.length - 1}; } diff --git a/src/libs/Navigation/AppNavigator/usePreloadFullScreenNavigators.ts b/src/libs/Navigation/AppNavigator/usePreloadFullScreenNavigators.ts index 8f052fb191940..9bb3ee4c71f07 100644 --- a/src/libs/Navigation/AppNavigator/usePreloadFullScreenNavigators.ts +++ b/src/libs/Navigation/AppNavigator/usePreloadFullScreenNavigators.ts @@ -134,7 +134,6 @@ function usePreloadFullScreenNavigators() { } hasPreloadedRef.current = true; setTimeout(() => { - const currentRoutes = navigation.getState().routes; for (const tabName of TABS_TO_PRELOAD) { // Don't preload the current tab const isCurrentTab = TAB_TO_FULLSCREEN[tabName].includes(route.name as FullScreenName); @@ -148,13 +147,6 @@ function usePreloadFullScreenNavigators() { continue; } - // Don't preload tabs whose navigator is already in the regular routes stack - const isRouteInStack = currentRoutes.some((r) => TAB_TO_FULLSCREEN[tabName].includes(r.name as FullScreenName)); - - if (isRouteInStack) { - continue; - } - // Preload everything else preloadTab(tabName, navigation, subscriptionPlan); }