App icon indicating copy to clipboard operation
App copied to clipboard

[$175] 106796 - Android - Home - Chart updates when closing RHP with no changes

Open applause-bot[bot] opened this issue 2 weeks ago • 17 comments

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

  1. Open Expensify mobile app
  2. Go to Home, scroll to insight chart
  3. Open RHP, for example, tap + -> create expense
  4. On a different session as account B submit an expense to the Workspace
  5. 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

View all open jobs on GitHub

Applause Internal Information Exported by: Alberto Gutierrez Bug ID: 7313199

Upwork Automation - Do Not Edit

applause-bot[bot] avatar Nov 13 '26 16:11 applause-bot[bot]

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

applause-bot[bot] avatar Nov 13 '26 16:11 applause-bot[bot]

Triggered auto assignment to Contributor-plus team member for initial proposal review - @linhvovan29546 (External)

melvin-bot[bot] avatar Nov 13 '26 16:11 melvin-bot[bot]

Job added to Upwork: https://www.upwork.com/jobs/~022121282404764323273

melvin-bot[bot] avatar Nov 13 '26 16:11 melvin-bot[bot]

⚠️ 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.


view run

MelvinBot avatar Nov 13 '26 16:11 MelvinBot

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:

  1. 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!
  1. 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:

  1. getPreservedNavigatorState(route.key) (where useNativeTabNavigator preserves realized tab state during stack navigation).
  2. getTabScreenParam(route) (the initial or target screen parameter).
  3. 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

  1. ** 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.
  2. ** 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

kevinjosh10 avatar Nov 13 '26 17:11 kevinjosh10

✅ Contributor details stored successfully. Thank you for contributing to Expensify!

melvin-bot[bot] avatar Nov 13 '26 17:11 melvin-bot[bot]

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?

  1. PR #106796 stopped useInsightData (src/pages/home/InsightsSection/hooks/useInsightData.ts) from auto-refetching on live spendDataSignature changes, relying on useTabFocusedRefresh(SCREENS.HOME, isScreenVisible, refreshOnReturn) (src/hooks/useTabFocusedRefresh.ts) so Home only refreshes when the user switches back to SCREENS.HOME from another tab (isTabFocused && !wasTabFocused -> isRefreshPendingRef.current = true).
  2. However, when Account A taps + -> Create expense over Home, IOURequestStartPage mounts ScanSkipConfirmation (src/pages/iou/request/step/IOURequestStepScan/components/ScanSkipConfirmation.tsx, and similarly IOURequestStepAmount / DynamicIOURequestStepDistance / useSubmitDestinationPreMount), which resolves skipConfirmationPreMountRoute (r/<reportID>, whose fullscreen destination lives inside TAB_NAVIGATOR -> NAVIGATORS.REPORTS_SPLIT_NAVIGATOR) and calls usePreMountDestination(skipConfirmationPreMountRoute) (src/hooks/usePreMountDestination/index.ts).
  3. Once the RHP open transition completes, usePreMountDestination invokes Navigation.preInsertFullscreenUnderRHP(route) (src/libs/Navigation/Navigation.ts):
    • On wide desktop layouts (!getIsNarrowLayout()), preInsertFullscreenUnderRHP calls preMountFullscreenOnWide -> preMountWideDestinationInTab (src/libs/Navigation/helpers/wideTabPreMount.ts), which keeps tabState.index on SCREENS.HOME (0) and only appends REPORTS_SPLIT_NAVIGATOR to preloadedRouteKeys—which is why this bug does not reproduce on desktop Chrome.
    • On narrow mobile layouts (getIsNarrowLayout() === true), preInsertFullscreenUnderRHP dispatches CONST.NAVIGATION.ACTION_TYPE.REPLACE_FULLSCREEN_UNDER_RHP. handleReplaceFullscreenUnderRHP (src/libs/Navigation/AppNavigator/createRootStackNavigator/GetStateForActionHandlers.ts) saves the original Home tab route in preInsertedOriginalTabRoute and mutates the live TAB_NAVIGATOR state underneath the open RHP from [Tab(SCREENS.HOME), RHP] (index: 0) to [Tab(NAVIGATORS.REPORTS_SPLIT_NAVIGATOR), RHP] (index: 1).
  4. Because HomePage stays mounted inside TabNavigator while topTabNavigator switches to NAVIGATORS.REPORTS_SPLIT_NAVIGATOR underneath the RHP, useIsTabFocused(SCREENS.HOME) (src/hooks/useIsTabFocused.ts) flips from true to false, setting wasTabFocusedRef.current = false inside useTabFocusedRefresh.
  5. When Account A closes the RHP without submitting, usePreMountDestination's cleanup (removePreInsertedFullscreenIfNeeded -> handleRemoveFullscreenUnderRHP / revertPreMountBufferIfRHPClosed) rolls TAB_NAVIGATOR back to preInsertedOriginalTabRoute (SCREENS.HOME). useIsTabFocused(SCREENS.HOME) transitions false -> true, causing useTabFocusedRefresh to mistake the cancelled speculative pre-mount rollback for a real tab switch (isRefreshPendingRef.current = true) and fire retry() (search()) as soon as HomePage becomes visible again.

What changes do you think we should make in order to solve the problem?

  1. Treat preInsertedOriginalTabRoute as the logically focused tab in src/hooks/useIsTabFocused.ts while a speculative tab-switch pre-insertion is active behind an unsubmitted RHP: GetStateForActionHandlers.ts already tracks getPreInsertedOriginalTabRoute() for the exact lifetime of a speculative TAB_NAVIGATOR switch under an RHP—setting it synchronously in handleReplaceFullscreenUnderRHP, restoring the tab and clearing it simultaneously in handleRemoveFullscreenUnderRHP / revertPreMountBufferIfRHPClosed when the RHP is dismissed without submitting, and clearing it in clearFullscreenPreInsertedFlag() when the user actually submits/reveals the destination. Update src/hooks/useIsTabFocused.ts to read getPreInsertedOriginalTabRoute(): when topTabNavigator matches preInsertedOriginalTabRoute?.key, resolve getActiveTabName(preInsertedOriginalTabRoute) instead of the speculatively pre-inserted topTabNavigator:
    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, effectiveTabNavigator remains Tab(SCREENS.HOME) throughout (true -> true -> true), preventing any false false -> true transition on Home (and also preventing premature useIsTabFocused arrival 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() clears preInsertedOriginalTabRoute, cleanly transitioning useIsTabFocused from SCREENS.HOME to the revealed destination tab.
  2. Avoid a 1-frame gap in the requestAnimationFrame fallback of removePreInsertedFullscreenIfNeeded (src/libs/Navigation/helpers/preMountBuffer.ts): In the fallback branch of removePreInsertedFullscreenIfNeeded (used when RHP inner stack depth prevented PRE_MOUNT_BUFFER insertion and the RHP already closed before cleanup), move clearPreInsertedOriginalTabRoute() inside the requestAnimationFrame callback right before navigationRef.current?.dispatch(TabActions.jumpTo(originalTabName)) (and into the !originalTabName early return), so getPreInsertedOriginalTabRoute() stays populated until TabActions.jumpTo restores the original tab.
  3. Add unit tests in tests/unit/useIsTabFocusedTest.ts (and tests/unit/useInsightDataRefreshTest.ts) verifying that REPLACE_FULLSCREEN_UNDER_RHP followed by REMOVE_FULLSCREEN_UNDER_RHP (cancel RHP) keeps useIsTabFocused(SCREENS.HOME) true and never triggers search(), whereas committing via clearFullscreenPreInsertedFlag() transitions useIsTabFocused(SCREENS.HOME) to false so a subsequent return to Home refreshes as expected.

What alternative solutions did you explore? (Optional)

  • Falling back to getPreservedNavigatorState(route.key) when route.state is undefined in getActiveTabName: Does not solve the bug because topTabNavigator.state is not undefined here—handleReplaceFullscreenUnderRHP assigns a realized NavigationState with index: 1 (NAVIGATORS.REPORTS_SPLIT_NAVIGATOR), and useNativeTabNavigator also updates preservedNavigatorState with that pre-inserted state.
  • Skipping usePreMountDestination when opening + -> Create expense from SCREENS.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 fixing useIsTabFocused at the source protects all consumers (useInsightData, RecentlyAddedSection, YourSpendSection, useIsWorkspacesTabFocused) uniformly.

cocvn157 avatar Nov 14 '26 02:11 cocvn157

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 getActiveTabName fallback assumes route.state is undefined, but the handler writes a full state, so it changes nothing here.
  • cocvn157 has the same cause; I leave out the preMountBuffer requestAnimationFrame edit, which this fix does not need.
  • A flag in the shared useTabFocusedRefresh: fixing the source hook is cleaner.

Stephen3453 avatar Nov 15 '26 05:11 Stephen3453

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?

  1. PR #106796 removed live spendDataSignature updates from the Insights refresh key in useInsightData.ts and wired useTabFocusedRefresh(SCREENS.HOME, isScreenVisible, refreshOnReturn) (src/hooks/useTabFocusedRefresh.ts) so the chart only refreshes when returning to SCREENS.HOME from another tab (isTabFocused && !wasTabFocused sets isRefreshPendingRef.current = true).
  2. However, when Account A taps + -> Create expense from Home on a narrow layout (getIsNarrowLayout() === true), IOURequestStartPage mounts ScanSkipConfirmation, which calls usePreMountDestination(skipConfirmationPreMountRoute) (src/hooks/usePreMountDestination/index.ts) for r/<reportID> (located inside TAB_NAVIGATOR -> NAVIGATORS.REPORTS_SPLIT_NAVIGATOR).
  3. Once the RHP transition finishes, Navigation.preInsertFullscreenUnderRHP dispatches REPLACE_FULLSCREEN_UNDER_RHP. handleReplaceFullscreenUnderRHP (src/libs/Navigation/AppNavigator/createRootStackNavigator/GetStateForActionHandlers.ts) stores the original Home tab route in preInsertedOriginalTabRoute and replaces the active tab underneath the RHP with NAVIGATORS.REPORTS_SPLIT_NAVIGATOR (index: 1).
  4. While the RHP is open, useIsTabFocused(SCREENS.HOME) (src/hooks/useIsTabFocused.ts) sees getActiveTabName(topTabNavigator) === NAVIGATORS.REPORTS_SPLIT_NAVIGATOR and flips from true to false, updating wasTabFocusedRef.current = false inside useTabFocusedRefresh.
  5. When Account A closes the RHP without creating an expense, removePreInsertedFullscreenIfNeeded (src/libs/Navigation/helpers/preMountBuffer.ts) reverts TAB_NAVIGATOR back to preInsertedOriginalTabRoute (SCREENS.HOME). useIsTabFocused(SCREENS.HOME) transitions false -> true, causing useTabFocusedRefresh to treat the cancelled RHP pre-mount rollback as a genuine tab switch (isRefreshPendingRef.current = true) and call retry() (search()) as soon as HomePage becomes visible.

What changes do you think we should make in order to solve the problem?

  1. Resolve the logically focused tab from getPreInsertedOriginalTabRoute() in src/hooks/useIsTabFocused.ts while an unsubmitted RHP speculative pre-mount is active:
    • In src/hooks/useIsTabFocused.ts, check getPreInsertedOriginalTabRoute() from GetStateForActionHandlers: when topTabNavigator?.key matches preInsertedOriginalTabRoute?.key, evaluate getActiveTabName(preInsertedOriginalTabRoute) instead of topTabNavigator:
      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;
          });
      }
      
  2. Keep preInsertedOriginalTabRoute set until TabActions.jumpTo executes in the requestAnimationFrame fallback of removePreInsertedFullscreenIfNeeded (src/libs/Navigation/helpers/preMountBuffer.ts):
    • Move clearPreInsertedOriginalTabRoute() inside the requestAnimationFrame callback right before navigationRef.current?.dispatch(TabActions.jumpTo(originalTabName)) so there is no intermediate render frame where useIsTabFocused(SCREENS.HOME) briefly flips to false.
  3. Add unit tests:
    • In tests/unit/useIsTabFocusedTest.ts and tests/unit/HomePage/InsightsSection/useInsightDataRefreshTest.ts, verify that dispatching REPLACE_FULLSCREEN_UNDER_RHP followed by REMOVE_FULLSCREEN_UNDER_RHP keeps useIsTabFocused(SCREENS.HOME) true and does not trigger search().

What alternative solutions did you explore? (Optional)

  • Disabling usePreMountDestination when opening Create expense from Home: Rejected because pre-mounting the destination report under the RHP is an intentional performance optimization for expense submission.

U-ITACHII avatar Nov 15 '26 10:11 U-ITACHII

Reviewing this one today.

linhvovan29546 avatar Nov 17 '26 03:11 linhvovan29546

@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.

linhvovan29546 avatar Nov 17 '26 08:11 linhvovan29546

@huult could you take a look into this?

mountiny avatar Nov 18 '26 00:11 mountiny

@huult could you take a look into this?

@mountiny Yes, I'm looking into this and will provide feedback soon.

huult avatar Nov 18 '26 02:11 huult

@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?

huult avatar Nov 18 '26 05:11 huult

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?

huult avatar Nov 18 '26 05:11 huult

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!

linhvovan29546 avatar Nov 18 '26 07:11 linhvovan29546

yeah I think we should fix ti

mountiny avatar Nov 19 '26 01:11 mountiny