Skip to content

[Performance] Migrate submit-expense flow to usePreMountDestination - #96480

Merged
roryabraham merged 2 commits into
Expensify:mainfrom
software-mansion-labs:korytko/migrate-submit-expense
Jul 24, 2026
Merged

[Performance] Migrate submit-expense flow to usePreMountDestination#96480
roryabraham merged 2 commits into
Expensify:mainfrom
software-mansion-labs:korytko/migrate-submit-expense

Conversation

@JakubKorytko

@JakubKorytko JakubKorytko commented Jul 20, 2026

Copy link
Copy Markdown
Member

Explanation of Change

Migrates the submit-expense flow off the bespoke pre-insert logic (useSkipConfirmationPreInsert + the inline effect in IOURequestStepConfirmation) to the usePreMountDestination hook, extracting two tested pure route resolvers. Also fixes a self-invalidation loop where a route's own pre-insertion flipped its eligibility to false and tore it back down.

Fixed Issues

$ #94673
PROPOSAL: N/A

Tests

The migrated behavior is the modal-to-destination transition: after submitting, the destination screen must already be there when the modal closes, with no flash of the screen you started on.

Setup: two accounts, at least one workspace you belong to, and one existing 1:1 chat.
"Wait until fully settled" = let the Confirm details screen finish animating before submitting; submitting sooner exercises the fallback path (covered by Narrow test 2).

Narrow layout

  1. Create expense from Inbox to an existing workspace (primary case):
    1. Go to the Inbox tab, tap the + (FAB), and select "Create expense".
    2. Enter an amount, tap Next, and select an existing workspace.
    3. On "Confirm details", wait until fully settled, then tap "Create $X expense".
    4. Verify that the workspace chat appears the instant the modal closes, with no Inbox flash.
  2. Submit immediately (fallback path): repeat test 1 but tap "Create $X expense" as fast as possible, before the screen settles. Verify that the transition is still clean (the chat is revealed, no Inbox flash).
  3. Create expense from Reports (Search), same type: on the Reports tab (Expenses view), FAB → Create expense → amount → Next → pick a destination → Confirm details → wait until settled → submit. Verify that you stay on Reports (Expenses) with no flash.
  4. Create expense from a different Search type: on the Reports tab, then FAB → Create expense (a normal expense) → amount → Next → pick a destination → Confirm details → submit. Verify that Reports switches to the Expenses view with no flash and does not stay stuck on Reports.
  5. Track / self-DM: Inbox → FAB → Create expense → amount → Next → select yourself → Confirm details → submit. Verify that your self-DM chat appears immediately.
  6. Split from a chat: open a DM or group chat, use the composer + menu → Split expense → amount → Next → (add participants if prompted) → Confirm details → tap "Split $X". Verify that you land back on the split's chat with no flash. (Split is not in the FAB; it is entered from a chat or the Quick action.)
  7. Split via Quick action (new group): after performing test 6 once so the Quick action shows "Split expense", Inbox → FAB → Quick action: Split expense → complete it. Verify that the newly created group report opens immediately with no Inbox flash.
  8. New, not-yet-existing destination: Inbox → FAB → Create expense → amount → Next → enter a brand-new email you have no chat with → Confirm details → submit. Verify that the new chat opens with a loading skeleton and no Inbox flash.
  9. Submit while already viewing the destination: open an existing workspace chat, then from inside it FAB → Create expense → amount → Next → keep that same workspace → Confirm details → wait until settled → submit. Verify that you stay on that chat with no duplicated report, and that pressing Back afterwards takes a single press.
  10. Change destination then submit: Inbox → FAB → Create expense → amount → Next → pick workspace A → Confirm details → wait until settled → change the destination to workspace B → submit. Verify that you land on workspace B, not A, with no flash.
  11. Back out without submitting: Inbox → FAB → Create expense → amount → Next → pick a workspace → reach Confirm details → wait until settled → press Back without submitting. Verify that you return in one action, the Inbox stays interactive, and no leftover or duplicated screen remains. Repeat pressing Back immediately (before it settles) and verify the same clean result.
  12. Skip-confirmation via Quick action: perform any scan/create once so the Quick action is populated, then Inbox → FAB → tap the Quick action item (which skips the Confirm details screen). Verify that the destination is reached with no flash. Repeat the same Quick action from the Reports tab and verify it is gapless there too.

Wide layout

  1. Create expense from Inbox to an existing workspace: Inbox → FAB → Create expense → amount → Next → pick an existing workspace → Confirm details → submit. Verify that the workspace report is revealed with no flash of the previous page.
  2. Create expense from a different Search type: on the Reports tab, then FAB → Create expense (normal expense) → amount → Next → pick a destination → Confirm details → submit. Verify that Reports switches to Expenses cleanly with the correct type and no flash.
  3. Split via Quick action: ensure the Quick action shows "Split expense" (perform a split once if needed), then Inbox → FAB → Quick action: Split expense → complete it. Verify that the group report is revealed with no flash of the previous page.
  4. Submit from a report shown in the right pane: open a report so it is shown in the right-hand pane, then FAB → Create expense → amount → Next → keep/pick destination → Confirm details → submit. Verify that the report is revealed and the panel fully closes, with no half-open panel and no flash.
  5. Skip-confirmation via Quick action: ensure the Quick action shows a scan/create, then Inbox → FAB → tap the Quick action item (skips Confirm details). Verify that the destination is revealed with no flash of the previous full-screen page.

Offline tests

  1. Enable offline mode (disable the network connection).
  2. In narrow layout, from the Inbox, create an expense to an existing destination and submit it.
  3. Verify that the destination report is revealed gaplessly with the optimistic expense shown, and that the expense syncs once the connection is restored.

QA Steps

Same as the Tests section above.

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
Android: mWeb Chrome
iOS: Native
iOS.mov
iOS: mWeb Safari
MacOS: Chrome / Safari
Web.mov

@codecov

codecov Bot commented Jul 20, 2026

Copy link
Copy Markdown

Codecov Report

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

Files with missing lines Coverage Δ
src/hooks/usePreMountDestination/index.ts 94.73% <100.00%> (+0.14%) ⬆️
...rc/pages/iou/request/step/IOURequestStepAmount.tsx 88.03% <100.00%> (+0.10%) ⬆️
.../pages/iou/request/step/IOURequestStepDistance.tsx 75.21% <100.00%> (+0.10%) ⬆️
...equestStepScan/components/ScanSkipConfirmation.tsx 77.77% <100.00%> (+0.20%) ⬆️
...ion/getSkipConfirmationPreMountDestinationRoute.ts 100.00% <100.00%> (ø)
...mation/getSubmitExpensePreMountDestinationRoute.ts 100.00% <100.00%> (ø)
...st/step/confirmation/getSubmitExpenseSearchType.ts 100.00% <100.00%> (ø)
...es/iou/request/step/IOURequestStepConfirmation.tsx 65.74% <80.00%> (+1.08%) ⬆️
...st/step/confirmation/SubmitExpenseOrchestrator.tsx 52.87% <0.00%> (+7.68%) ⬆️
... and 9 files with indirect coverage changes

@JakubKorytko

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 64de0aad5f

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/pages/iou/request/step/IOURequestStepConfirmation.tsx
@JakubKorytko

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: 70c8e6d9ab

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@JakubKorytko
JakubKorytko force-pushed the korytko/migrate-submit-expense branch from 70c8e6d to f64c512 Compare July 21, 2026 11:38
@JakubKorytko

Copy link
Copy Markdown
Member Author

@codex review

@JakubKorytko JakubKorytko changed the title [WIP] [Performance] Migrate submit-expense flow to usePreMountDestination [Performance] Migrate submit-expense flow to usePreMountDestination Jul 22, 2026
@mountiny
mountiny requested a review from Copilot July 22, 2026 12:08
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: f64c512de5

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Copilot AI left a comment

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.

Pull request overview

This PR migrates the submit-expense (and related skip-confirmation) modal-to-destination navigation from bespoke pre-insert logic to the shared usePreMountDestination hook, extracting pure “route resolver” helpers and adding unit coverage to keep modal dismiss transitions gapless (no flash/gap).

Changes:

  • Replaced inline pre-insert orchestration in IOURequestStepConfirmation and the deprecated useSkipConfirmationPreInsert hook with usePreMountDestination.
  • Introduced two route-resolver utilities (getSubmitExpensePreMountDestinationRoute, getSkipConfirmationPreMountDestinationRoute) plus shared getSubmitExpenseSearchType, with new unit tests.
  • Tightened enforcement by updating the ESLint local rule to only allow direct fullscreen pre-insert from usePreMountDestination / Navigation.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/unit/getSubmitExpensePreMountDestinationRouteTest.ts Adds unit tests covering the submit-expense pre-mount destination decision logic.
tests/unit/getSkipConfirmationPreMountDestinationRouteTest.ts Adds unit tests for skip-confirmation pre-mount destination decision logic.
src/pages/iou/request/step/IOURequestStepScan/components/ScanSkipConfirmation.tsx Switches skip-confirmation pre-insert to usePreMountDestination via the new route resolver.
src/pages/iou/request/step/IOURequestStepDistance.tsx Switches skip-confirmation pre-insert to usePreMountDestination via the new route resolver.
src/pages/iou/request/step/IOURequestStepAmount.tsx Switches skip-confirmation pre-insert to usePreMountDestination via the new route resolver.
src/pages/iou/request/step/IOURequestStepConfirmation.tsx Replaces inline pre-insert effect with memoized route resolution + usePreMountDestination, and wires reveal into the orchestrator.
src/pages/iou/request/step/confirmation/SubmitExpenseOrchestrator.tsx Consumes the injected revealPreMountDestination instead of managing pre-insert flags directly.
src/pages/iou/request/step/confirmation/getSubmitExpenseSearchType.ts Centralizes IOU-type → Search-tab mapping to keep handlers/resolvers consistent.
src/pages/iou/request/step/confirmation/getSubmitExpensePreMountDestinationRoute.ts New submit-expense-specific pre-mount route resolver (narrow-only).
src/pages/iou/request/step/confirmation/getSkipConfirmationPreMountDestinationRoute.ts New skip-confirmation pre-mount route resolver (delegates narrow gating to the hook).
src/hooks/useSkipConfirmationPreInsert.ts Removes the old bespoke skip-confirmation pre-insert hook.
src/hooks/usePreMountDestination/index.ts Adds a warning for unexpected “non-owned reveal with pre-insert flag set” scenarios and exports AfterTransition.
eslint-plugin-local-rules/no-direct-pre-insert-fullscreen-under-rhp.js Updates allowlist to enforce using usePreMountDestination instead of ad-hoc pre-insert calls.
.claude/skills/coding-standards/rules/perf-18-use-pre-mount-destination.md Updates the internal rule doc to remove deprecated exception references.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/hooks/usePreMountDestination/index.ts
@JakubKorytko
JakubKorytko marked this pull request as ready for review July 22, 2026 12:24
@JakubKorytko
JakubKorytko requested review from a team as code owners July 22, 2026 12:24
@melvin-bot
melvin-bot Bot requested review from ZhenjaHorbach and removed request for a team July 22, 2026 12:24
@melvin-bot

melvin-bot Bot commented Jul 22, 2026

Copy link
Copy Markdown

@ZhenjaHorbach 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 requested review from JmillsExpensify and removed request for a team July 22, 2026 12:24
Comment thread src/pages/iou/request/step/IOURequestStepConfirmation.tsx
@ZhenjaHorbach

ZhenjaHorbach commented Jul 23, 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
2026-07-23.16.06.55.mov
Android: mWeb Chrome
2026-07-23.16.00.52.mov
iOS: HybridApp
2026-07-23.16.06.55.mov
iOS: mWeb Safari
2026-07-23.16.00.52.mov
MacOS: Chrome / Safari
2026-07-23.15.58.51.mov

@ZhenjaHorbach

Copy link
Copy Markdown
Contributor

@JakubKorytko
Can you fix conflicts, please?

@melvin-bot
melvin-bot Bot requested review from mountiny and roryabraham July 23, 2026 14:11
@ZhenjaHorbach

Copy link
Copy Markdown
Contributor

LGTM!

@roryabraham
roryabraham merged commit cb94dd3 into Expensify:main Jul 24, 2026
35 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

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

@github-actions

Copy link
Copy Markdown
Contributor

🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
Built from App PR #96480.

Android 🤖 iOS 🍎
❌ FAILED ❌ https://ad-hoc-expensify-cash.s3.us-east-1.amazonaws.com/rock-artifacts/ad-hoc/rock-ios-device-AdHoc-cb94dd3-c60f8d8-26e56e414b931a7c1041e0ce7a60cbffb4c6fef1/index.html
The QR code can't be generated, because the Android build failed iOS
Web 🕸️
https://96480.pr-testing.expensify.com
Web

👀 View the workflow run that generated this build 👀

@OSBotify

Copy link
Copy Markdown
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/roryabraham in version: 9.4.45-0 🚀

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

@MelvinBot

Copy link
Copy Markdown
Contributor

🤖 I reviewed the changes in this PR against Expensify's help site files under App/docs/articles.

No help site changes are required, so I did not create a draft PR.

This PR is a purely internal performance/architecture refactor:

  • It migrates the submit-expense flow off the bespoke pre-insert logic (useSkipConfirmationPreInsert + the inline effect in IOURequestStepConfirmation) to the usePreMountDestination hook, extracts two tested pure route resolvers, and fixes a self-invalidation loop.
  • All changed files are hooks, ESLint rules, orchestrator internals, route resolvers, and unit tests.

Per the linked issue Expensify/App#94673, the user-facing behavior (gapless modal-to-destination transitions) is already shipped — this PR only changes how it's implemented, not what the user sees. There are no new features, UI changes, copy/label changes, or changes to product behavior that the help site documents.

Since the help site documents user-facing product functionality and none of that changes here, there is nothing to update in App/docs/articles.

@JakubKorytko, since no user-facing behavior changed, no help site PR was created and there is nothing to review. If you believe a specific article is affected, let me know which one and I'll take another look.

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/marcaaron in version: 9.4.45-14 🚀

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