Skip to content

[Performance] Fix submit-to-destination span stalls caused by sliced tab state and fragile dismiss signals#93452

Closed
JakubKorytko wants to merge 10 commits into
Expensify:mainfrom
software-mansion-labs:korytko/fix-submit-to-destination-visible-metrics
Closed

[Performance] Fix submit-to-destination span stalls caused by sliced tab state and fragile dismiss signals#93452
JakubKorytko wants to merge 10 commits into
Expensify:mainfrom
software-mansion-labs:korytko/fix-submit-to-destination-visible-metrics

Conversation

@JakubKorytko

@JakubKorytko JakubKorytko commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Explanation of Change

Fixes six submit-to-destination-visible span failures identified from 11 Sentry traces across iOS HybridApp, Android HybridApp, and Web standalone. The common root cause is lazy/sliced tab navigator state being unavailable at submit-time decision points, combined with fragile post-dismiss visibility signals.

Issue 01 - Global create falls back to default handler (trace ce57bcb9, Android, ~6.1s): The REPLACE_FULLSCREEN_UNDER_RHP dispatch fails because existingTabState.routes only contains [Home] when the target is SearchFullscreenNavigator. Fix: getTabStateWithFocusedTarget now reconstructs missing tabs from buildTabNavigatorNestedState, normalizes routeNames to TAB_SCREENS, strips stale history, and marks the state stale: true so TabRouter rehydrates with valid route keys.

Issue 02 - Report pre-insert lands on Inbox (traces ae1d8901, 3779d897, e7e05ac2, iOS/Android, 6.5–34.8s): The report_pre_insert handler dismisses but the user lands on Inbox because getTopmostReportParams can match a report in an unfocused Reports tab. Fix: dismissAfterEnsuringDestinationReportIsPreInserted now gates the pre-insert check on isReportTopmostSplitNavigator() and falls back to revealRouteBeforeDismissingModal when the tab isn't focused.

Issue 03 - Search report visibility depends on layout re-firing (traces b593642b, b0153d43, Web Firefox/Safari, 17.8–32.0s): SearchMoneyRequestReportPage used only the LAYOUT trigger, which doesn't re-fire when the page is merely uncovered after being covered by RHP screens. Fix: useSubmitToDestinationVisible now supports [LAYOUT, FOCUS] dual triggers with a shared hasEndedRef guard.

Issue 04 - Dismiss-only span waits for report (trace 5bee564c, Android, ~28.3s): The dismiss_modal handler stores DISMISS_MODAL_ONLY with a destination report ID even when returning to Search. Fix: setDismissOnlyPendingActionForCurrentRoute omits the report ID when Search is the topmost fullscreen route.

Issue 05 - Search dismiss leaves create flow open (trace 1ffba096, Web Chrome, ~17.9s): dismissModal fired and createTransaction succeeded, but the RHP create stack remained visible. Fix: handleSearchDismiss now verifies the RHP is gone after the first dismiss afterTransition and performs a recovery dismiss with logging if it's still on top.

Issue 06 - Global create scan from Spend misidentifies Search context (traces d0c23d02, 2a89ae3d, 9789e05e, iOS HybridApp, 44.5–50.6s): isSearchTopmostFullScreenRoute() returns false because live tab state is sliced. Fix: getTopmostFullScreenRoute now falls back through live state → preserved state → params.screen hint. navigateAfterExpenseCreate no longer infers Search root from missing navigator state.

Additionally, the submit orchestrator is refactored: GPS permission callbacks now route through dispatchSubmitHandler (same handler selection as onConfirm), threading locationPermissionGranted into all handlers to prevent silent coordinate loss.

Fixed Issues

$ TBA
PROPOSAL: N/A

Tests

Issue 01 - Global create from Home falls back to default handler (narrow layout, Android/iOS)

  1. Use a narrow layout (mobile device or narrow browser window)
  2. Start from Home, or another non-Spend and non-Inbox screen that is not already showing a destination report
  3. Open the global + FAB → Create expense
  4. Select a manual expense to non-empty workspace report
  5. Reach the confirmation screen
  6. Submit the expense
  7. Verify that you are navigated to Spend/Search with the new expense visible
  8. Verify in the ManualSubmitToDestinationVisible span end log that fast_path_handler is search_pre_insert or search_dismiss, not default

Issue 02 - Report pre-insert lands on Inbox instead of destination report (narrow layout, iOS/Android)

  1. Use a narrow layout
  2. Open Inbox
  3. Open the report that will receive the submitted expense so it is loaded locally
  4. Return to Inbox so that destination report is no longer visible
  5. Create a new manual expense and choose that report as the destination
  6. Reach the confirmation page and wait until the page is fully visible and idle
  7. Submit the new expense
  8. Verify that after the modal dismisses, the destination report is visible - not Inbox
  9. Verify in the ManualSubmitToDestinationVisible span end log that fast_path_handler is report_pre_insert

Issue 03 - Search report visibility depends on layout re-firing (wide web, Firefox/Safari)

  1. Use wide web layout
  2. Open Spend > Reports
  3. Open a report; it opens in the right-hand panel
  4. In that right-hand panel, choose Add expense (if the report does not have that option, choose a different report)
  5. Choose Create expense
  6. Create and submit a new manual expense to that report
  7. Verify the ManualSubmitToDestinationVisible span ends promptly when the Search money-request report is revealed - it should not wait for a data/layout change to re-fire onLayout

Issue 04 - Dismiss-only span waits for report instead of ending on Search (narrow layout, Android)

Note: Not currently reproducible with a verified UI flow. The tested UI flows route through search_dismiss and the span ends normally. This issue requires fast_path_handler: dismiss_modal while Search is already the topmost fullscreen route and a destination report ID is present.

  1. Use a narrow layout
  2. Open Spend > Reports
  3. Apply filters (e.g. from:... to:...)
  4. From search results, tap a FAB to start creating an expense
  5. Switch to manual tab if landed on scan, then submit
  6. After submit, verify you return to Spend Search and the ManualSubmitToDestinationVisible span ends on the Search return
  7. Verify the span does NOT wait for the user to manually open the destination report

Issue 05 - Search dismiss leaves create flow open (wide web, Chrome)

  1. Use wide web layout
  2. Open Spend > Expenses
  3. Open global create
  4. Create a manual expense
  5. Reach confirmation
  6. Submit the expense
  7. Verify the create/money-request modal dismisses completely and Spend > Expenses is visible
  8. Verify the expense was created (check search results) and the ManualSubmitToDestinationVisible span ends without the user having to manually back out

Issue 06 - Global create scan from Spend misidentifies Search context (narrow layout, iOS HybridApp)

  1. Use a narrow layout on iOS (HybridApp preferred)
  2. Open Spend > Expenses
  3. Open global create
  4. Create an expense using receipt scan
  5. Submit the scanned expense
  6. Verify the app dismisses back to Spend > Expenses without a prolonged stall (should be <5s, not the 40-50s seen in production traces)
  7. Verify in the ManualSubmitToDestinationVisible span end log that fast_path_handler is search_dismiss, not default

GPS permission threading (all layouts)

  1. Reset app location permission
    • Web: You reset it through browser site settings (e.g. click the lock icon in the address bar, reset location permission)
    • iOS: Settings > Privacy > Location Services > Expensify, or delete/reinstall the app
    • Android: Settings > Apps > Expensify > Permissions > Location, or delete/reinstall
  2. Create a scan expense in a workspace chat, upload a receipt, submit
  3. Grant location permission when prompted
  4. Verify the expense is created with GPS coordinates regardless of which submit handler was selected
  5. Repeat but deny permission - verify the expense is created without coordinates

Offline tests

N/A

QA Steps

Same as tests

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 any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • 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 shown in the product is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • 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)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • 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)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • 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.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • 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.mov
Android: mWeb Chrome
iOS: Native
iOS.mov
iOS: mWeb Safari
MacOS: Chrome / Safari
Web.mov

getTopmostFullScreenRoute now falls back to preserved state when live
state exists but can't resolve a focused route, and to params.screen
as a last resort.

getTabStateWithFocusedTarget rebuilds missing tabs with normalized
routeNames, stripped history, and stale: true so TabRouter rehydrates
properly with valid route keys.

navigateAfterExpenseCreate no longer infers Search root when the
navigator state is missing - only trusts explicit SCREENS.SEARCH.ROOT.

Also tightens SPLIT_TO_SIDEBAR type access via a helper that preserves
the original strongly-typed key check.
setDismissOnlyPendingActionForCurrentRoute now omits the destination
report ID when Search is the topmost fullscreen route, preventing
the span from waiting for a report that will never become visible.
…ading

Replace handleLocationPermissionSubmit with dispatchSubmitHandler that
routes GPS permission callbacks through the same handler selection as
onConfirm, threading locationPermissionGranted into every handler.

Gate getTopmostReportParams on isReportTopmostSplitNavigator to avoid
trusting pre-inserted report state from unfocused tabs.

Add recovery logging when Search dismiss finds RHP still on top.
Add array overload to useSubmitToDestinationVisible so a single hook
call can handle both FOCUS and LAYOUT triggers with a shared guard.

Consolidate SearchMoneyRequestReportPage from two separate hook calls
into one [LAYOUT, FOCUS] call, preserving both completion signals.
@JakubKorytko

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: b67bf79fa8

ℹ️ 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".

@codecov

codecov Bot commented Jun 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.

Files with missing lines Coverage Δ
...bs/Navigation/helpers/getTopmostFullScreenRoute.ts 100.00% <100.00%> (ø)
...s/Navigation/helpers/navigateAfterExpenseCreate.ts 88.09% <100.00%> (+1.25%) ⬆️
src/pages/Search/SearchMoneyRequestReportPage.tsx 0.00% <ø> (ø)
...quest/step/confirmation/submitDismissStrategies.ts 100.00% <100.00%> (ø)
src/hooks/useSubmitToDestinationVisible.ts 78.94% <85.71%> (+0.37%) ⬆️
...ateRootStackNavigator/GetStateForActionHandlers.ts 39.02% <75.00%> (+12.48%) ⬆️
...st/step/confirmation/SubmitExpenseOrchestrator.tsx 52.08% <46.15%> (-9.89%) ⬇️
... and 11 files with indirect coverage changes

@grgia grgia requested a review from Copilot June 15, 2026 12:07
@grgia

grgia commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

@codex review

@grgia

grgia commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Oh you got codex already 😁

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 targets submit-time navigation/visibility stalls in the expense submit flow by hardening navigation state handling (especially when tab state is lazily/sliced) and making the “submit-to-destination-visible” span end reliably across dismiss + reveal flows.

Changes:

  • Reconstructs/normalizes missing tab navigator state during tab-target pre-insert/replace actions, including preserved-state/params.screen fallbacks for “topmost fullscreen route” detection.
  • Improves dismiss-and-reveal reliability (e.g., report pre-insert gated on the focused Reports tab; dismiss-only follow-up action omits reportID when returning to Search).
  • Extends submit-to-destination-visible span ending to support dual triggers (LAYOUT + FOCUS) and refactors orchestrator handler dispatch to thread GPS permission results through all handlers.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/unit/submitDismissStrategiesTest.ts Adds coverage for clearing reportID on dismiss-only returns to Search.
tests/unit/Navigation/getTopmostFullScreenRouteTest.ts Updates mocks to align with the new navigationRef import path.
tests/unit/Navigation/getTabStateWithFocusedTargetTest.ts Adds unit tests for reconstructing a full tab state from sliced state and focusing a target tab.
tests/unit/isSearchTopmostFullScreenRouteTest.ts Adds tests validating Search detection via live state → preserved state → params.screen fallback.
tests/unit/getSubmitHandlerTest.ts Adds coverage for handler selection when Search isn’t topmost but dismiss-from-search is allowed.
tests/ui/TimeExpenseConfirmationTest.tsx Updates navigationRef mocking to the default-exported module shape.
tests/ui/components/IOURequestStepConfirmationPageTest.tsx Updates navigationRef mocking to the default-exported module shape.
src/pages/Search/SearchMoneyRequestReportPage.tsx Switches span-ending trigger from LAYOUT-only to [LAYOUT, FOCUS].
src/pages/iou/request/step/confirmation/SubmitExpenseOrchestrator.tsx Refactors submit handler dispatch; adds report pre-insert gating and Search dismiss recovery; threads GPS permission flag through all handlers.
src/pages/iou/request/step/confirmation/submitDismissStrategies.ts Omits reportID for dismiss-only when returning to Search; updates pending follow-up action selection accordingly.
src/libs/Navigation/helpers/navigateAfterExpenseCreate.ts Refactors Search navigator state retrieval and follow-up action derivation for post-create navigation.
src/libs/Navigation/helpers/getTopmostFullScreenRoute.ts Adds fallback chain (live → preserved → params.screen) for identifying the active fullscreen tab route.
src/libs/Navigation/AppNavigator/createRootStackNavigator/GetStateForActionHandlers.ts Introduces getTabStateWithFocusedTarget to reconstruct missing tabs and normalize tab state during pre-insert/replace.
src/hooks/useSubmitToDestinationVisible.ts Adds support for multiple triggers with a shared end-guard to prevent double-ending spans.

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

@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: 982972dd97

ℹ️ 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

Copy link
Copy Markdown
Contributor Author

@codex review

@JakubKorytko JakubKorytko requested a review from Copilot June 15, 2026 12:38

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

Copilot reviewed 14 out of 14 changed files in this pull request and generated 4 comments.

Comment thread src/libs/Navigation/helpers/getTopmostFullScreenRoute.ts
Comment thread tests/unit/isSearchTopmostFullScreenRouteTest.ts
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: a983bc76f4

ℹ️ 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 requested a review from Copilot June 15, 2026 14:55
@JakubKorytko

Copy link
Copy Markdown
Contributor Author

@codex review

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

Copilot reviewed 14 out of 14 changed files in this pull request and generated 4 comments.

Comment thread src/libs/Navigation/helpers/getTopmostFullScreenRoute.ts
Comment thread src/libs/Navigation/helpers/navigateAfterExpenseCreate.ts
@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: b51e14fdd5

ℹ️ 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 changed the title [WIP] [Performance] Fix submit-to-destination span stalls caused by sliced tab state and fragile dismiss signals [Performance] Fix submit-to-destination span stalls caused by sliced tab state and fragile dismiss signals Jun 15, 2026
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.

3 participants