Skip to content

[$250] Distance field shows old distance, but waypoints are updated when split is edited offline #83504

Closed

Description

@vincdargento

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Version Number: 9.3.26-0
Reproducible in staging?: Yes
Reproducible in production?: N/A - new feature, doesn't exist in prod
If this was caught during regression testing, add the test name, ID and link from BrowserStack: #82257
Email or phone of affected tester (no customers): sdjoisnjdosnjdosjoi@gmail.com
Issue reported by: Applause Internal Team
Bug source: Exploratory - Significant User Experience Deterioration
Device used: Mac 26.2 / Chrome
App Component: Money Requests

Action Performed:

  1. Go to staging.new.expensify.com
  2. Go to workspace chat.
  3. Create a map distance expense.
  4. Open the expense.
  5. Click More > Split > Save.
  6. Open any split.
  7. Go offline.
  8. Click Amount.
  9. Click on the highlighted row.
  10. Click Distance.
  11. Add one more stop with any waypoint from the recent destination list.
  12. Click Save > Save.
  13. Go online.
  14. Click Distance field.

Expected Result:

Distance field will show the new distance.

Actual Result:

Distance field shows the old distance, but waypoints are updated.

Workaround:

Unknown

Platforms:

  • Android: App
  • Android: mWeb Chrome
  • iOS: App
  • iOS: mWeb Safari
  • iOS: mWeb Chrome
  • Windows: Chrome
  • MacOS: Chrome / Safari

Screenshots/Videos

bug.mp4

View all open jobs on GitHub

Issue OwnerCurrent Issue Owner: @abdulrahuman5196
Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~022026795641307665315
  • Upwork Job ID: 2026795641307665315
  • Last Price Increase: 2026-02-25

Activity

  1. added
    DeployBlockerCashThis issue or pull request should block deployment
    BugSomething is broken. Auto assigns a BugZero manager.
    on Feb 25, 2026
  2. melvin-bot commented on Feb 25, 2026

    @melvin-bot

    You have been assigned to this deploy blocker because you recently merged this PR: #82257

  3. melvin-bot commented on Feb 25, 2026

    @melvin-bot

    💬 A slack conversation has been started in #expensify-open-source

  4. melvin-bot commented on Feb 25, 2026

    @melvin-bot

    Triggered auto assignment to @trjExpensify (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

  5. github-actions commented on Feb 25, 2026

    @github-actions
    Contributor

    👋 Friendly reminder that deploy blockers are time-sensitive ⏱ issues! Check out the open `StagingDeployCash` deploy checklist to see the list of PRs included in this release, then work quickly to do one of the following:

    1. Identify the pull request that introduced this issue and revert it.
    2. Find someone who can quickly fix the issue.
    3. Fix the issue yourself.
  6. OSBotify commented on Feb 25, 2026

    @OSBotify
    Contributor

    🔍 Investigation Summary

    Classification: Frontend bug
    Causing PR: #82257 - "feat: handle the Distance and Rate fields for splits" by @ZhenjaHorbach (High confidence)
    Related Issues: None identified

    Recommendation: REVERT

    PR #82257 introduced distance and rate field handling for split expenses but appears to have an issue with offline-to-online synchronization. When a split is edited offline with new waypoints and then goes online, the route/distance recalculation does not properly update the displayed distance field, even though the waypoints are correctly updated.

    Labels: No label changes needed. This is a frontend bug, so DeployBlockerCash should remain.

    📋 Detailed Analysis

    Evidence

    PR #82257 was merged on 2026-02-24 and is included in version 9.3.26-0 (listed in the StagingDeployCash issue). The PR introduced:

    1. New SPLIT_DRAFT transaction state for handling split expense drafts
    2. New API command GetRouteForSplitDraft for fetching routes for split drafts
    3. Changes to how waypoints are updated for split transactions
    4. Modified useFetchRoute hook to handle split draft transactions

    The issue reproduction steps directly match the new functionality added in this PR:

    • Creating a map distance expense and splitting it
    • Editing a split offline
    • Adding waypoints from recent destinations
    • Going online and observing the distance field

    Verification

    The PR modifies these key files related to the bug:

    • src/libs/actions/Transaction.ts - Added SPLIT_DRAFT state handling in getRoute() and updateWaypoints()
    • src/pages/iou/request/step/IOURequestStepDistanceMap.tsx - Modified to use splitDraftTransaction when editing splits
    • src/pages/iou/request/step/IOURequestStepDistance.tsx - Added split draft transaction handling
    • src/hooks/useFetchRoute.ts - Already supports transactionState parameter
    • src/libs/actions/IOU/Split.ts - Extensive changes to handle distance splits

    Root Cause

    When editing a split expense offline:

    1. Waypoints are saved to SPLIT_TRANSACTION_DRAFT collection correctly
    2. When going online, useFetchRoute triggers a route fetch using GetRouteForSplitDraft API command
    3. The route is fetched and the distance is calculated by the backend
    4. However, the distance displayed in the UI is not properly updated from the fetched route

    The issue appears to be in how the split draft transaction merges the fetched route data back into the displayed transaction. The waypoints are correctly shown (they are saved optimistically), but the distance field (which depends on the route calculation) shows the old value.

    This is likely because:

    • The route response updates SPLIT_TRANSACTION_DRAFT but not the main transaction
    • Or the distance field is reading from the wrong transaction object
    • Or there is a race condition where the old distance is being displayed before the route fetch completes
  7. MelvinBot commented on Feb 25, 2026

    @MelvinBot
    Contributor

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    When a user edits a split distance expense offline by modifying waypoints (e.g., adding a stop), then goes back online and views the distance field, it displays the old distance rather than reflecting the updated waypoints. The waypoints themselves are correctly updated, but the distance value is stale.

    What is the root cause of that problem?

    The root cause is that comment.customUnit.quantity (the stored distance value) is never cleared on the main split draft when waypoints change during the split distance edit flow.

    Here's the exact chain of events:

    1. When the user edits waypoints on a split, saveWaypoint() (Transaction.ts:143-170) correctly clears routes.route0.distance, routes.route0.geometry.coordinates, and comment.customUnit.quantity — but only on the temporary distance edit draft (SPLIT_TRANSACTION_DRAFT + OPTIMISTIC_DISTANCE_SPLIT_TRANSACTION_ID, i.e., key '2').

    2. When the user presses Save on the distance page, submitWaypoints in IOURequestStepDistance.tsx:442-448 calls setDraftSplitTransaction() which propagates changes back to the main split draft (SPLIT_TRANSACTION_DRAFT + OPTIMISTIC_TRANSACTION_ID, key '1').

    3. Inside setDraftSplitTransaction (Split.ts:1803-1811), getUpdatedTransaction() deep-clones the main draft (key '1') and applies the waypoint changes. The deep clone preserves the original comment.customUnit.quantity (the old distance value) because getUpdatedTransaction (TransactionUtils/index.ts:713-751) never clears this field when processing waypoint changes.

    4. Meanwhile, useFetchRoute (useFetchRoute.ts:31-33) cannot recalculate the route because it has an isOffline guard that skips getRoute() entirely when offline. Route fetching uses API.read() which is not queued for offline replay.

    5. When getDistanceInMeters() (getDistanceInMeters.ts:7-18) runs to display the distance, it checks routes.route0.distance first (null — cleared), then falls back to comment.customUnit.quantity — which still contains the old distance value, causing the stale display.

    6. This also affects updateSplitExpenseField (Split.ts:2293-2332), which reads the same stale customUnit.quantity and sends the old distance/amount to the server when the split is finalized.

    What changes do you think we should make in order to solve the problem?

    In getUpdatedTransaction() in TransactionUtils/index.ts, inside the waypoints change block (line 713+), when waypoints have changed but no route coordinates are available (the "pending from BE" branch at lines 721-726), also clear comment.customUnit.quantity:

    // Inside the `if (!transactionChanges.routes?.route0?.geometry?.coordinates)` block:
    updatedTransaction.amount = CONST.IOU.DEFAULT_AMOUNT;
    updatedTransaction.modifiedAmount = CONST.IOU.DEFAULT_AMOUNT;
    updatedTransaction.modifiedMerchant = translateLocal('iou.fieldPending');
    // ADD: Clear stale distance so getDistanceInMeters doesn't fall back to old value
    lodashSet(updatedTransaction, 'comment.customUnit.quantity', null);
    

    This ensures that when waypoints change without a recalculated route (the offline case), the stale distance quantity is cleared. getDistanceInMeters will then return 0 instead of the old value, and the UI will correctly show the distance as pending until the route is recalculated by the backend when the queued API.write command fires upon reconnection.

    This fix is safe for non-split transactions as well, since in that case the amount is already set to 0 and modifiedMerchant is set to "Pending..." — the stale quantity was just never read because non-split edits use API.write(UPDATE_MONEY_REQUEST_DISTANCE) which queues for offline replay and the backend recalculates.

    What alternative solutions did you explore? (Optional)

    1. Clear quantity in setDraftSplitTransaction specifically: Could add lodashSet(updatedTransaction, 'comment.customUnit.quantity', null) directly in setDraftSplitTransaction before the Onyx merge. This is more targeted but only fixes the split path — the underlying issue in getUpdatedTransaction would remain for any future callers.

    2. Include customUnit.quantity: null in transactionChanges: Modify IOURequestStepDistance.tsx:446 to pass customUnit: {quantity: null} in the transactionChanges alongside waypoints and routes. This shifts the responsibility to the caller rather than fixing the generic utility.

    3. Add a reconnection handler: Register a listener that triggers getRoute() for split drafts with pending routes when connectivity is restored. This is more complex and doesn't address the stale display issue — the distance would still show the old value until the route is recalculated.


    Next Steps for Contributor+ team: Reply with @MelvinBot implement this to create a draft PR, or @MelvinBot <your feedback> to refine this analysis.

  8. 5 remaining items

  9. melvin-bot commented on Feb 25, 2026

    @melvin-bot
  10. suneox commented on Feb 26, 2026

    @suneox
    Contributor

    This issue requires both FE and BE handling, as the BE response is the same after clearing the cache.

    83504.1.mp4
  11. puneetlath commented on Feb 26, 2026

    @puneetlath
    Contributor

    Demoting as BE issue. cc @lakchote

  12. removed
    Help WantedApply this label when an issue is open to proposals by contributors
    on Feb 27, 2026
  13. lakchote commented on Feb 27, 2026

    @lakchote
    Contributor

    EDIT: see #83504 (comment)

    This is not a BE issue @puneetlath @suneox. It's a frontend issue cc @ZhenjaHorbach

    After going back offline, UpdateSplitTransaction is called with new waypoints but with old distance/quantity.

    BE persists what the FE sends, so it's expected that clearing the cache doesn't change anything.

    Video:

    Screen.Recording.2026-02-27.at.08.19.18.mp4
  14. ZhenjaHorbach commented on Feb 27, 2026

    @ZhenjaHorbach
    Contributor

    This is not a BE issue @puneetlath @suneox. It's a frontend issue cc @ZhenjaHorbach

    After going back offline, UpdateSplitTransaction is called with new waypoints but with old distance/quantity.

    BE persists what the FE sends, so it's expected that clearing the cache doesn't change anything.

    Video:

    Screen.Recording.2026-02-27.at.08.19.18.mp4

    But how are we planning to calculate it offline?
    If the distance between waypoints we can get only online?

  15. lakchote commented on Feb 27, 2026

    @lakchote
    Contributor
  16. lakchote commented on Mar 19, 2026

    @lakchote
    Contributor

    Issue not repro:

    Screen.Recording.2026-03-19.at.09.08.47.mp4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugSomething is broken. Auto assigns a BugZero manager.EngineeringExternalAdded to denote the issue can be worked on by a contributorHourlyKSv2ReviewingHas a PR in review

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions