Skip to content

[$250] Distance - After changing unit, Distance field keeps the new value with old unit #83654

Closed

Description

@mitarachim

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-7
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): sdjoijnsdoinsjoisjio@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:

Precondition:

  • Enable Distance rates in workspace settings > More features.
  1. Go to staging.new.expensify.com
  2. Go to workspace chat.
  3. Create a manual distance expense.
  4. Open the expense.
  5. Click More > Split > Save.
  6. Go to workspace settings > Distance rates.
  7. Click Settings > Unit.
  8. Change to another unit.
  9. Open any distance split from Step 5.
  10. Click Amount > click highlighted row.
  11. Click Distance.
  12. Click Save.
  13. Click Distance.
  14. Click Save.

Expected Result:

After saving distance with new unit, Distance field should also save the new unit.

Actual Result:

After saving distance with new unit, Distance field keeps the new value with old unit.
When user reopens Distance and resaves it, the value is converted again and old unit is saved.

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

Bug7089791_1772166810414.18.mp4

View all open jobs on GitHub

Issue OwnerCurrent Issue Owner: @aimane-chnaif
Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~022027246830565122976
  • Upwork Job ID: 2027246830565122976
  • Last Price Increase: 2026-02-27

Activity

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

    @melvin-bot

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

  3. melvin-bot commented on Feb 27, 2026

    @melvin-bot

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

  4. melvin-bot commented on Feb 27, 2026

    @melvin-bot

    Triggered auto assignment to @heyjennahay (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 27, 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. MelvinBot commented on Feb 27, 2026

    @MelvinBot
    Contributor

    Proposal

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

    After changing the distance rate unit in workspace settings (e.g., miles → kilometers), editing a split expense's Distance field shows the correctly converted value but with the wrong unit label. When the user saves and reopens the Distance field, the value gets converted again, compounding the error on each save cycle.

    What is the root cause of that problem?

    The root cause is in getUpdatedTransaction in src/libs/TransactionUtils/index.ts:859-888. When processing a distance change for split edits, it updates comment.customUnit.quantity with the new distance value (which is expressed in the current policy unit) but never updates comment.customUnit.distanceUnit to match.

    Here's the specific flow that triggers the bug:

    1. A split is created with 10 mi. The split draft stores quantity=10, distanceUnit='mi'.
    2. The workspace admin changes the distance unit from miles to kilometers.
    3. The user opens the Distance field on the split. IOURequestStepDistanceManual.tsx:112-116 uses useTransactionDistanceUnit: false to get the current policy unit (km), correctly converts 10 mi → 16.09 km for display.
    4. The user saves. setDraftSplitTransaction is called with {distance: 16.09}, which triggers getUpdatedTransaction. At line 862, quantity is set to 16.09. At line 865-866, the policy unit km is fetched correctly for amount calculation. But distanceUnit on the draft is never updated — it remains 'mi'.
    5. The split draft now has quantity=16.09 (in km) but distanceUnit='mi' — a mismatch.
    6. When the user reopens the Distance field, getDistanceInMeters at line 117 reads distanceUnit='mi' from the draft and interprets 16.09 as miles, converting it to ~25,896 meters instead of the correct ~16,090 meters. This is then displayed as ~25.9 km.
    7. Each subsequent save-and-reopen cycle compounds the error.

    By contrast, the customUnitRateID change handler at lines 757-773 in the same function does correctly update distanceUnit (line 766) and convert the quantity (lines 769-772). The distance change handler was simply missing the same distanceUnit update.

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

    In src/libs/TransactionUtils/index.ts, in the distance change handler block (line 859-888), add a line to update distanceUnit to match the current policy unit. Specifically, after line 866 where unit is already available from the policy rate, add:

    lodashSet(updatedTransaction, 'comment.customUnit.distanceUnit', unit);
    

    This ensures the split draft's distanceUnit stays in sync with the unit the quantity value was expressed in, preventing the mismatch that causes the double-conversion bug.

    What alternative solutions did you explore? (Optional)

    An alternative would be to update distanceUnit in the split-specific save path in IOURequestStepDistanceManual.tsx:169-171 by passing distanceUnit alongside distance in the transactionChanges. However, fixing it in getUpdatedTransaction is more robust since it addresses the root cause at the shared utility level, ensuring any caller that updates distance on a transaction also gets the correct distanceUnit.


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

  7. 13 remaining items

  8. melvin-bot commented on Feb 27, 2026

    @melvin-bot

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

  9. melvin-bot commented on Feb 27, 2026

    @melvin-bot

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

  10. github-actions commented on Feb 27, 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.
  11. OSBotify commented on Feb 27, 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

    Recommendation: REVERT

    This is a new feature that does not exist in production (as confirmed in the issue description: "N/A - new feature, doesn't exist in prod"). The bug fundamentally breaks the distance split editing flow when workspace distance units are changed, causing values to be incorrectly converted on each save cycle. A clean revert is the safest option to unblock the deploy, and the feature can be re-introduced with a proper fix.

    Labels: Keeping DeployBlockerCash (frontend App PR caused the issue, blocks App deploy)

    📋 Detailed Analysis

    Evidence

    PR #82257 was merged on 2026-02-24 and appears in the current StagingDeployCash checklist (#83466). The PR added the ability to edit distance and rate fields on individual splits. MelvinBot automatically assigned this issue to the PR author, and the reproduction steps directly involve the new split distance editing functionality introduced by this PR.

    Verification

    The bug occurs in split distance expense editing. PR #82257 modified these key files:

    • src/libs/TransactionUtils/index.ts (added distance change handler)
    • src/pages/iou/request/step/IOURequestStepDistanceManual.tsx (split editing logic)
    • src/pages/iou/SplitExpenseEditPage.tsx (split distance/rate UI)
    • src/libs/actions/IOU/Split.ts (split transaction handling)

    All files are in the App repository and directly relate to the reported split distance editing bug.

    Root Cause

    In src/libs/TransactionUtils/index.ts lines 859-888, the distance change handler updates comment.customUnit.quantity with the new distance value (line 862) and correctly fetches the current policy unit at line 866. However, it never updates comment.customUnit.distanceUnit to match.

    This creates a mismatch: the quantity is stored in the new unit (e.g., km) but distanceUnit still reflects the old unit (e.g., mi).

    When the user reopens the Distance field, getDistanceInMeters() at line 117 of IOURequestStepDistanceManual reads the mismatched distanceUnit and interprets the quantity as being in the wrong unit, causing incorrect conversion. Each save-reopen cycle compounds the error.

    By contrast, the customUnitRateID change handler in the same file (lines 757-773) correctly updates distanceUnit at line 766 and properly converts the quantity when the unit changes (lines 769-772). The distance handler should follow this same pattern but currently does not.

  12. added and removed
    DeployBlockerCashThis issue or pull request should block deployment
    on Feb 27, 2026
  13. melvin-bot commented on Mar 6, 2026

    @melvin-bot

    @suneox, @heyjennahay, @lakchote, @ZhenjaHorbach Still overdue 6 days?! Let's take care of this!

  14. lakchote commented on Mar 9, 2026

    @lakchote
    Contributor
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.DailyKSv2Engineering

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions