[$175] 106796 - Android - Home - Chart updates when closing RHP with no changes
If you haven’t already, check out our contributing guidelines for onboarding. To join our Slack channel, fill out this form.
Version Number: 9.5.39-0 Reproducible in staging?: Yes Reproducible in production?: Yes If this was caught during regression testing, add the test name, ID and link from BrowserStack: https://github.com/Expensify/App/pull/106796 Email or phone of affected tester (no customers): N/A Issue reported by: Applause Internal Team Bug source: Pull Request QA execution Device used: Android 16 / Samsung Galaxy A06 App Component: Other
Action Performed:
Precondition: Account A is owner of a Workspace with enough expenses to populate Home Insights Account B is member of the workspace submitting to Account A, so that expenses from B can alter Insights from Account A
- Open Expensify mobile app
- Go to Home, scroll to insight chart
- Open RHP, for example, tap + -> create expense
- On a different session as account B submit an expense to the Workspace
- As account A, close the RHP
Expected Result:
Chart does not refresh when the panel is closed.
Actual Result:
Chart refreshes when the panel is closed.
Workaround:
Unknown
Platforms:
- [x] Android: App
- [ ] Android: mWeb Chrome
- [x] iOS: App
- [ ] iOS: mWeb Safari
- [ ] iOS: mWeb Chrome
- [ ] Windows: Chrome
- [ ] MacOS: Chrome Safari
Screenshots/Videos
https://github.com/user-attachments/assets/093306e1-2290-4460-b33b-2966c4737702
Applause Internal Information Exported by: Alberto Gutierrez Bug ID: 7313199
Upwork Automation - Do Not Edit
- Upwork Job URL: https://www.upwork.com/jobs/~022121282404764323273
- Upwork Job ID: 2121282404764323273
- Last Price Increase: 2026-11-13
While Applause doesn't embed attachments for this bug, here are the links for quick view: https://platform.applause.com/services/links/v1/external/967772d87299cee95c6bd903d1401d020777c73259b3f2491798c3dcdf2cb7f7
Triggered auto assignment to Contributor-plus team member for initial proposal review - @linhvovan29546 (External)
Job added to Upwork: https://www.upwork.com/jobs/~022121282404764323273
⚠️ Preliminary analysis (low confidence) — the reported refresh trigger is not yet confirmed.
Findings
Stop expense-driven Home Insights chart refreshes removed expense changes from the chart’s refresh key. An incoming expense alone should therefore not queue a refresh.
A plausible alternative is an app-return refresh: if Account A was backgrounded while operating Account B, returning to A can queue a refresh behind the RHP. Closing the panel then allows that pending refresh to run. This behavior predates the linked PR; there is insufficient evidence to call this an introduced regression.
Code evidence and test coverage
- The remaining refresh key contains query hash, connectivity, configuration resolution, and workspace IDs—not the expense signature:
useInsightData.ts:38–62. - App-return refreshes remain pending until the screen becomes visible:
useTabFocusedRefresh.ts:46–73. - The expense-behind-RHP regression test mocks navigation rather than exercising actual panel transitions:
useInsightDataRefreshTest.ts:153–169. - Four focused suites passed: 36 tests. They do not exclude a real navigation/remount issue.
Verification limits
Web reproduction was blocked: the tester supports one session, while these steps require two accounts. No chart behavior was verified. Production confirmation also lacks account identifiers, an exact reproduction timestamp, and client-side trigger telemetry.
Recommended next step
Repeat with A continuously foregrounded and B on a separate device. Capture the selected chart’s Search request—not other Home requests—and check whether Home remounts or its refresh key changes. Repeat without B submitting anything.
No code fix is justified yet: distinguish a chart refetch from a visual redraw and identify its initiating event first.
Related: Home — Stop live-updating the Insights chart on expense changes.
Proposal
What is the root cause of that problem?
The root cause is a false tab transition in useIsTabFocused and getActiveTabName caused by how React Navigation represents inactive stack routes on native platforms:
-
getActiveTabName falls back to 'TabNavigator' when nested oute.state is unhydrated (src/libs/Navigation/helpers/getActiveTabName.ts:13-20): ` ypescript function getActiveTabName(route: NavigationRoute | undefined): string | undefined { if (!route) { return undefined; }
if (route.name === NAVIGATORS.TAB_NAVIGATOR && route.state) { const index = route.state.index ?? 0; return route.state.routes?.at(index)?.name; } return route.name;} ` When RIGHT_MODAL_NAVIGATOR (such as Create expense) is pushed on native, TAB_NAVIGATOR becomes a non-top route on RootStack. In the raw root navigation state emitted by avigationRef.getRootState(), React Navigation does not keep the nested .state for inactive child navigators hydrated (which is why estoreTabNavigatorRoutes and getPreservedNavigatorState exist to restore lost states during stack slicing).
Because opTabNavigator.state becomes undefined in the root state while covered by a modal:
oute.name === NAVIGATORS.TAB_NAVIGATOR && route.state evaluates to alse.
- getActiveTabName falls through to eturn route.name ('TabNavigator').
- In useIsTabFocused: getActiveTabName(topTabNavigator) === SCREENS.HOME evaluates to 'TabNavigator' === 'Home' -> alse!
-
Spurious Tab-Arrival Refresh queued on RHP Close (src/hooks/useTabFocusedRefresh.ts:43-45, 68-73): In useTabFocusedRefresh: ` ypescript const wasTabFocused = wasTabFocusedRef.current; wasTabFocusedRef.current = isTabFocused;
if (isTabFocused && !wasTabFocused) { isRefreshPendingRef.current = true; } `
- While the RHP was open, isTabFocused dropped to alse.
- When the user taps < to close the RHP, TAB_NAVIGATOR returns to the top of RootStack, its nested state re-hydrates with outes[0].name === 'Home', and useIsTabFocused transitions from alse to rue.
- Because isTabFocused && !wasTabFocused is now rue, isRefreshPendingRef.current is set to rue (treating closing an RHP identically to a user switching away to another tab and returning).
- Once the RHP unmounts and Home becomes visible (isScreenVisible = true), useTabFocusedRefresh executes onRefresh(), calling etry() in useInsightData, which executes search() and re-fetches the chart.
What changes do you think we should make in order to solve the problem?
1. Resilient Active Tab Resolution in getActiveTabName (src/libs/Navigation/helpers/getActiveTabName.ts)
Update getActiveTabName so that when oute.name === NAVIGATORS.TAB_NAVIGATOR but oute.state is undefined or unhydrated, it checks:
- getPreservedNavigatorState(route.key) (where useNativeTabNavigator preserves realized tab state during stack navigation).
- getTabScreenParam(route) (the initial or target screen parameter).
- If still unhydrated, defaults to SCREENS.HOME (the default initial route of TabNavigator), rather than returning the generic container name 'TabNavigator'.
` ypescript import {getPreservedNavigatorState} from '@libs/Navigation/AppNavigator/createSplitNavigator/usePreserveNavigatorState'; import {getTabScreenParam} from '@libs/Navigation/helpers/tabNavigatorUtils'; import type {NavigationRoute} from '@libs/Navigation/types'; import NAVIGATORS from '@src/NAVIGATORS'; import SCREENS from '@src/SCREENS'; import type {NavigationState} from '@react-navigation/native';
function getActiveTabName(route: NavigationRoute | undefined): string | undefined { if (!route) { return undefined; }
if (route.name === NAVIGATORS.TAB_NAVIGATOR) {
const state = (route.state ?? getPreservedNavigatorState<NavigationState>(route.key)) as NavigationState | undefined;
if (state?.routes) {
const index = state.index ?? 0;
return state.routes.at(index)?.name;
}
const paramScreen = getTabScreenParam(route);
if (paramScreen) {
return paramScreen;
}
return SCREENS.HOME;
}
return route.name;
}
export default getActiveTabName; `
2. Defensive check in useIsTabFocused (src/hooks/useIsTabFocused.ts)
In useIsTabFocused, utilize getTabNavigatorState(state) from @libs/Navigation/helpers/tabNavigatorUtils to ensure partial and rehydrated root states are normalized:
ypescript
function useIsTabFocused(tabName: string): boolean {
return useRootNavigationState((state) => {
if (!state) {
return false;
}
const topTabNavigator = state.routes.findLast((route) => route.name === NAVIGATORS.TAB_NAVIGATOR) as NavigationRoute | undefined;
return getActiveTabName(topTabNavigator) === tabName;
});
}
3. Automated Unit Tests
- ** ests/unit/hooks/useIsTabFocused.test.ts**:
- Add a test verifying that when TAB_NAVIGATOR has state: undefined (simulating covered stack state on native), useIsTabFocused(SCREENS.HOME) retains rue instead of returning alse.
- ** ests/unit/HomePage/InsightsSection/useInsightDataRefreshTest.ts**:
- Add a test verifying that when an RHP opens and closes over Home where TAB_NAVIGATOR temporarily loses its realized .state, closing the RHP does not trigger mockedSearch.
What alternative solutions did you explore? (Optional)
- Adding an isRhpClosing ref in useTabFocusedRefresh: Rejected because useTabFocusedRefresh is a shared hook used across RecentlyAddedSection and YourSpendSection. Fixing getActiveTabName directly resolves the root issue at the source for all consumers relying on tab focus without fragile per-hook bypass flags.
Contributor details
Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~0131dae36abcf59374
✅ Contributor details stored successfully. Thank you for contributing to Expensify!
Proposal
Please re-state the problem that we are trying to solve in this issue.
On narrow mobile layouts (Android and iOS apps), after Account B submits a new expense in a shared workspace while Account A is viewing Home, if Account A taps + -> Create expense to open the RHP and then closes the RHP without creating or changing anything, the Home Insights chart still refetches and updates.
What is the root cause of that problem?
- PR
#106796stoppeduseInsightData(src/pages/home/InsightsSection/hooks/useInsightData.ts) from auto-refetching on livespendDataSignaturechanges, relying onuseTabFocusedRefresh(SCREENS.HOME, isScreenVisible, refreshOnReturn)(src/hooks/useTabFocusedRefresh.ts) so Home only refreshes when the user switches back toSCREENS.HOMEfrom another tab (isTabFocused && !wasTabFocused->isRefreshPendingRef.current = true). - However, when Account A taps + -> Create expense over Home,
IOURequestStartPagemountsScanSkipConfirmation(src/pages/iou/request/step/IOURequestStepScan/components/ScanSkipConfirmation.tsx, and similarlyIOURequestStepAmount/DynamicIOURequestStepDistance/useSubmitDestinationPreMount), which resolvesskipConfirmationPreMountRoute(r/<reportID>, whose fullscreen destination lives insideTAB_NAVIGATOR->NAVIGATORS.REPORTS_SPLIT_NAVIGATOR) and callsusePreMountDestination(skipConfirmationPreMountRoute)(src/hooks/usePreMountDestination/index.ts). - Once the RHP open transition completes,
usePreMountDestinationinvokesNavigation.preInsertFullscreenUnderRHP(route)(src/libs/Navigation/Navigation.ts):- On wide desktop layouts (
!getIsNarrowLayout()),preInsertFullscreenUnderRHPcallspreMountFullscreenOnWide->preMountWideDestinationInTab(src/libs/Navigation/helpers/wideTabPreMount.ts), which keepstabState.indexonSCREENS.HOME(0) and only appendsREPORTS_SPLIT_NAVIGATORtopreloadedRouteKeys—which is why this bug does not reproduce on desktop Chrome. - On narrow mobile layouts (
getIsNarrowLayout() === true),preInsertFullscreenUnderRHPdispatchesCONST.NAVIGATION.ACTION_TYPE.REPLACE_FULLSCREEN_UNDER_RHP.handleReplaceFullscreenUnderRHP(src/libs/Navigation/AppNavigator/createRootStackNavigator/GetStateForActionHandlers.ts) saves the originalHometab route inpreInsertedOriginalTabRouteand mutates the liveTAB_NAVIGATORstate underneath the open RHP from[Tab(SCREENS.HOME), RHP](index: 0) to[Tab(NAVIGATORS.REPORTS_SPLIT_NAVIGATOR), RHP](index: 1).
- On wide desktop layouts (
- Because
HomePagestays mounted insideTabNavigatorwhiletopTabNavigatorswitches toNAVIGATORS.REPORTS_SPLIT_NAVIGATORunderneath the RHP,useIsTabFocused(SCREENS.HOME)(src/hooks/useIsTabFocused.ts) flips fromtruetofalse, settingwasTabFocusedRef.current = falseinsideuseTabFocusedRefresh. - When Account A closes the RHP without submitting,
usePreMountDestination's cleanup (removePreInsertedFullscreenIfNeeded->handleRemoveFullscreenUnderRHP/revertPreMountBufferIfRHPClosed) rollsTAB_NAVIGATORback topreInsertedOriginalTabRoute(SCREENS.HOME).useIsTabFocused(SCREENS.HOME)transitionsfalse -> true, causinguseTabFocusedRefreshto mistake the cancelled speculative pre-mount rollback for a real tab switch (isRefreshPendingRef.current = true) and fireretry()(search()) as soon asHomePagebecomes visible again.
What changes do you think we should make in order to solve the problem?
- Treat
preInsertedOriginalTabRouteas the logically focused tab insrc/hooks/useIsTabFocused.tswhile a speculative tab-switch pre-insertion is active behind an unsubmitted RHP:GetStateForActionHandlers.tsalready tracksgetPreInsertedOriginalTabRoute()for the exact lifetime of a speculativeTAB_NAVIGATORswitch under an RHP—setting it synchronously inhandleReplaceFullscreenUnderRHP, restoring the tab and clearing it simultaneously inhandleRemoveFullscreenUnderRHP/revertPreMountBufferIfRHPClosedwhen the RHP is dismissed without submitting, and clearing it inclearFullscreenPreInsertedFlag()when the user actually submits/reveals the destination. Updatesrc/hooks/useIsTabFocused.tsto readgetPreInsertedOriginalTabRoute(): whentopTabNavigatormatchespreInsertedOriginalTabRoute?.key, resolvegetActiveTabName(preInsertedOriginalTabRoute)instead of the speculatively pre-insertedtopTabNavigator:import {getPreInsertedOriginalTabRoute} from '@libs/Navigation/AppNavigator/createRootStackNavigator/GetStateForActionHandlers'; import getActiveTabName from '@libs/Navigation/helpers/getActiveTabName'; import type {NavigationRoute} from '@libs/Navigation/types'; import NAVIGATORS from '@src/NAVIGATORS'; import useRootNavigationState from './useRootNavigationState'; function useIsTabFocused(tabName: string): boolean { return useRootNavigationState((state) => { if (!state) { return false; } const topTabNavigator = state.routes.findLast((route) => route.name === NAVIGATORS.TAB_NAVIGATOR) as NavigationRoute | undefined; const preInsertedOriginalTabRoute = getPreInsertedOriginalTabRoute() as NavigationRoute | undefined; const effectiveTabNavigator = topTabNavigator && preInsertedOriginalTabRoute?.key === topTabNavigator.key ? preInsertedOriginalTabRoute : topTabNavigator; return getActiveTabName(effectiveTabNavigator) === tabName; }); }- If the user closes the RHP without changes,
effectiveTabNavigatorremainsTab(SCREENS.HOME)throughout (true -> true -> true), preventing any falsefalse -> truetransition on Home (and also preventing prematureuseIsTabFocusedarrival refetches on the speculatively pre-inserted destination tab while it is still hidden behind an unsubmitted RHP). - If the user submits in the RHP,
clearFullscreenPreInsertedFlag()clearspreInsertedOriginalTabRoute, cleanly transitioninguseIsTabFocusedfromSCREENS.HOMEto the revealed destination tab.
- If the user closes the RHP without changes,
- Avoid a 1-frame gap in the
requestAnimationFramefallback ofremovePreInsertedFullscreenIfNeeded(src/libs/Navigation/helpers/preMountBuffer.ts): In the fallback branch ofremovePreInsertedFullscreenIfNeeded(used when RHP inner stack depth preventedPRE_MOUNT_BUFFERinsertion and the RHP already closed before cleanup), moveclearPreInsertedOriginalTabRoute()inside therequestAnimationFramecallback right beforenavigationRef.current?.dispatch(TabActions.jumpTo(originalTabName))(and into the!originalTabNameearly return), sogetPreInsertedOriginalTabRoute()stays populated untilTabActions.jumpTorestores the original tab. - Add unit tests in
tests/unit/useIsTabFocusedTest.ts(andtests/unit/useInsightDataRefreshTest.ts) verifying thatREPLACE_FULLSCREEN_UNDER_RHPfollowed byREMOVE_FULLSCREEN_UNDER_RHP(cancel RHP) keepsuseIsTabFocused(SCREENS.HOME)trueand never triggerssearch(), whereas committing viaclearFullscreenPreInsertedFlag()transitionsuseIsTabFocused(SCREENS.HOME)tofalseso a subsequent return to Home refreshes as expected.
What alternative solutions did you explore? (Optional)
- Falling back to
getPreservedNavigatorState(route.key)whenroute.stateisundefinedingetActiveTabName: Does not solve the bug becausetopTabNavigator.stateis notundefinedhere—handleReplaceFullscreenUnderRHPassigns a realizedNavigationStatewithindex: 1(NAVIGATORS.REPORTS_SPLIT_NAVIGATOR), anduseNativeTabNavigatoralso updatespreservedNavigatorStatewith that pre-inserted state. - Skipping
usePreMountDestinationwhen opening+ -> Create expensefromSCREENS.HOME: Rejected because it would regress post-submission transition latency when the user actually creates an expense from Home. - Adding RHP-specific suppression logic inside
useTabFocusedRefresh: Rejected because fixinguseIsTabFocusedat the source protects all consumers (useInsightData,RecentlyAddedSection,YourSpendSection,useIsWorkspacesTabFocused) uniformly.
Proposal
What is the root cause of that problem?
On narrow layout, opening the Create expense RHP pre-inserts the destination fullscreen under it: handleReplaceFullscreenUnderRHP saves the Home tab route in preInsertedOriginalTabRoute and rewrites the live TAB_NAVIGATOR state to the target tab (GetStateForActionHandlers.ts:684-697). useIsTabFocused(HOME) (useIsTabFocused.ts:17-18) therefore flips to false while Home is still the tab the user is on. Cancelling the RHP runs handleRemoveFullscreenUnderRHP, which restores the saved route (:763-776). The flip back to true looks like a tab arrival, so useTabFocusedRefresh sets isRefreshPendingRef (useTabFocusedRefresh.ts:43-45) and retry() fires as soon as the RHP closes. Wide layout keeps the tab index, so it does not reproduce there.
What changes do you think we should make in order to solve the problem?
One change in useIsTabFocused.ts: while getPreInsertedOriginalTabRoute() (already exported, :957) has the same key as topTabNavigator, pass that saved route to getActiveTabName instead. The module value changes in the same dispatch as the state, so the selector stays in step. Home then stays true through open and cancel, and a committed submit still moves focus. Test: extend tests/unit/Navigation/createRootStackNavigator/handleReplaceFullscreenUnderRHP.test.ts to run REPLACE then REMOVE and assert useIsTabFocused(HOME) is true throughout. Add a case in useInsightDataRefreshTest.ts that search is not called after cancel.
What alternative solutions did you explore? (Optional)
- kevinjosh10's
getActiveTabNamefallback assumesroute.stateis undefined, but the handler writes a full state, so it changes nothing here. - cocvn157 has the same cause; I leave out the
preMountBufferrequestAnimationFrameedit, which this fix does not need. - A flag in the shared
useTabFocusedRefresh: fixing the source hook is cleaner.
Proposal
Please re-state the problem that we are trying to solve in this issue.
On mobile layouts (Android and iOS apps), when Account A is on Home viewing the Insights chart, opens a Right Hand Panel (e.g., + -> Create expense), and Account B submits an expense to the workspace while that RHP is open, closing the RHP without making any changes causes Account A's Home Insights chart to refetch and update.
What is the root cause of that problem?
- PR
#106796removed livespendDataSignatureupdates from the Insights refresh key inuseInsightData.tsand wireduseTabFocusedRefresh(SCREENS.HOME, isScreenVisible, refreshOnReturn)(src/hooks/useTabFocusedRefresh.ts) so the chart only refreshes when returning toSCREENS.HOMEfrom another tab (isTabFocused && !wasTabFocusedsetsisRefreshPendingRef.current = true). - However, when Account A taps
+ -> Create expensefrom Home on a narrow layout (getIsNarrowLayout() === true),IOURequestStartPagemountsScanSkipConfirmation, which callsusePreMountDestination(skipConfirmationPreMountRoute)(src/hooks/usePreMountDestination/index.ts) forr/<reportID>(located insideTAB_NAVIGATOR -> NAVIGATORS.REPORTS_SPLIT_NAVIGATOR). - Once the RHP transition finishes,
Navigation.preInsertFullscreenUnderRHPdispatchesREPLACE_FULLSCREEN_UNDER_RHP.handleReplaceFullscreenUnderRHP(src/libs/Navigation/AppNavigator/createRootStackNavigator/GetStateForActionHandlers.ts) stores the originalHometab route inpreInsertedOriginalTabRouteand replaces the active tab underneath the RHP withNAVIGATORS.REPORTS_SPLIT_NAVIGATOR(index: 1). - While the RHP is open,
useIsTabFocused(SCREENS.HOME)(src/hooks/useIsTabFocused.ts) seesgetActiveTabName(topTabNavigator) === NAVIGATORS.REPORTS_SPLIT_NAVIGATORand flips fromtruetofalse, updatingwasTabFocusedRef.current = falseinsideuseTabFocusedRefresh. - When Account A closes the RHP without creating an expense,
removePreInsertedFullscreenIfNeeded(src/libs/Navigation/helpers/preMountBuffer.ts) revertsTAB_NAVIGATORback topreInsertedOriginalTabRoute(SCREENS.HOME).useIsTabFocused(SCREENS.HOME)transitionsfalse -> true, causinguseTabFocusedRefreshto treat the cancelled RHP pre-mount rollback as a genuine tab switch (isRefreshPendingRef.current = true) and callretry()(search()) as soon asHomePagebecomes visible.
What changes do you think we should make in order to solve the problem?
- Resolve the logically focused tab from
getPreInsertedOriginalTabRoute()insrc/hooks/useIsTabFocused.tswhile an unsubmitted RHP speculative pre-mount is active:- In
src/hooks/useIsTabFocused.ts, checkgetPreInsertedOriginalTabRoute()fromGetStateForActionHandlers: whentopTabNavigator?.keymatchespreInsertedOriginalTabRoute?.key, evaluategetActiveTabName(preInsertedOriginalTabRoute)instead oftopTabNavigator:import {getPreInsertedOriginalTabRoute} from '@libs/Navigation/AppNavigator/createRootStackNavigator/GetStateForActionHandlers'; import getActiveTabName from '@libs/Navigation/helpers/getActiveTabName'; import type {NavigationRoute} from '@libs/Navigation/types'; import NAVIGATORS from '@src/NAVIGATORS'; import useRootNavigationState from './useRootNavigationState'; function useIsTabFocused(tabName: string): boolean { return useRootNavigationState((state) => { if (!state) { return false; } const topTabNavigator = state.routes.findLast((route) => route.name === NAVIGATORS.TAB_NAVIGATOR) as NavigationRoute | undefined; const preInsertedOriginalTabRoute = getPreInsertedOriginalTabRoute() as NavigationRoute | undefined; const effectiveTabNavigator = topTabNavigator && preInsertedOriginalTabRoute?.key === topTabNavigator.key ? preInsertedOriginalTabRoute : topTabNavigator; return getActiveTabName(effectiveTabNavigator) === tabName; }); }
- In
- Keep
preInsertedOriginalTabRouteset untilTabActions.jumpToexecutes in therequestAnimationFramefallback ofremovePreInsertedFullscreenIfNeeded(src/libs/Navigation/helpers/preMountBuffer.ts):- Move
clearPreInsertedOriginalTabRoute()inside therequestAnimationFramecallback right beforenavigationRef.current?.dispatch(TabActions.jumpTo(originalTabName))so there is no intermediate render frame whereuseIsTabFocused(SCREENS.HOME)briefly flips tofalse.
- Move
- Add unit tests:
- In
tests/unit/useIsTabFocusedTest.tsandtests/unit/HomePage/InsightsSection/useInsightDataRefreshTest.ts, verify that dispatchingREPLACE_FULLSCREEN_UNDER_RHPfollowed byREMOVE_FULLSCREEN_UNDER_RHPkeepsuseIsTabFocused(SCREENS.HOME)trueand does not triggersearch().
- In
What alternative solutions did you explore? (Optional)
- Disabling
usePreMountDestinationwhen openingCreate expensefrom Home: Rejected because pre-mounting the destination report under the RHP is an intentional performance optimization for expense submission.
Reviewing this one today.
@mountiny @huult This looks like part of #106791, which says closing the Create expense panel shouldn't refresh the chart. It still does on mobile.
@huult could you take a look into this?
@huult could you take a look into this?
@mountiny Yes, I'm looking into this and will provide feedback soon.
@huult could you take a look into this?
Cause: When Create expense opens, the app pre-inserts the Spend tab under the RHP, so the active tab briefly switches from Home to Search. useIsTabFocused sees Home "lose focus and regain it", so useTabFocusedRefresh treats that as "returned to Home" and refreshes every card, including the chart, as soon as the RHP closes. It has nothing to do with another account's expense.
Fix: In useIsTabFocused, when an RHP is on top and its destination is pre-inserted underneath, report the original tab (Home) as still focused.
function useIsTabFocused(tabName: string): boolean {
return useRootNavigationState((state) => {
if (!state) {
return false;
}
+ const tabNavigatorIndex = state.routes.findLastIndex((route) => route.name === NAVIGATORS.TAB_NAVIGATOR);
const topTabNavigator = state.routes.findLast((route) => route.name === NAVIGATORS.TAB_NAVIGATOR) as NavigationRoute | undefined;
- return getActiveTabName(topTabNavigator) === tabName;
+ // Opening a flow such as Create expense pre-inserts its destination under the RHP, which makes another tab the
+ // active one while the RHP is still open. The user has not left the tab yet, and the original tab comes back if
+ // they close the RHP, so report the original one. Requiring an RHP above the tab ends this as soon as the RHP is gone.
+ const preInsertedOriginalTabRoute = getPreInsertedOriginalTabRoute();
+ const isDestinationPreInsertedUnderRHP =
+ !!preInsertedOriginalTabRoute &&
+ preInsertedOriginalTabRoute.key === topTabNavigator?.key &&
+ state.routes.slice(tabNavigatorIndex + 1).some((route) => isSideModalNavigator(route.name));
+ return getActiveTabName(isDestinationPreInsertedUnderRHP ? preInsertedOriginalTabRoute : topTabNavigator) === tabName;
});
}
https://github.com/user-attachments/assets/a9cefc09-a26b-45bd-967f-0d778158e615
@mountiny This issue is quite an edge case, and I think it has a different root cause from https://github.com/Expensify/App/issues/106791. Would you like to address this case as well?
Hi @linhvovan29546 , Since this ticket is related to one I've already worked on, but covers an edge case, I've already investigated it to identify the root cause and a solution. Would you mind if I took over this ticket?
Hi @linhvovan29546 , Since this ticket is related to one I've already worked on, but covers an edge case, I've already investigated it to identify the root cause and a solution. Would you mind if I took over this ticket?
Sure, go ahead!
yeah I think we should fix ti