diff --git a/src/libs/SearchQueryUtils.ts b/src/libs/SearchQueryUtils.ts index fec2a31fce4e..eba4e94c8494 100644 --- a/src/libs/SearchQueryUtils.ts +++ b/src/libs/SearchQueryUtils.ts @@ -33,6 +33,7 @@ import {getCardDescription} from './CardUtils'; import {convertToBackendAmount, convertToFrontendAmountAsInteger} from './CurrencyUtils'; import Log from './Log'; import {validateAmount} from './MoneyRequestUtils'; +import {getPreservedNavigatorState} from './Navigation/AppNavigator/createSplitNavigator/usePreserveNavigatorState'; import navigationRef from './Navigation/navigationRef'; import type {SearchFullscreenNavigatorParamList} from './Navigation/types'; import {getPersonalDetailByEmail} from './PersonalDetailsUtils'; @@ -1017,13 +1018,14 @@ function getQueryWithUpdatedValues(query: string) { function getCurrentSearchQueryJSON() { const rootState = navigationRef.getRootState(); - const lastPolicyRoute = rootState?.routes?.findLast((route) => route.name === NAVIGATORS.REPORTS_SPLIT_NAVIGATOR || route.name === NAVIGATORS.SEARCH_FULLSCREEN_NAVIGATOR); + const lastSearchNavigator = rootState?.routes?.findLast((route) => route.name === NAVIGATORS.SEARCH_FULLSCREEN_NAVIGATOR); - if (!lastPolicyRoute) { + const lastSearchNavigatorState = lastSearchNavigator && lastSearchNavigator.key ? getPreservedNavigatorState(lastSearchNavigator?.key) : undefined; + if (!lastSearchNavigatorState) { return; } - const lastSearchRoute = lastPolicyRoute.state?.routes.findLast((route) => route.name === SCREENS.SEARCH.ROOT); + const lastSearchRoute = lastSearchNavigatorState.routes.findLast((route) => route.name === SCREENS.SEARCH.ROOT); if (!lastSearchRoute || !lastSearchRoute.params) { return; }