App icon indicating copy to clipboard operation
App copied to clipboard

[Due for payment 2026-11-25] [$250] Android/iOS-Offline-Navigation arrows disappear after deleted expense syncs online

Open applause-bot[bot] opened this issue 1 month ago • 112 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.5-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/103109 Email or phone of affected tester (no customers): [email protected] Issue reported by: Applause Internal Team Bug source: Pull Request QA execution Device used: Samsung Galaxy S21/Android 15, iPhone 13/18.6.2 App Component: Other

Action Performed:

  1. Launch Expensify app
  2. Log in with valid credentials
  3. Open Home and make sure the Recently added section shows at least 3 expenses.
  4. Open dev tools and turn on Force offline.
  5. Open the first (newest) expense, then select More > Delete.
  6. Go back to Home and open the expense right under the deleted one.
  7. Turn off Force offline and wait for the delete to sync, keeping the expense open.

Expected Result:

The deleted expense is removed from Recently added, and the navigation arrows remain visible and allow navigation between expenses that were not deleted.

Actual Result:

After the delete syncs while the expense is open, the navigation arrows disappear.

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/600ae5fe-1a19-4ac9-a757-bb79be71eecc

View all open jobs on GitHub

Applause Internal Information Exported by: Mita Rachim Bug ID: 7280546

Upwork Automation - Do Not Edit
Issue OwnerCurrent Issue Owner: @mallenexpensify

applause-bot[bot] avatar Oct 08 '26 00:10 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/991fcc884615f7f34162ec2bb59523f8cd4800b9fe29cc80ee67921d351a60e3

applause-bot[bot] avatar Oct 08 '26 00:10 applause-bot[bot]

Proposal

What is the root cause of that problem?

The header remounts while the Test Tools modal covers the expense, and its unmount cleanup wipes the arrow list. The delete sync only coincides with this. Keep pending-delete expenses out of the Recently added carousel did not cause it, and the issue already reproduces in production.

  1. On native, deleting expense A leaves nvp_deleteTransactionNavigateBackURL set. The native stack unmounts A's screen right away, which cancels the pending clear in DeleteTransactionNavigateBackHandler.tsx:22-37.
  2. You open expense B, then open Test Tools to turn off Force offline. B loses focus, so B's own handler clears the URL.
  3. ReportNotFoundGuard.tsx:127-131 switches from bare children to <ReportNotFoundInnerGuard>. React then remounts the whole header.
  4. The old navigation component's cleanup in MoneyRequestReportTransactionsNavigation.tsx:209-217 sees TEST_TOOLS_MODAL.ROOT focused. That screen is not in CAROUSEL_PRESERVING_SCREENS, so the cleanup calls clearActiveTransactionIDs().
  5. The new component reads an empty list and renders no arrows. Nothing seeds the list again.

Web is not affected because the JS stack keeps the closing screen mounted through the animation, so step 1 clears the URL normally.

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

In the unmount cleanup of MoneyRequestReportTransactionsNavigation, skip clearActiveTransactionIDs() while the component's own route key (useRoute().key) is still in the navigation state. If the route is still there, the header remounted inside an open screen and the user did not leave. When the user really leaves, the route is gone from the state, so the list still clears. Use extractNavigationKeys from extractNavigationKeys.ts for the check.

Add a unit test in MoneyRequestReportTransactionsNavigation.test.tsx with a useRoute mock. The test should expect no clear when the route is still in the state while Test Tools is focused.

What alternative solutions did you explore? (Optional)

  • Stop ReportNotFoundGuard from changing its root element type, for example by always rendering the inner guard with an enabled flag. This prevents the remount, but the inner guard was split out for performance.
  • Clear the URL when the deleted screen leaves the stack on native. This fixes the leak, which also disables the deleted-parent "not found" check on the next expense you open. On its own it does not protect the arrows from other remounts.
Confidence and verification

Confidence is medium. This comes from reading the code. It has not been tested on a device, and the web tester can't reproduce a native-only bug. Two predictions would confirm it on Android/iOS:

  1. After steps 1–6, opening and closing Test Tools without going online also hides the arrows.
  2. Going online with airplane mode instead of Test Tools keeps the arrows.

The hook itself still returns the right siblings after the sync (useCarouselTransactionIDs.ts:26-47). The list goes empty only because the stored list was cleared.


Next Steps for Contributor+ team: To accept: @MelvinBot implement [this](https://github.com/Expensify/App/issues/103403) to create a draft PR. To refine: @MelvinBot <your feedback> To reject: Explain why you are rejecting Melvin's proposal.


view run

MelvinBot avatar Oct 08 '26 01:10 MelvinBot

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

melvin-bot[bot] avatar Oct 08 '26 01:10 melvin-bot[bot]

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

melvin-bot[bot] avatar Oct 08 '26 01:10 melvin-bot[bot]

Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~0163955a2ba22190aa

Proposal

Please re-state the problem that we are trying to solve in this issue.

In Android/iOS, after an expense is deleted while offline, opening an adjacent expense from the carousel and waiting for the offline delete to sync causes the navigation arrows in the header (MoneyRequestReportTransactionsNavigation) to disappear.

What is the root cause of that problem?

  1. Unnecessary Component Remounting in ReportNotFoundGuard.tsx: In src/pages/inbox/ReportNotFoundGuard.tsx:127-131:

    if (!deleteTransactionNavigateBackUrl && isReportTransactionThread(report)) {
        return <ReportNotFoundInnerGuard reportIDFromPath={routeParams?.reportID}>{children}</ReportNotFoundInnerGuard>;
    }
    
    return children;
    

    When an expense is deleted offline, deleteTransactionNavigateBackUrl is set in Onyx (ONYXKEYS.NVP_DELETE_TRANSACTION_NAVIGATE_BACK_URL). While it is set, ReportNotFoundGuard renders {children} directly. When the delete syncs and DeleteTransactionNavigateBackHandler clears deleteTransactionNavigateBackUrl, ReportNotFoundGuard switches from bare {children} to <ReportNotFoundInnerGuard>{children}</ReportNotFoundInnerGuard>. Because the element type changes at the guard root, React unmounts the entire children tree (including MoneyRequestHeader and MoneyRequestReportTransactionsNavigation) and mounts a new one.

  2. Premature Clearing in MoneyRequestReportTransactionsNavigation.tsx: In src/components/MoneyRequestReportView/MoneyRequestReportTransactionsNavigation.tsx:209-217:

    useEffect(() => {
        return () => {
            const focusedRoute = findFocusedRoute(navigationRef.getRootState());
            if (focusedRoute?.name && (CAROUSEL_PRESERVING_SCREENS as readonly string[]).includes(focusedRoute.name)) {
                return;
            }
            clearActiveTransactionIDs();
        };
    }, []);
    

    When the unmount cleanup fires:

    • If the user has opened the Test Tools modal to toggle offline mode, findFocusedRoute returns TEST_TOOLS_MODAL.ROOT (or SCREENS.RIGHT_MODAL.TEST_TOOLS), which is not in CAROUSEL_PRESERVING_SCREENS.
    • Checking only focusedRoute.name fails to distinguish between the user actually navigating away from the screen versus a modal being focused or an internal remount where the screen route is still intact in the navigation state.
    • Consequently, clearActiveTransactionIDs() is called, wiping ONYXKEYS.TRANSACTION_THREAD_NAVIGATION_TRANSACTION_IDS. When the re-mounted MoneyRequestReportTransactionsNavigation evaluates useCarouselTransactionIDs(), transactionIDsList is empty, causing lines 426-429 to return early and hide the arrows.

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

  1. Stabilize ReportNotFoundGuard.tsx to prevent tree remounts: Instead of conditionally swapping between {children} and <ReportNotFoundInnerGuard>{children}</ReportNotFoundInnerGuard>, always render <ReportNotFoundInnerGuard> for transaction threads and pass a condition (or check !deleteTransactionNavigateBackUrl internally in ReportNotFoundInnerGuard before determining shouldShowNotFoundPage):

    diff --git a/src/pages/inbox/ReportNotFoundGuard.tsx b/src/pages/inbox/ReportNotFoundGuard.tsx
    --- a/src/pages/inbox/ReportNotFoundGuard.tsx
    +++ b/src/pages/inbox/ReportNotFoundGuard.tsx
    @@ -127,5 +127,9 @@ function ReportNotFoundGuard({children}: ReportNotFoundGuardProps) {
    -    if (!deleteTransactionNavigateBackUrl && isReportTransactionThread(report)) {
    -        return <ReportNotFoundInnerGuard reportIDFromPath={routeParams?.reportID}>{children}</ReportNotFoundInnerGuard>;
    +    if (isReportTransactionThread(report)) {
    +        return (
    +            <ReportNotFoundInnerGuard
    +                reportIDFromPath={routeParams?.reportID}
    +                shouldCheckParent={!deleteTransactionNavigateBackUrl}
    +            >
    +                {children}
    +            </ReportNotFoundInnerGuard>
    +        );
         }
    

    In ReportNotFoundInnerGuard, if shouldCheckParent is false, set shouldShowNotFoundPage = false. This guarantees the component tree never unmounts due to deleteTransactionNavigateBackUrl updates.

  2. Harden MoneyRequestReportTransactionsNavigation.tsx unmount cleanup: In src/components/MoneyRequestReportView/MoneyRequestReportTransactionsNavigation.tsx, check whether the component's route key (useRoute().key) is still in the navigation state before clearing:

    const route = useRoute();
    useEffect(() => {
        return () => {
            const rootState = navigationRef.getRootState();
            const activeKeys = extractNavigationKeys(rootState);
            if (activeKeys.includes(route.key)) {
                return;
            }
            const focusedRoute = findFocusedRoute(rootState);
            if (focusedRoute?.name && (CAROUSEL_PRESERVING_SCREENS as readonly string[]).includes(focusedRoute.name)) {
                return;
            }
            clearActiveTransactionIDs();
        };
    }, [route.key]);
    

    Additionally, include SCREENS.RIGHT_MODAL.TEST_TOOLS in CAROUSEL_PRESERVING_SCREENS.

What alternative solutions did you explore? (Optional)

  • Only updating CAROUSEL_PRESERVING_SCREENS: Does not solve cases where other overlays or transient state transitions cause a remount while the screen route remains alive. Combining route key verification with ReportNotFoundGuard stabilization provides complete stability across both native and web platforms.

What specific scenarios should we cover in automated tests?

  1. In tests/unit/components/MoneyRequestReportTransactionsNavigation.test.tsx:
    • Verify that when MoneyRequestReportTransactionsNavigation unmounts while its route key is still in navigation state (or while a modal is focused), clearActiveTransactionIDs is not called.
  2. In tests/unit/ReportNotFoundGuardTest.tsx:
    • Verify that toggling deleteTransactionNavigateBackUrl does not cause children to unmount and remount.

jloa-dev avatar Oct 08 '26 03:10 jloa-dev

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

melvin-bot[bot] avatar Oct 08 '26 03:10 melvin-bot[bot]

Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~010e53044b5828fe60

Proposal

Please re-state the problem that we are trying to solve in this issue.

In Android/iOS, after an expense is deleted while offline, opening an adjacent expense from the carousel and waiting for the offline delete to sync causes the navigation arrows in the header (MoneyRequestReportTransactionsNavigation) to disappear.

What is the root cause of that problem?

The bug is caused by a race condition between a component tree remount in ReportNotFoundGuard and premature cache clearing in MoneyRequestReportTransactionsNavigation:

  1. Tree Remount in ReportNotFoundGuard.tsx: In src/pages/inbox/ReportNotFoundGuard.tsx:127-131:

    if (!deleteTransactionNavigateBackUrl && isReportTransactionThread(report)) {
        return <ReportNotFoundInnerGuard reportIDFromPath={routeParams?.reportID}>{children}</ReportNotFoundInnerGuard>;
    }
    
    return children;
    

    On native platforms, deleting an expense leaves deleteTransactionNavigateBackUrl set in Onyx because the native stack immediately unmounts the deleted expense screen, aborting the pending clear in DeleteTransactionNavigateBackHandler. When the user opens a sibling expense from the carousel, deleteTransactionNavigateBackUrl is initially truthy, so ReportNotFoundGuard renders {children} directly. When the user opens Test Tools or the offline action syncs, DeleteTransactionNavigateBackHandler clears deleteTransactionNavigateBackUrl. This causes ReportNotFoundGuard to switch from bare {children} to <ReportNotFoundInnerGuard>{children}</ReportNotFoundInnerGuard>. Because the root wrapper component type changes, React completely unmounts the existing {children} tree (including MoneyRequestHeader and MoneyRequestReportTransactionsNavigation) and mounts a new one.

  2. Premature Cache Clearing in MoneyRequestReportTransactionsNavigation.tsx: In src/components/MoneyRequestReportView/MoneyRequestReportTransactionsNavigation.tsx:209-217:

    useEffect(() => {
        return () => {
            const focusedRoute = findFocusedRoute(navigationRef.getRootState());
            if (focusedRoute?.name && (CAROUSEL_PRESERVING_SCREENS as readonly string[]).includes(focusedRoute.name)) {
                return;
            }
            clearActiveTransactionIDs();
        };
    }, []);
    

    When the unmount cleanup fires during the tree remount:

    • findFocusedRoute inspects the top of the stack. If Test Tools or another modal is open, its name is not in CAROUSEL_PRESERVING_SCREENS.
    • The cleanup assumes the user navigated away from the screen entirely and calls clearActiveTransactionIDs(), wiping ONYXKEYS.TRANSACTION_THREAD_NAVIGATION_TRANSACTION_IDS.
    • When the re-mounted MoneyRequestReportTransactionsNavigation evaluates useCarouselTransactionIDs(), the stored IDs list is empty, causing the component to return early and hide the arrows.

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

We should apply a two-layer fix to eliminate both the spurious tree remount and the unsafe unmount cleanup:

  1. In src/pages/inbox/ReportNotFoundGuard.tsx: Keep the component structure stable so deleteTransactionNavigateBackUrl changes do not unmount and remount {children}:

    if (isReportTransactionThread(report)) {
        return (
            <ReportNotFoundInnerGuard
                reportIDFromPath={routeParams?.reportID}
                shouldCheck={!deleteTransactionNavigateBackUrl}
            >
                {children}
            </ReportNotFoundInnerGuard>
        );
    }
    
    return children;
    

    Inside ReportNotFoundInnerGuard, if shouldCheck is false, bypass the parent report action check (setting shouldShowNotFoundPage = false). This guarantees {children} remains mounted without unmounting when deleteTransactionNavigateBackUrl updates.

  2. In src/components/MoneyRequestReportView/MoneyRequestReportTransactionsNavigation.tsx: Harden the unmount cleanup so it verifies whether the screen's route key is still in the active navigation state using extractNavigationKeys:

    const route = useRoute();
    useEffect(() => {
        return () => {
            const rootState = navigationRef.getRootState();
            const activeKeys = extractNavigationKeys(rootState?.routes);
            // If the route key is still present in the navigation hierarchy, the screen is still active (remount or modal overlay)
            if (activeKeys.has(route.key)) {
                return;
            }
    
            const focusedRoute = findFocusedRoute(rootState);
            if (focusedRoute?.name && (CAROUSEL_PRESERVING_SCREENS as readonly string[]).includes(focusedRoute.name)) {
                return;
            }
            clearActiveTransactionIDs();
        };
    }, [route.key]);
    

What specific scenarios should we cover in automated tests?

  1. In tests/unit/ReportNotFoundGuardTest.tsx:
    • Verify that updating deleteTransactionNavigateBackUrl from a URL to null does not trigger an unmount/remount of children.
  2. In tests/unit/components/MoneyRequestReportTransactionsNavigation.test.tsx:
    • Verify that when MoneyRequestReportTransactionsNavigation unmounts while its route key exists in extractNavigationKeys, clearActiveTransactionIDs is not invoked.
    • Verify that when the route key is removed from navigation state, clearActiveTransactionIDs is called as expected.

ashusatyarthi-wq avatar Oct 08 '26 05:10 ashusatyarthi-wq

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

melvin-bot[bot] avatar Oct 08 '26 05:10 melvin-bot[bot]

Proposal

Please re-state the problem that we are trying to solve in this issue.

On Android/iOS, when an expense is deleted while offline and the user opens an adjacent expense from the carousel, opening SCREENS.TEST_TOOLS_MODAL.ROOT (or waiting for the delete to sync online) causes the header navigation arrows to disappear.

What is the root cause of that problem?

The root cause consists of two intertwined issues in ReportNotFoundGuard and MoneyRequestReportTransactionsNavigation:

  1. Unnecessary Component Remounting in ReportNotFoundGuard.tsx: On native, deleting the first expense sets ONYXKEYS.NVP_DELETE_TRANSACTION_NAVIGATE_BACK_URL, and popping the deleted screen unmounts src/pages/inbox/DeleteTransactionNavigateBackHandler.tsx#L22-L37 (handle.cancel()) before the deferred clear runs. When the adjacent expense is opened, src/pages/inbox/ReportNotFoundGuard.tsx#L127-L131 conditionally wraps {children} in <ReportNotFoundInnerGuard> only when !deleteTransactionNavigateBackUrl && isReportTransactionThread(report). While deleteTransactionNavigateBackUrl is set, it renders bare {children}. As soon as SCREENS.TEST_TOOLS_MODAL.ROOT (or any overlay/edit modal) opens over the expense and blurs it, DeleteTransactionNavigateBackHandler clears deleteTransactionNavigateBackUrl, switching the returned JSX element from {children} to <ReportNotFoundInnerGuard>{children}</ReportNotFoundInnerGuard>. In React's reconciliation engine, changing the wrapper component type destroys and remounts the entire subtree, unmounting MoneyRequestReportTransactionsNavigation.

  2. Premature Cache Eviction in MoneyRequestReportTransactionsNavigation.tsx: During unmount, the cleanup effect in src/components/MoneyRequestReportView/MoneyRequestReportTransactionsNavigation.tsx#L211-L219 checks findFocusedRoute(navigationRef.getRootState()) against CAROUSEL_PRESERVING_SCREENS. Because SCREENS.TEST_TOOLS_MODAL.ROOT (or another overlay modal) is focused, it concludes navigation has exited the screen and unconditionally invokes clearActiveTransactionIDs(), wiping ONYXKEYS.TRANSACTION_THREAD_NAVIGATION_TRANSACTION_IDS. When the component remounts, the carousel transaction ID list in Onyx is empty, causing the component to render nothing and hiding the navigation arrows.

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

  1. In src/pages/inbox/ReportNotFoundGuard.tsx#L127-L164: Stabilize the component hierarchy so that updating deleteTransactionNavigateBackUrl does not alter the wrapper component structure. Always render ReportNotFoundInnerGuard when isReportTransactionThread(report) is true and pass a boolean prop (shouldCheckParent={!deleteTransactionNavigateBackUrl}) into ReportNotFoundInnerGuard. When shouldCheckParent is false, skip the parent report action not-found gate (shouldShowNotFoundPage = shouldCheckParent && (isParentActionDeleted || isParentActionMissingAfterLoad)). Non-thread reports continue returning children directly, while transaction threads never unmount {children} when deleteTransactionNavigateBackUrl clears under SCREENS.TEST_TOOLS_MODAL.ROOT or any other modal.

  2. In src/components/MoneyRequestReportView/MoneyRequestReportTransactionsNavigation.tsx#L211-L219: Harden the unmount cleanup hook so it does not clear transaction IDs while the hosting report screen remains mounted in navigation state. Capture the hosting route key via const route = useContext(NavigationRouteContext) and check extractNavigationKeys(navigationRef.getRootState()).has(route.key) in the unmount cleanup before calling clearActiveTransactionIDs(). Only execute clearActiveTransactionIDs() when the route has truly been removed from navigation state (and not preserved by CAROUSEL_PRESERVING_SCREENS).

What alternative solutions did you explore? (Optional)

  • Only adding SCREENS.TEST_TOOLS_MODAL.ROOT / SCREENS.TEST_TOOLS_MODAL.SERVER to CAROUSEL_PRESERVING_SCREENS: While that masks the Test Tools repro, it does not prevent the full ReportScreen unmount/remount cycle in ReportNotFoundGuard when deleteTransactionNavigateBackUrl clears, and any other overlay screen pushed over the expense (such as editing Description/Amount or viewing Receipt attachments) still wipes the arrows. Stabilizing ReportNotFoundGuard and guarding unmount cleanup by route presence fixes SCREENS.TEST_TOOLS_MODAL.ROOT and every overlay screen cleanly.

What specific scenarios should we cover in automated tests?

  1. In tests/unit/ReportNotFoundGuardTest.tsx:
  • Verify that transitioning deleteTransactionNavigateBackUrl from a non-empty string to undefined/null on a transaction thread maintains component stability without unmounting children.
  1. In tests/unit/components/MoneyRequestReportTransactionsNavigation.test.tsx:
  • Verify that unmounting while SCREENS.TEST_TOOLS_MODAL.ROOT is focused and the hosting route key remains in navigation state does not call clearActiveTransactionIDs.
  • Verify that navigating away (hosting route key removed from navigation state) still calls clearActiveTransactionIDs.

Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~0139ed4098bdc50182

bonnhatnguyen avatar Oct 08 '26 07:10 bonnhatnguyen

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

melvin-bot[bot] avatar Oct 08 '26 07:10 melvin-bot[bot]

@shubham1206agra

While testing this issue locally, I noticed an important finding regarding the root cause that contradicts the original issue description:

The issue description states that the navigation arrows disappear after the offline delete syncs online. However, as shown in the attached recording and screenshot, the delete sync has nothing to do with it. The navigation arrows disappear the exact moment the Dev Tools drawer opens on top of the expense, while the app is still completely offline.

Screenshot demonstrating this exact behavior:

Image

Video demonstrating this exact behavior:

https://github.com/user-attachments/assets/1e74a129-11d0-490b-9763-0c7b40b14861

This happens because opening an overlay modal causes the underlying expense screen to lose focus, which triggers an unnecessary component unmount/remount in the report guard and prematurely clears the cached carousel transaction IDs.

I have already tested and verified a clean, two-layer solution that:

  1. Prevents the unwanted screen unmount/remount when focus changes.
  2. Hardens the carousel unmount cleanup to avoid wiping navigation state while the screen remains active in navigation.

Would you like me to submit the full proposal for review?

Video showing the working fix:

https://github.com/user-attachments/assets/208c4ee8-98e6-4acc-a752-3fa0a0994420

emkhalid avatar Oct 09 '26 16:10 emkhalid

@shubham1206agra Huh... This is 4 days overdue. Who can take care of this?

melvin-bot[bot] avatar Oct 13 '26 21:10 melvin-bot[bot]

@shubham1206agra 6 days overdue. This is scarier than being forced to listen to Vogon poetry!

melvin-bot[bot] avatar Oct 15 '26 21:10 melvin-bot[bot]

@MelvinBot Try to focus the fix wrt TEST_TOOLS_MODAL.ROOT screen as shown here too https://github.com/Expensify/App/issues/103403#issuecomment-6084642140

shubham1206agra avatar Oct 18 '26 16:10 shubham1206agra

Proposal (updated, focused on TEST_TOOLS_MODAL.ROOT)

Please re-state the problem that we are trying to solve in this issue.

On Android/iOS, the expense navigation arrows disappear when you open Test Tools over an expense right after deleting another expense offline.

What is the root cause of that problem?

The delete sync is not the trigger. As emkhalid showed in this comment, the arrows vanish the moment Test Tools opens, while still offline.

  1. On native, the deleted expense's screen unmounts before it clears nvp_deleteTransactionNavigateBackURL, so the URL is left set (DeleteTransactionNavigateBackHandler.tsx:22-37).
  2. Opening Test Tools pushes SCREENS.TEST_TOOLS_MODAL.ROOT over the expense. The expense loses focus, and its handler clears the URL.
  3. ReportNotFoundGuard.tsx:127-131 then wraps its children in ReportNotFoundInnerGuard, which remounts the header.
  4. The old carousel's unmount cleanup sees TEST_TOOLS_MODAL.ROOT focused. That screen is not in CAROUSEL_PRESERVING_SCREENS, so the cleanup calls clearActiveTransactionIDs(). The remounted carousel finds an empty list and renders no arrows.

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

Add SCREENS.TEST_TOOLS_MODAL.ROOT and SCREENS.TEST_TOOLS_MODAL.SERVER to CAROUSEL_PRESERVING_SCREENS in MoneyRequestReportTransactionsNavigation.tsx.

Test Tools is a debug overlay. It never ends the expense-navigation flow, and closing it returns to the same expense screen. So a carousel teardown while Test Tools is focused must keep the list. SERVER is included because you can reach it from the Test Tools menu.

What specific scenarios should we cover in automated tests?

In tests/unit/components/MoneyRequestReportTransactionsNavigation.test.tsx, add both screens to the existing keeps the active transaction IDs when unmounting onto %s table.

What alternative solutions did you explore? (Optional)

  • Skip the clear while the component's own route key is still in the navigation state. This was my earlier proposal. It covers any overlay, but it changes more behavior than this bug needs.
  • Always render ReportNotFoundInnerGuard with an enabled flag so the header never remounts. This removes the remount, but it changes the guard that was split out for performance.
Confidence and side effects

Confidence is medium. This comes from reading the code and matches the Android recording in the linked comment. I did not test it on a device. Web is not affected, because the JS stack clears the URL normally in step 1, so the web tester can't reproduce it.

The change only affects teardown while Test Tools is focused. If the list is kept when it should not be, nothing breaks: the carousel renders nothing when the current expense is not in the list, and the next carousel overwrites the list.


Next Steps for Contributor+ team: To accept: @MelvinBot implement [this](https://github.com/Expensify/App/issues/103403) to create a draft PR. To refine: @MelvinBot <your feedback> To reject: Explain why you are rejecting Melvin's proposal.


view run

MelvinBot avatar Oct 18 '26 16:10 MelvinBot

@MelvinBot Try to focus the fix wrt TEST_TOOLS_MODAL.ROOT screen as shown here too #103403 (comment)

Comment By human and no automation!

@shubham1206agra

Thanks for looking into my finding! Before moving forward with MelvinBot's updated proposal, I wanted to point out a key limitation with that approach:

Adding TEST_TOOLS_MODAL to CAROUSEL_PRESERVING_SCREENS as in Melvin proposal is just a temporary band-aid:

  • It only handles Test Tools. If a user opens any other drawer, modal, or overlay over the expense, the screen still loses focus and the arrows disappear again.
  • It doesn't address the real bug: ReportNotFoundGuard is still unmounting and remounting the entire report screen when focus changes.

The proper fix is much simpler and directly targets the root cause in ReportNotFoundGuard.tsx:127-131:

https://github.com/Expensify/App/blob/ef784ba78226f211bbaa5d6698a5a162c20221e9/src/pages/inbox/ReportNotFoundGuard.tsx#L127-L131

Instead of conditionally swapping wrapper component types, keep ReportNotFoundInnerGuard mounted for transaction threads and pass shouldCheckParentAction={!deleteTransactionNavigateBackUrl}:

if (isReportTransactionThread(report)) {
    return (
        <ReportNotFoundInnerGuard
            reportIDFromPath={routeParams?.reportID}
            shouldCheckParentAction={!deleteTransactionNavigateBackUrl}
        >
            {children}
        </ReportNotFoundInnerGuard>
    );
}

return children;

And in ReportNotFoundInnerGuard:

const shouldShowNotFoundPage = shouldCheckParentAction && (isParentActionDeleted || isParentActionMissingAfterLoad);

This clean 4-line change stops the entire screen from remounting, avoids polluting carousel screens with debug modal names, and permanently fixes the issue for all modals.

I've already implemented and validated this locally (as shown in my previous fix video). If this approach looks good to you, I can post the full proposal so you can review it and we can get this resolved cleanly.

emkhalid avatar Oct 18 '26 18:10 emkhalid

:sos: C+ Help Wanted

shubham1206agra avatar Oct 19 '26 05:10 shubham1206agra

Proposal

What is the root cause of that problem?

The sync does not remove the arrows. The expense screen remounts while another screen covers it, and the carousel's unmount cleanup wipes the sibling list.

  1. Deleting an expense sets nvp_deleteTransactionNavigateBackURL, so the closing thread does not flash "not found". Its handler clears the URL only after the closing transition and cancels that on unmount, so on native the URL can still be set when the next expense is opened from Home:

https://github.com/Expensify/App/blob/f8bb9886c921b49056f054ead83d0f90d6257502/src/pages/inbox/DeleteTransactionNavigateBackHandler.tsx#L22-L37

  1. When that expense loses focus (Test Tools, or any page opened on top such as Description), its own handler clears the URL. ReportNotFoundGuard then stops returning bare children and wraps them in ReportNotFoundInnerGuard. The element type changes, so React remounts the whole report subtree, header included:

https://github.com/Expensify/App/blob/f8bb9886c921b49056f054ead83d0f90d6257502/src/pages/inbox/ReportNotFoundGuard.tsx#L127-L131

  1. The old carousel's cleanup runs during that remount. The focused route is the covering screen, not a carousel screen, so it calls clearActiveTransactionIDs():

https://github.com/Expensify/App/blob/f8bb9886c921b49056f054ead83d0f90d6257502/src/components/MoneyRequestReportView/MoneyRequestReportTransactionsNavigation.tsx#L209-L217

  1. The remounted header reads an empty list and renders no arrows, and nothing seeds it again:

https://github.com/Expensify/App/blob/f8bb9886c921b49056f054ead83d0f90d6257502/src/components/MoneyRequestReportView/MoneyRequestReportTransactionsNavigation.tsx#L432-L437

I did not reproduce this on Android/iOS yet. I seeded nvp_deleteTransactionNavigateBackURL on an open expense on dev web and measured the carousel: opening Test Tools cleared the URL, and 21 ms later that cleanup set transactionThreadNavigationTransactionIDs to null. The arrows stayed gone after closing it, and opening Description did the same.

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

Keep the guard's tree stable: always render ReportNotFoundInnerGuard for a transaction thread, and move the URL check into its not-found condition.

-    if (!deleteTransactionNavigateBackUrl && isReportTransactionThread(report)) {
+    if (isReportTransactionThread(report)) {
         return <ReportNotFoundInnerGuard reportIDFromPath={routeParams?.reportID}>{children}</ReportNotFoundInnerGuard>;
...
     const parentReportAction = useParentReportAction(report);
+    const [deleteTransactionNavigateBackUrl] = useOnyx(ONYXKEYS.NVP_DELETE_TRANSACTION_NAVIGATE_BACK_URL);
...
-    const shouldShowNotFoundPage = isParentActionDeleted || isParentActionMissingAfterLoad;
+    const shouldShowNotFoundPage = !deleteTransactionNavigateBackUrl && (isParentActionDeleted || isParentActionMissingAfterLoad);

Clearing the URL then no longer swaps the wrapper, so an open expense is never remounted under another screen.

With the change, the same seeded steps keep both arrows after Test Tools and after Description. Going back to Home still clears the list, and deleting still returns to Home with no "not found" flash.

What alternative solutions did you explore? (Optional)

  • Skip the clear while the cleanup's route key is still in the navigation state: the screen still remounts, and two existing tests render it without a navigator.
  • Clear the URL when the deleted screen unmounts: fixes only this trigger, not later URL changes.

yusufdeveloper2903 avatar Oct 19 '26 05:10 yusufdeveloper2903

Proposal

What is the root cause of that problem?

The arrows don't disappear because PR #103109 filtered the deleted row — that filter is working. Opening an expense from Home "Recently added" seeds the carousel with every sibling ID and hides only the pending-delete one, so [A, B, C] becomes [B, C] (useCarouselTransactionIDs.ts#L26-L47). Two entries is still enough to render arrows (MoneyRequestReportTransactionsNavigation.tsx#L435-L437). They vanish only because the whole seeded list gets wiped. Here's the chain:

  1. Home seeds the carousel (source home:recentlyAdded) and opens the expense on SEARCH_REPORT (RecentlyAddedSection/index.tsx#L92-L97). The whole report screen — header, actions, footer — renders inside ReportNotFoundGuard (ReportScreen.tsx#L128-L165).
  2. Because you deleted the previous expense offline, the global NVP_DELETE_TRANSACTION_NAVIGATE_BACK_URL is still set. While it's set, the guard returns the report body as bare children (ReportNotFoundGuard.tsx#L127-L131).
  3. Opening Test Tools unfocuses the expense, so its handler clears that URL after the transition settles (DeleteTransactionNavigateBackHandler.tsx#L22-L37).
  4. The instant the URL clears, the guard's return flips from bare children to <ReportNotFoundInnerGuard>{children}</ReportNotFoundInnerGuard> (L127-L131). The element type at that slot changes, so React tears down the entire children subtree and mounts a new one.
  5. In that teardown, the carousel component's unmount effect runs. It clears the list unless the focused route is in CAROUSEL_PRESERVING_SCREENS (MoneyRequestReportTransactionsNavigation.tsx#L209-L217, list at L38-L43). With Test Tools focused, the focused route is RIGHT_MODAL.TEST_TOOLS — not in the list — so it calls clearActiveTransactionIDs().
  6. The newly-mounted header reads an empty list, hits transactionIDsList.length < 2, and renders nothing. Nothing re-seeds, so the arrows are gone for good.

The true defect is the element-type swap at L127-L131. The outer guard already folds deleteTransactionNavigateBackUrl into its own not-found decision (L79); the bare-children branch exists only to suppress the inner guard's parent-deletion check during the back-navigation, and it pays for that with a full remount of the report screen every time the URL toggles. Web is unaffected because the deleted expense's screen stays mounted through its close animation, so step 2's URL never leaks past the delete.

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

Fix layer: render — ReportNotFoundGuard. Keep the element type at that slot stable so the report body never remounts when the URL toggles. Always render the inner guard for transaction threads and let it no-op its check while the URL is set, instead of swapping to bare children:

// ReportNotFoundGuard.tsx — stop swapping the wrapper component
if (isReportTransactionThread(report)) {
    return (
        <ReportNotFoundInnerGuard reportIDFromPath={routeParams?.reportID} isActive={!deleteTransactionNavigateBackUrl}>
            {children}
        </ReportNotFoundInnerGuard>
    );
}
return children;
// ReportNotFoundInnerGuard — gate the parent-deletion check on isActive (default true)
const shouldShowNotFoundPage = isActive && (isParentActionDeleted || isParentActionMissingAfterLoad);

Now toggling the URL only flips a prop. children stay mounted, the carousel component never unmounts, clearActiveTransactionIDs() never fires, and — as a bonus — the whole report view stops rebuilding on every offline-delete sync.

Race-free: this removes the remount structurally (stable element type), so there's no ordering between "URL clears" and "teardown fires." A teardown-side guard only narrows when the clear is safe; the subtree still remounts.

On the perf split: ReportNotFoundInnerGuard was separated so non-transaction-thread reports don't subscribe to the expensive parent keys. That still holds — I only always-mount it for transaction threads, which already mount it the instant the URL clears. The sole change is it stays mounted through the brief URL-set window instead of mounting a beat later; no additional reports start subscribing.

Verification: I read the code at 4bb6832 but couldn't run Jest — this checkout has no node_modules, so numbers below are the suites that constrain the change, not a run. The "clearing the carousel on unmount" block in tests/unit/components/MoneyRequestReportTransactionsNavigation.test.tsx (preserved screens → no clear; unrelated screen → clear) stays green because I don't touch that effect at all. For the fix itself, add a case to tests/unit/ReportNotFoundGuardTest.tsx: wrap a probe that counts its mounts, toggle NVP_DELETE_TRANSACTION_NAVIGATE_BACK_URL from a URL to null, and assert the probe mounts once — it mounts twice on main.

What alternative solutions did you explore? (Optional)

  • Clear NVP_DELETE_TRANSACTION_NAVIGATE_BACK_URL when the deleted expense's screen leaves the native stack (fix the leak at the source). Rejected: the leak is only one trigger — any future element-type change in this guard reintroduces the remount — and clearing the URL too eagerly brings back the not-found flash the URL exists to prevent.
  • Hardening the unmount cleanup so the clear survives a remount is a real improvement, but it treats the symptom and leaves the full report-screen rebuild in place; another contributor has taken that route.

Abdulloh0109 avatar Oct 19 '26 05:10 Abdulloh0109

Proposal

Please re-state the problem that we are trying to solve in this issue.

On Android/iOS, after deleting one expense offline and opening the next one, the prev/next arrows disappear from the open expense once the delete syncs. The arrows should stay and page between the expenses that are left.

What is the root cause of that problem?

The delete sync doesn't hide the arrows. Opening Test Tools to turn Force offline off does, because Test Tools blurs the expense screen and that sets off an unmount cleanup that assumes the user has left the expense.

On native, the deleted expense's screen unmounts before its deferred clear runs, and the cleanup cancels that clear. That leaves nvp_deleteTransactionNavigateBackURL set:

https://github.com/Expensify/App/blob/adb2c0217dceb9f5ac7fe6cced904ef0ebd87440/src/pages/inbox/DeleteTransactionNavigateBackHandler.tsx#L22-L37

When Test Tools opens over expense B, B loses focus and its own handler clears the URL. ReportNotFoundGuard then stops returning children directly and wraps them in ReportNotFoundInnerGuard. React sees a different tree, so the header remounts:

https://github.com/Expensify/App/blob/adb2c0217dceb9f5ac7fe6cced904ef0ebd87440/src/pages/inbox/ReportNotFoundGuard.tsx#L127-L131

The old carousel's cleanup only checks the focused route name against CAROUSEL_PRESERVING_SCREENS. TEST_TOOLS_MODAL.ROOT isn't on that list, so it wipes the list even though B's route is still in the stack under the modal:

https://github.com/Expensify/App/blob/adb2c0217dceb9f5ac7fe6cced904ef0ebd87440/src/components/MoneyRequestReportView/MoneyRequestReportTransactionsNavigation.tsx#L209-L217

https://github.com/Expensify/App/blob/adb2c0217dceb9f5ac7fe6cced904ef0ebd87440/src/libs/actions/TransactionThreadNavigation.ts#L179-L189

The remounted carousel then has fewer than two IDs and renders nothing:

https://github.com/Expensify/App/blob/adb2c0217dceb9f5ac7fe6cced904ef0ebd87440/src/components/MoneyRequestReportView/MoneyRequestReportTransactionsNavigation.tsx#L437-L439

I rebuilt that moment in a test: Test Tools focused, the expense route still nested in the RHP, and the header rewrapped like the guard does.

  • Root state at teardown: RightModalNavigator > SEARCH_REPORT (report-route-key), with TestToolsModalNavigator > TEST_TOOLS_MODAL.ROOT focused on top.
  • findFocusedRoute returns TEST_TOOLS_MODAL.ROOT, and it's not in the allowlist.
  • clearActiveTransactionIDs fired once on that remount (expected 0, got 1), while the screen that owns the carousel never left.
flowchart TD
    A["Delete expense A offline, open expense B"] -->|"A unmounts, deferred clear cancelled"| B["deleteTransactionNavigateBackURL stays set"]
    B -->|"Test Tools opens, B blurs"| C["B's handler clears the URL"]
    C -->|"guard wraps children in ReportNotFoundInnerGuard"| D["Header remounts, B's route still in the stack"]
    D -->|"focused route TEST_TOOLS_MODAL.ROOT not allowlisted"| E["clearActiveTransactionIDs fires"]
    E -->|"transactionIDsList.length < 2"| F["Arrows gone"]

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

The cleanup should tell an internal remount apart from actually leaving the expense. The carousel already sits inside the report screen, so it can capture its own useRoute().key. On unmount, if that key is still anywhere in navigationRef.getRootState(), the user hasn't left, and the list stays. The existing helper already walks nested states, which matters because the report route sits under the modal navigator:

https://github.com/Expensify/App/blob/adb2c0217dceb9f5ac7fe6cced904ef0ebd87440/src/libs/Navigation/helpers/extractNavigationKeys.ts#L10-L35

+    const {key: routeKey} = useRoute();
 ...
         return () => {
-            const focusedRoute = findFocusedRoute(navigationRef.getRootState());
+            const rootState = navigationRef.getRootState();
+            if (extractNavigationKeys(rootState?.routes).has(routeKey)) {
+                return;
+            }
+            const focusedRoute = findFocusedRoute(rootState);
             if (focusedRoute?.name && (CAROUSEL_PRESERVING_SCREENS as readonly string[]).includes(focusedRoute.name)) {
                 return;
             }
             clearActiveTransactionIDs();
         };
-    }, []);
+    }, [routeKey]);

The CAROUSEL_PRESERVING_SCREENS check stays as it is for the case it was written for: the expense route is gone but the user is still inside the carousel flow (#90366). Going back from the expense removes its route key, so every real exit still reaches clearActiveTransactionIDs().

I ran this against the same setup. With the fix, the remount under Test Tools no longer clears the list. When the expense route itself is gone while Test Tools is focused, it still clears. I added both cases to MoneyRequestReportTransactionsNavigation.test.tsx. The first one fails on current main and passes with the change, and the existing allowlist and unrelated-screen tests still pass.

What alternative solutions did you explore? (Optional)

Adding TEST_TOOLS_MODAL.ROOT and SERVER to CAROUSEL_PRESERVING_SCREENS makes this one repro go away. But the bug isn't really about Test Tools. Any modal outside the list that blurs the expense while that stale URL is set causes the same rewrap and the same wipe, and the allowlist would need another entry each time someone finds one. It also changes the wrong thing: it keeps the list whenever Test Tools is focused, even if the expense route has really gone. The route-key check only skips the clear when the screen that owns the carousel is provably still mounted.

Always mounting ReportNotFoundInnerGuard behind a flag would stop the remount too. That would undo the split that keeps parentReportAction subscriptions off non-thread report screens, so I'd rather leave the guard alone.

https://github.com/user-attachments/assets/8269f30c-6d6e-4e75-a83e-82f6fb10fb90

https://github.com/user-attachments/assets/f7c8dfce-05d3-4c16-8696-b0c57559d205

mukhrr avatar Oct 19 '26 05:10 mukhrr