Skip to content

Share extension: pre-mount destination report and create expense before reveal transition - #97242

Open
jmgraa wants to merge 37 commits into
Expensify:mainfrom
software-mansion-labs:jmgraa/share-extension-create-expense
Open

Share extension: pre-mount destination report and create expense before reveal transition#97242
jmgraa wants to merge 37 commits into
Expensify:mainfrom
software-mansion-labs:jmgraa/share-extension-create-expense

Conversation

@jmgraa

@jmgraa jmgraa commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Explanation of Change

Before this change, submitting a shared receipt could briefly show the Inbox behind the share modal before the destination chat appeared on top - a visible flash during dismiss.

SubmitDetailsPage now handles two navigation strategies based on layout and report state:

Narrow layout: Pre-mounts the destination report behind the modal (when it already exists in Onyx) so the correct chat is ready when the modal closes.

Wide layout (tablets/desktop): Reveals the destination report on top of the modal first, then dismisses the modal after the animation completes.

Both strategies keep the confirm button in loading state until navigation is safe. When the destination report doesn't exist yet (new recipient), the page waits for the optimistic report to land in Onyx before navigating - with fallback timers (500ms if ID changes, 5s absolute timeout) to prevent indefinite hangs.

The expense is created immediately on submit (not after the reveal animation), and cleanup skips a second navigation (shouldNavigate: false) since reveal/pre-mount already handles routing. Stale tracking spans are cancelled before creation to avoid lifecycle conflicts, improving telemetry accuracy.

Fixed Issues

$ #97667
PROPOSAL:

Tests

  1. Share extension with existing recipient

    • Share a receipt/image to Expensify via share extension
    • Select an existing contact as recipient
    • Verify confirm button shows loading state briefly, then navigates to the report
  2. Share extension with new recipient

    • Share a receipt/image via share extension
    • Select a new recipient (first-time conversation)
    • Verify destination report doesn't exist yet (pre-mount disabled)
    • Verify confirm button stays in loading state until optimistic report lands from backend
    • Verify navigation completes to newly created report within 5 seconds
  3. Share extension with destination already topmost

    • Open a report, then trigger share extension for the same recipient
    • Verify standard navigation flow works correctly

Repeat tests 1-3 both on narrow and wide layout

  • Verify that no errors appear in the JS console

Offline tests

Same as tests

QA Steps

Same as tests

  • 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

iOS: Native
ios.mov

@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

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

Files with missing lines Coverage Δ
...on/helpers/cleanupAndNavigateAfterExpenseCreate.ts 100.00% <100.00%> (ø)
src/pages/Share/SubmitDetailsPage.tsx 90.18% <90.38%> (+1.68%) ⬆️
... and 7 files with indirect coverage changes

@JakubKorytko JakubKorytko left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

the pre-mount idea is right, and the refactor is clean 🎉

Main thing: this re-does what the manual flow already has (getSubmitExpensePreMountDestinationRoute + handleReportPreInsert + usePreMountDestination) and drops the stability guard, which I think breaks the pre-mount. Details on the preMountDestinationRoute line.

On telemetry: ManualSubmitToDestinationVisible can't regress here - thank you for that haha. Share never calls startTracking, so the span is never started and every touchpoint is behind isTracking(). But that also means the whole flow is unmeasured, so the win this PR claims isn't verifiable, added a more precise comment in code.

Three behaviour changes also look inherited rather than decided: Search tab, wide layout, and report-already-in-RHP.

Comment thread src/pages/Share/SubmitDetailsPage.tsx Outdated
Comment thread src/pages/Share/SubmitDetailsPage.tsx Outdated
Comment thread src/pages/Share/SubmitDetailsPage.tsx
Comment thread src/pages/Share/SubmitDetailsPage.tsx Outdated
Comment thread src/pages/Share/SubmitDetailsPage.tsx Outdated
Comment thread tests/ui/SubmitDetailsPageTest.tsx
Comment thread tests/ui/SubmitDetailsPageTest.tsx Outdated
Comment thread tests/ui/SubmitDetailsPageTest.tsx
Comment thread tests/ui/SubmitDetailsPageTest.tsx
Comment thread tests/unit/cleanupAndNavigateAfterExpenseCreateTest.ts

@JakubKorytko JakubKorytko left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

the pre-insert gates and optimisticChatReportID close most of the last round, so what's left is mainly the pending-navigation branch (still the one that can park the modal in a loading state with nothing to resolve it) plus a few leftovers from round one. Otherwise, LGTM!

Comment thread src/pages/Share/SubmitDetailsPage.tsx Outdated
Comment thread src/pages/Share/SubmitDetailsPage.tsx
Comment thread src/pages/Share/SubmitDetailsPage.tsx
Comment thread src/pages/Share/SubmitDetailsPage.tsx Outdated
Comment thread src/libs/Navigation/helpers/cleanupAndNavigateAfterExpenseCreate.ts Outdated
Comment thread src/libs/Navigation/helpers/cleanupAndNavigateAfterExpenseCreate.ts Outdated
Comment thread tests/unit/cleanupAndNavigateAfterExpenseCreateTest.ts
Comment thread tests/unit/cleanupAndNavigateAfterExpenseCreateTest.ts Outdated
Comment thread tests/ui/SubmitDetailsPageTest.tsx Outdated
@mjasikowski

Copy link
Copy Markdown
Contributor

@MelvinBot create a new issue for this and attach it as a sub-issue of #95335

@MelvinBot

Copy link
Copy Markdown
Contributor

Created a new issue for this and attached it as a sub-issue of #95335:

👉 #97667 — Share extension: eliminate Inbox flash when dismissing share modal after submit

It captures the Inbox-flash-during-dismiss problem this PR addresses and links back to both this PR and the parent performance issue. The parent now tracks 2 sub-issues.

@jmgraa
jmgraa marked this pull request as ready for review August 3, 2026 09:38
@jmgraa
jmgraa requested review from a team as code owners August 3, 2026 09:38
@melvin-bot
melvin-bot Bot requested a review from ChavdaSachin August 3, 2026 09:38
@melvin-bot

melvin-bot Bot commented Aug 3, 2026

Copy link
Copy Markdown

@ChavdaSachin 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 heyjennahay and removed request for a team August 3, 2026 09:38

@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: 19d8139deb

ℹ️ 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/Share/SubmitDetailsPage.tsx Outdated
Comment thread src/pages/Share/SubmitDetailsPage.tsx Outdated
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.

4 participants