Skip to content

Fix device back from Submit to my employer confirmation landing on the workspace chat - #97512

Merged
carlosmiceli merged 1 commit into
Expensify:mainfrom
abzokhattab:fix/97437-submit-employer-device-back
Aug 18, 2026
Merged

carlosmiceli merged 1 commit into
Expensify:mainfrom
abzokhattab:fix/97437-submit-employer-device-back

Conversation

@abzokhattab

@abzokhattab abzokhattab commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

Problem: pressing the device back button on the "Submit it to my employer" confirmation page leaves you on the workspace chat instead of the self DM you started from.

Cause: the confirmation RHP pre-mounts its destination report underneath itself, so submitting reveals an already-rendered screen. This flow rebinds the draft to the workspace chat before the confirmation opens, so the destination is a chat the user has never visited while they are still looking at their self DM. Both are reports, so there is no tab to switch to and the pre-mount overwrites the visible report in place. Back pops the RHP and reveals that overwritten screen.

Cleaning it up afterwards doesn't work. The pop happens before the cleanup runs, so the workspace chat is already on screen for the whole dismiss animation, and any restore that follows shows the wrong screen first and then jumps.

Fix: don't pre-mount in this case. Skip it when a tracked expense is being relocated (submit/share/categorize) to a report other than the one currently on screen. Backing out is then a true no-op, and submitting falls through to the existing dismiss-and-navigate path already used whenever the pre-mount isn't eligible.

Unaffected: in-place expense creation, Search pre-mounts, cross-tab pre-mounts, and skip-confirmation flows.

Fixed Issues

$ #97437
PROPOSAL:

Tests

With the submit2026 beta enabled, on an account with a self DM and exactly one paid workspace, on Android (or any narrow layout):

  1. Open the self DM and create a manual expense.
  2. On the expense whisper, tap Submit it to my employer — the confirmation page opens directly (no destination picker).
  3. Press the device back button.
  4. Verify you land back on the self DM, with no flash of the workspace chat on the way.
  5. Repeat steps 1–2, then tap Submit instead of backing out, and verify you still land on the workspace chat.

Regression checks for flows that keep the pre-mount:

  1. From the Inbox tab, create and submit an expense in a chat you are already viewing, and verify it behaves as before.
  2. From the global create (FAB) on the Inbox tab, submit an expense and verify you still land on Search.
  • Verify that no errors appear in the JS console

Offline tests

Same as Tests while offline — the flow is navigation-only, so behavior is identical.

QA Steps

  1. On an account with the submit2026 beta, a self DM and exactly one paid workspace, create a manual expense in the self DM on Android.
  2. Tap Submit it to my employer, then press the device back button on the confirmation page.
  3. Verify you return to the self DM instead of the workspace chat.
  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Screen.Recording.2026-08-08.at.16.15.54.mov
Android: mWeb Chrome
Screen.Recording.2026-08-04.at.22.53.03.mov
iOS: Native
Screen.Recording.2026-08-04.at.23.07.47.mov
iOS: mWeb Safari
Screen.Recording.2026-08-04.at.23.09.31.mov
MacOS: Chrome / Safari
Screen.Recording.2026-08-04.at.22.49.47.mov

@codecov

codecov Bot commented Jul 30, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ Changes either increased or maintained existing code coverage, great job!

Files with missing lines Coverage Δ
...es/iou/request/step/IOURequestStepConfirmation.tsx 73.90% <100.00%> (+0.56%) ⬆️
...mation/getSubmitExpensePreMountDestinationRoute.ts 100.00% <100.00%> (ø)
... and 983 files with indirect coverage changes

@abzokhattab
abzokhattab force-pushed the fix/97437-submit-employer-device-back branch 2 times, most recently from 9c8baac to 21cdb27 Compare August 8, 2026 14:36
…r a visible report

Submitting, sharing or categorizing a tracked expense rebinds the draft to its
destination chat before the confirmation screen opens, so the destination is a
report the user has never been on while they are still looking at the one they
started from. Both are reports, so the pre-insert has no tab to switch to and
overwrites the visible report in place. Cancelling then has to rebuild it from a
navigation-state snapshot - a restore that runs through the root router's guards
and can be silently swallowed.

Skip the pre-insert for that case so cancelling is a true no-op with nothing
speculative to undo. Submitting falls through to the existing dismiss-and-navigate
path, which already handles this destination transition whenever pre-insert is not
eligible for other reasons. Flows that create an expense in place keep the
pre-mount. Per Expensify#97437.
@abzokhattab
abzokhattab force-pushed the fix/97437-submit-employer-device-back branch from 21cdb27 to 93ea88f Compare August 8, 2026 14:41
@abzokhattab

Copy link
Copy Markdown
Contributor Author

@MelvinBot review the PR

@abzokhattab
abzokhattab marked this pull request as ready for review August 8, 2026 14:45
@abzokhattab
abzokhattab requested review from a team as code owners August 8, 2026 14:45
@melvin-bot
melvin-bot Bot requested review from heyjennahay and mananjadhav August 8, 2026 14:45
@melvin-bot

melvin-bot Bot commented Aug 8, 2026

Copy link
Copy Markdown

@mananjadhav Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@melvin-bot
melvin-bot Bot removed request for a team August 8, 2026 14:45
@abzokhattab

Copy link
Copy Markdown
Contributor Author

This is finally read ... it was not easy to fix .. please have a look @hungvu193

@MelvinBot

Copy link
Copy Markdown
Contributor

PR Review

Verdict: Looks correct and well-scoped. The fix targets the real root cause, follows an idiom already established in this file, and ships focused regression tests. A couple of minor, non-blocking notes below.

What the fix does: On the dismissed-RHP cleanup path, removePreInsertedFullscreenIfNeeded used to call jumpTo(originalTabName), which only restores focus. When the pre-insert had rewritten the tab the user was already on (single-workspace "Submit it to my employer": both source self-DM and destination workspace chat live in the same Reports tab), jumpTo to that same tab is a no-op and the user was stranded on the pre-inserted workspace chat. The PR now swaps the whole saved TAB_NAVIGATOR route back via CommonActions.reset, restoring the focused tab and every tab's nested state. This is strictly more correct than the old behavior, which also discarded nested state on the cross-tab path.

Why I'm confident it's sound
  • Idiom is established. The CommonActions.reset({...state, routes, index}) full-state-swap pattern is already used in this same file — removeScreenFromNavigationState, removeScreenByKey, removeReportScreen. The new code follows it faithfully.
  • Snapshot integrity. originalTabRoute is the fully-keyed route captured at pre-insert time in handleReplaceFullscreenUnderRHP. The tab navigator's key is preserved across the whole flow, so reset reconciles the same navigator instance rather than remounting it. On narrow the RHP covers the tab fullscreen, so the underlying tab can't have drifted between snapshot and restore.
  • currentState is re-read inside the rAF, and only the tab route is swapped — every other root route (with its keys) is preserved, so nothing else in the stack is clobbered.
  • Branching preserved. getPreInsertedOriginalTabRoute() is only set on the tab-switch path; the push path stays undefined and correctly falls through to the pop-the-pre-inserted-route branch. The RHP-still-on-top path is untouched.
  • Tests cover all three states: same-tab restore (the reported bug), cross-tab restore (asserts nested state via toEqual), and cleanup while the RHP is still on top.

Minor notes (non-blocking):

  • clampedIndex is effectively dead: newRoutes always has the same length as currentState.routes (you remove exactly one tab route and insert exactly one snapshot route), so currentState.index >= newRoutes.length can only be true if the index was already out of bounds. Harmless defensive code, but it reads as if a length change is possible when it isn't.
  • The two restore paths now use two different mechanisms for the same snapshot (REMOVE_FULLSCREEN_UNDER_RHP custom action vs. CommonActions.reset). That's inherent to the two navigation states, just worth a mental note for future maintenance.

Testing note: The reported bug is narrow-layout + Android device (hardware) back button, which this run can only test on web. I verified on a 375px-wide web viewport that the general flow is healthy — create expense → open the confirmation RHP → back out (discard) returns cleanly to the report list with no blank/stuck screen, and the happy-path submit lands the expense in the self-DM correctly. The exact "single workspace / device-back-before-cleanup" scenario is Android-specific and is covered by the new unit tests, which model it directly (I couldn't execute the Jest suite in this environment — worth confirming CI is green on tests/navigation/RemovePreInsertedFullscreenAfterRHPDismissTests.tsx).

🤖 Generated with MelvinBot

@hungvu193
hungvu193 requested review from hungvu193 and removed request for mananjadhav August 8, 2026 14:57
@MelvinBot

Copy link
Copy Markdown
Contributor

PR Review

Verdict: ✅ Looks correct and well-scoped. The fix targets the real root cause, reuses gating logic already established in this builder, and ships focused regression tests. CI is green (the only failing check, Check independent approval, is expected on an unreviewed PR). No blocking issues.

Note: this reviews the current diff (the "skip the pre-mount" approach in getSubmitExpensePreMountDestinationRoute). The earlier MelvinBot comment on this PR reviewed a since-replaced Navigation.ts implementation and no longer applies.

What the fix does: For the single-workspace "Submit it to my employer" flow, the source (self DM) and destination (workspace chat) are both reports in the same tab, so there's no tab to switch to — pre-mounting the destination overwrites the visible report in place, and device-back pops the RHP to reveal that overwritten screen (#97437). The PR adds an isReplacingVisibleReport guard that skips the pre-insert in exactly this topology, so backing out becomes a true no-op and submit falls through to the existing dismiss-and-navigate path.

Why I'm confident it's sound
  • Fallback path verified. When the builder returns undefined, usePreMountDestination.revealDestination calls Navigation.dismissModal() directly — the same dismiss-and-navigate path used whenever pre-insert isn't eligible. And since nothing was pre-inserted, cleanupPreMount() on back-out is a genuine no-op. This matches the PR's claim exactly.
  • Correct gate. isMovingTransactionFromTrackExpense covers SUBMIT/SHARE/CATEGORIZE — exactly the relocate-an-already-tracked-expense flows where the draft is rebound to a destination chat the user has never visited. In-place creation is excluded and keeps the pre-mount.
  • Stays narrow. The guard also requires isReportTopmostSplitNavigator() and getTopmostReportId() !== destinationReportID, so it only fires for the same-tab / different-visible-report shape. Cross-tab, Search pre-mounts, self-DM/in-place creation, and skip-confirmation flows are untouched.
  • Self-teardown protected. The !hasPreInsertedFullscreen prefix keeps eligibility stable once an insert exists (same pattern already used by hasValidDestination), so the hook can't tear down its own insert. The new test stays eligible once it has pre-inserted asserts this.
  • Tests cover the reported bug, the in-place per-diem look-alike that must keep the pre-mount, and the stability case — all passing in CI (test/Bun tests green).

Testing note: The reported bug is narrow-layout + Android hardware back button, which this run can only exercise on web. I ran the PR's own in-place regression check (#6) on a 375px web viewport: create a manual expense in the self DM → open the Confirm-details RHP → back out (discard) returns cleanly to the self DM with no blank/stuck/skeleton screen and no wrong-chat flash; and Submit lands the expense on the correct report. The exact "single paid workspace + submit2026 beta" repro couldn't be reproduced (this test account has zero workspaces), but that scenario is modeled directly by the new unit tests. Screenshots below.

🤖 Generated with MelvinBot

Evidence

Confirm details page for first manual expense in narrow layout

Confirm details page for first manual expense in narrow layout

Confirm details page for second manual expense before submit

Confirm details page for second manual expense before submit

Self DM after submitting the expense showing the expense card and Concierge whisper

Self DM after submitting the expense showing the expense card and Concierge whisper

@hungvu193

Copy link
Copy Markdown
Contributor

Damnn, Melvin can actually take the screenshot now 🤯 That's mind blowing

@hungvu193

hungvu193 commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: HybridApp
Screen.Recording.2026-08-17.at.11.57.11.mov
Android: mWeb Chrome
Screen.Recording.2026-08-17.at.11.57.11.mov
iOS: HybridApp
Screen.Recording.2026-08-17.at.12.07.47.mov
iOS: mWeb Safari
Screen.Recording.2026-08-17.at.12.09.29.mov
MacOS: Chrome / Safari
Screen.Recording.2026-08-17.at.12.02.41.mov

Comment on lines +81 to +82
const isReplacingVisibleReport =
!hasPreInsertedFullscreen && isMovingTransactionFromTrackExpense && isReportTopmostSplitNavigator() && Navigation.getTopmostReportId() !== destinationReportID;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MelvinBot can you help me verify this change?

@MelvinBot

Copy link
Copy Markdown
Contributor

I reviewed the change and verified it at the code + unit-test level. It looks correct. Live end-to-end verification was not possible this run (details below).

Verdict: ✅ change is sound

The fix adds a narrow, well-scoped guard (isReplacingVisibleReport) that skips the destination pre-mount for exactly the buggy topology, and the wiring is correct.

What I checked

1. The guard fires on exactly the reported case. In getSubmitExpensePreMountDestinationRoute.ts:81-82, isReplacingVisibleReport is true only when all of: not yet pre-inserted, relocating a tracked expense, a report is topmost, and that report differs from the destination. That is precisely "reading the self DM while the expense is bound to the workspace chat" — so shouldPreInsertReport becomes false and the builder returns undefined, making back a true no-op.

2. It's scoped to the relocation flows only. isMovingTransactionFromTrackExpense returns true only for SUBMIT/SHARE/CATEGORIZE, so in-place creation (per-diem, etc.), Search pre-mounts, cross-tab pre-mounts, and skip-confirmation flows keep the pre-mount — matching the PR's "Unaffected" list.

3. No self-teardown. The !hasPreInsertedFullscreen clause keeps the result stable once a pre-insert exists, so the hook won't tear down its own insert. The usePreMountDestination dependency array in IOURequestStepConfirmation.tsx was correctly updated to include the new param.

4. Unit tests pass and cover the branches. The new cases in getSubmitExpensePreMountDestinationRouteTest.ts cover: undefined when relocating over a different visible report, pre-insert kept for an in-place expense in the same topology, and staying eligible after pre-insert. These ran green in CI (test jobs 1–8 and Bun tests).

5. CI is green. Every functional check passes. The only red check is Check independent approval, which is an approval-gating status, not a code failure.

⚠️ One caveat — I couldn't run it live

This is a narrow-layout / device-back bug, and the entry point ("Submit it to my employer") is gated behind the server-provisioned submit2026 beta plus a paid workspace. My web test session ran on a fresh account that has neither (the beta has no client-side toggle), so I couldn't exercise steps 1–5 interactively. The author-recorded videos on the PR already cover Android native / mWeb / iOS / macOS, so I'd lean on those + the reviewer's manual run for the final behavioral sign-off.

Net: the change is logically correct and safe for its scope; just make sure a human confirms the on-device back behavior against the recorded videos before merge.

@hungvu193
hungvu193 requested a review from iwiznia August 17, 2026 05:10
@abzokhattab

Copy link
Copy Markdown
Contributor Author

cc @carlosmiceli

@carlosmiceli
carlosmiceli merged commit 31f2707 into Expensify:main Aug 18, 2026
43 of 46 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

🚧 carlosmiceli has triggered a test Expensify/App build. You can view the workflow run here.

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/carlosmiceli in version: 9.4.56-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

@MelvinBot

Copy link
Copy Markdown
Contributor

🤖 I reviewed the changes in this PR against the help site content under docs/articles, and no help site changes are required.

Why: This is a navigation-only bug fix. It changes internal pre-mount/routing logic so that pressing the device back button on the "Submit it to my employer" confirmation page returns you to the self DM instead of flashing the workspace chat. The three changed files are all logic/tests:

There are no new features, settings, buttons, tab names, or user-facing copy introduced (no src/languages/* changes). Help articles document how to submit/track expenses — they don't document the exact screen the device back button lands on, so there's nothing in the published docs that this fix contradicts or that needs updating.

Since no changes are needed, I did not create a draft help site PR.

@IuliiaHerets

Copy link
Copy Markdown

Hi @abzokhattab. No “Submit it to my employer” whisper appears on our side. We tried both Gmail and Expensifail accounts.
How can we enable the submit2026 beta, or which account should we use to access this flow?

image

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/Beamanator in version: 9.4.56-3 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

Bundle Size Analysis (Sentry):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants