From 6b96119d801b8ba873f40597856113d6b253a8d5 Mon Sep 17 00:00:00 2001 From: Lukasz Modzelewski Date: Fri, 16 Oct 2026 09:51:20 +0200 Subject: [PATCH 1/3] Defer navigation after draft workspace merges to avoid recipient picker flash --- src/libs/actions/IOU/StartExpenseFlows.ts | 17 +++++++++++------ tests/actions/IOU/CreateDraftTransactionTest.ts | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/libs/actions/IOU/StartExpenseFlows.ts b/src/libs/actions/IOU/StartExpenseFlows.ts index 01b7c63749af..cbc3829d91a0 100644 --- a/src/libs/actions/IOU/StartExpenseFlows.ts +++ b/src/libs/actions/IOU/StartExpenseFlows.ts @@ -183,17 +183,22 @@ function createDraftWorkspaceAndNavigateToConfirmationScreen( }, ]); setMoneyRequestReportID(transactionID, expenseChatReportID); - if (isCategorizing) { - Navigation.navigate( - createDynamicRoute(DYNAMIC_ROUTES.MONEY_REQUEST_STEP_CATEGORY.getRoute({action: actionName, iouType: CONST.IOU.TYPE.SUBMIT, transactionID, reportID: expenseChatReportID})), - ); - } else { + // The participants/reportID merges above land a microtask later, but a navigation dispatched from a press handler + // renders the next screen synchronously, so it would first read the draft without participants (and e.g. flash the + // participant picker on the confirmation page). Defer navigation until the merges have been applied. + Navigation.setNavigationActionToMicrotaskQueue(() => { + if (isCategorizing) { + Navigation.navigate( + createDynamicRoute(DYNAMIC_ROUTES.MONEY_REQUEST_STEP_CATEGORY.getRoute({action: actionName, iouType: CONST.IOU.TYPE.SUBMIT, transactionID, reportID: expenseChatReportID})), + ); + return; + } // The confirmation route needs a `:reportID`, so it points at the (draft) workspace expense chat to resolve the // draft policy/destination. That report only lives in REPORT_DRAFT. Send back to the origin report (e.g. the // self-DM the track expense came from) so navigateBack returns there instead of the draft report's start step. const backTo = backToReportID ? ROUTES.REPORT_WITH_ID.getRoute(backToReportID) : undefined; Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_CONFIRMATION.getRoute(actionName, CONST.IOU.TYPE.SUBMIT, transactionID, expenseChatReportID, undefined, true, backTo)); - } + }); } type CreateDraftTransactionParams = { diff --git a/tests/actions/IOU/CreateDraftTransactionTest.ts b/tests/actions/IOU/CreateDraftTransactionTest.ts index 4459c006b259..d88f85a470dc 100644 --- a/tests/actions/IOU/CreateDraftTransactionTest.ts +++ b/tests/actions/IOU/CreateDraftTransactionTest.ts @@ -39,7 +39,7 @@ jest.mock('@src/libs/Navigation/Navigation', () => ({ dismissModalWithReport: jest.fn(), goBack: jest.fn(), getTopmostReportId: jest.fn(() => topMostReportID), - setNavigationActionToMicrotaskQueue: jest.fn(), + setNavigationActionToMicrotaskQueue: jest.fn((callback: () => void) => callback()), removeScreenByKey: jest.fn(), isNavigationReady: jest.fn(() => Promise.resolve()), getReportRouteByID: jest.fn(), From 6733889cf8556ed1c7a98a966b2474ac39ed9659 Mon Sep 17 00:00:00 2001 From: Lukasz Modzelewski Date: Fri, 16 Oct 2026 09:57:34 +0200 Subject: [PATCH 2/3] Remove redundant navigation comment --- src/libs/actions/IOU/StartExpenseFlows.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/libs/actions/IOU/StartExpenseFlows.ts b/src/libs/actions/IOU/StartExpenseFlows.ts index cbc3829d91a0..58594d9b5b5a 100644 --- a/src/libs/actions/IOU/StartExpenseFlows.ts +++ b/src/libs/actions/IOU/StartExpenseFlows.ts @@ -183,9 +183,6 @@ function createDraftWorkspaceAndNavigateToConfirmationScreen( }, ]); setMoneyRequestReportID(transactionID, expenseChatReportID); - // The participants/reportID merges above land a microtask later, but a navigation dispatched from a press handler - // renders the next screen synchronously, so it would first read the draft without participants (and e.g. flash the - // participant picker on the confirmation page). Defer navigation until the merges have been applied. Navigation.setNavigationActionToMicrotaskQueue(() => { if (isCategorizing) { Navigation.navigate( From 3bb905136ea4e9a51606f42fa7297ef595fdc393 Mon Sep 17 00:00:00 2001 From: Lukasz Modzelewski Date: Fri, 16 Oct 2026 10:59:55 +0200 Subject: [PATCH 3/3] Explain navigation deferral and add regression test for recipient picker flash --- src/libs/actions/IOU/StartExpenseFlows.ts | 3 ++ .../actions/IOU/CreateDraftTransactionTest.ts | 38 +++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/src/libs/actions/IOU/StartExpenseFlows.ts b/src/libs/actions/IOU/StartExpenseFlows.ts index 58594d9b5b5a..10db3a9329c4 100644 --- a/src/libs/actions/IOU/StartExpenseFlows.ts +++ b/src/libs/actions/IOU/StartExpenseFlows.ts @@ -183,6 +183,9 @@ function createDraftWorkspaceAndNavigateToConfirmationScreen( }, ]); setMoneyRequestReportID(transactionID, expenseChatReportID); + // The participants and reportID above are written with Onyx.merge, which lands a microtask after this press handler. + // Navigating synchronously would render the confirmation screen before the merge, so it would see no participants and + // auto-open the Choose recipient picker. Defer navigation by a microtask plus an animation frame so the merge is applied first. Navigation.setNavigationActionToMicrotaskQueue(() => { if (isCategorizing) { Navigation.navigate( diff --git a/tests/actions/IOU/CreateDraftTransactionTest.ts b/tests/actions/IOU/CreateDraftTransactionTest.ts index d88f85a470dc..4ac8f0f4d40e 100644 --- a/tests/actions/IOU/CreateDraftTransactionTest.ts +++ b/tests/actions/IOU/CreateDraftTransactionTest.ts @@ -714,6 +714,44 @@ describe('actions/IOU', () => { expect(getConfirmationRouteBackTo()).toBe(ROUTES.REPORT_WITH_ID.getRoute(selfDMReport.reportID)); }); + it('should defer navigating to the confirmation page until the draft workspace is merged in as the recipient', async () => { + // Given the real navigation deferral rather than the synchronous mock used by the other tests + const {selfDMReport, trackedExpense} = await setUpSelfDMTrackedExpense(); + mockedIsReportTopmostSplitNavigator.mockReturnValue(false); + jest.mocked(Navigation.setNavigationActionToMicrotaskQueue).mockImplementationOnce( + jest.requireActual<{default: typeof Navigation.setNavigationActionToMicrotaskQueue}>('@libs/Navigation/helpers/setNavigationActionToMicrotaskQueue').default, + ); + + // When the expense is submitted to the employer and there is no workspace to submit to + createDraftTransactionAndNavigateToParticipantSelector({ + reportID: selfDMReport.reportID, + reportActions: undefined, + actionName: CONST.IOU.ACTION.SUBMIT, + reportActionID: '1', + introSelected: {choice: CONST.ONBOARDING_CHOICES.MANAGE_TEAM}, + draftTransactionIDs: [], + activePolicy: undefined, + userBillingGracePeriodEnds: undefined, + amountOwed: 0, + transaction: trackedExpense, + currentUserAccountID: RORY_ACCOUNT_ID, + currentUserEmail: RORY_EMAIL, + currentUserLocalCurrency: '', + submitDestination: CONST.IOU.SUBMIT_DESTINATION.EMPLOYER, + defaultWorkspaceName: "Rory's Workspace", + filteredPoliciesCount: 0, + firstPolicy: undefined, + }); + + // Then navigation does not happen synchronously, because the participants merge has not landed yet and the + // confirmation page would render without a recipient and auto-open the Choose recipient picker + expect(Navigation.navigate).not.toHaveBeenCalled(); + + // And it happens once the merge has been applied + await waitForBatchedUpdates(); + expect(getConfirmationRouteBackTo()).toBe(ROUTES.REPORT_WITH_ID.getRoute(selfDMReport.reportID)); + }); + it('should leave the draft transaction unreported when the destination picker is shown', async () => { // Given a tracked self DM expense and more than one workspace the user can submit to const {selfDMReport, trackedExpense} = await setUpSelfDMTrackedExpense();