Skip to content

[$250] Distance - Old unit persists when splitting distance after changing distance unit #83485

Closed

Description

@jponikarchuk

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): sdjsiodjsnodjsonjsio@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. Create a workspace.
  3. Go to workspace settings > More features.
  4. Enable Distance rates.
  5. Go to workspace settings > Distance rates.
  6. Click Settings > Unit > change to Kilometers.
  7. Go to workspace chat.
  8. Create a manual distance expense.
  9. Open the expense.
  10. Click More > Split.
  11. Click any split row.
    → Distance and Rate row still show miles after changing unit to kilometers.
  12. Click Distance.
    → Distance editor shows converted distance in kilometers.
  13. Click Save.
    → Distance is changed but the unit remains the same.

Expected Result:

In Step 11, Distance and Rate row will show kilometers because distance unit is changed to kilometers in Step 6.
In Step 13, Distance will update to kilometers together with the rate.

Actual Result:

In Step 11, Distance and Rate row still show miles after changing unit to kilometers.
In Step 13, Distance is changed but the unit is still miles.

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

1.mp4

View all open jobs on GitHub

Issue OwnerCurrent Issue Owner: @ZhenjaHorbach
Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~022026758698186474494
  • Upwork Job ID: 2026758698186474494
  • 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 @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 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

    Recommendation: REVERT

    The PR introduced a bug in the split distance expense flow where the distance unit is not updated when creating split expenses. When a workspace distance rate is changed from miles to kilometers, the split expenses still display the old unit (miles) instead of the updated unit (kilometers).

    Labels: No label changes made. The issue correctly has DeployBlockerCash since this is a frontend bug that requires an App PR to fix.

    📋 Detailed Analysis

    Evidence

    PR #82257 added comprehensive support for distance and rate fields in split expenses. The bug was introduced in the updateSplitExpenseDistanceFromAmount function in /home/runner/_work/App/App/src/libs/actions/IOU/Split.ts.

    The reproduction steps clearly show:

    1. User creates a workspace and enables distance rates
    2. Changes the distance unit from miles to kilometers in workspace settings
    3. Creates a distance expense and splits it
    4. The split expense rows incorrectly show miles instead of kilometers

    Verification

    The causing PR modifies several distance-related files:

    • src/libs/actions/IOU/Split.ts - Core split logic
    • src/pages/iou/SplitExpenseEditPage.tsx - Split expense UI
    • src/libs/TransactionUtils/index.ts - Transaction utilities

    The PR was merged on 2026-02-24 and is included in staging deploy 9.3.26-0, matching the version where the bug was reported.

    Root Cause

    In src/libs/actions/IOU/Split.ts, the function updateSplitExpenseDistanceFromAmount (lines 1890-1915):

    function updateSplitExpenseDistanceFromAmount(
        amount: number,
        rate: number,
        unit: Unit | undefined,  // This is the CORRECT unit from the policy (kilometers)
        existingCustomUnit: TransactionCustomUnit | undefined,  // This has the OLD unit (miles)
        mileageRate: {currency?: string},
        transactionCurrency?: string,
    ): {customUnit: TransactionCustomUnit | undefined; merchant: string} {
        // ...
        const customUnit: TransactionCustomUnit = {
            ...existingCustomUnit,  // Spreads old customUnit with distanceUnit: "mi"
            quantity,  // Only updates quantity, NOT distanceUnit
        };
        // The "unit" parameter is used for merchant calculation but NOT saved to customUnit.distanceUnit
        const merchant = getDistanceMerchantFromDistance(distanceInUnits, unit, rate, ...);
        
        return {customUnit, merchant};
    }

    The function receives the correct unit from the policy (kilometers) but only uses it to calculate the merchant string. It spreads existingCustomUnit which contains the old distanceUnit: "mi" from the original transaction, without updating it to the new unit.

    The fix would be to update line 1907-1910 to:

    const customUnit: TransactionCustomUnit = {
        ...existingCustomUnit,
        quantity,
        distanceUnit: unit,  // Add this line
    };
  7. lakchote commented on Feb 25, 2026

    @lakchote
    Contributor

    cc @ZhenjaHorbach comes from #78891

  8. 5 remaining items

  9. changed the title [-]Distance - Old unit persists when splitting distance after changing distance unit[/-] [+][$250] Distance - Old unit persists when splitting distance after changing distance unit[/+] on Feb 25, 2026
  10. melvin-bot commented on Feb 25, 2026

    @melvin-bot
  11. melvin-bot commented on Feb 26, 2026

    @melvin-bot

    ⚠️ Looks like this issue was linked to a Deploy Blocker here

    If you are the assigned CME please investigate whether the linked PR caused a regression and leave a comment with the results.

    If a regression has occurred and you are the assigned CM follow the instructions here.

    If this regression could have been avoided please consider also proposing a recommendation to the PR checklist so that we can avoid it in the future.

  12. melvin-bot commented on Feb 26, 2026

    @melvin-bot

    ⚠️ Looks like this issue was linked to a Deploy Blocker here

    If you are the assigned CME please investigate whether the linked PR caused a regression and leave a comment with the results.

    If a regression has occurred and you are the assigned CM follow the instructions here.

    If this regression could have been avoided please consider also proposing a recommendation to the PR checklist so that we can avoid it in the future.

  13. Pujan92 commented on Feb 26, 2026

    @Pujan92
    Contributor

    @lakchote Plz unassign me here and assign it to @ZhenjaHorbach

  14. m-natarajan commented on Feb 26, 2026

    @m-natarajan

    Not Repro, Windows 10/ Chrome, v9.3.26-6

    repro.-.issue.83485.mp4
  15. yifangoh commented on Feb 26, 2026

    @yifangoh
    Contributor

    Proposal

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

    After changing the workspace distance unit from miles to kilometers, splitting a distance expense still shows the old unit (miles) in each split row's Distance and Rate fields.

    What is the root cause of that problem?

    In src/libs/TransactionUtils/index.ts (buildOptimisticTransaction, ~line 511), when customUnit is provided (the split expense path), it is set on the transaction verbatim without updating distanceUnit:

    if (customUnit) {
        lodashSet(commentJSON, 'customUnit', customUnit);
    }
    

    The else branch (non-split path at line 515) correctly calls DistanceRequestUtils.getUpdatedDistanceUnit({transaction, policy}) to get the current policy unit. But the split path skips this entirely, so each split inherits the original transaction's stale distanceUnit (e.g. mi) even though the policy now uses km.

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

    In buildOptimisticTransaction in src/libs/TransactionUtils/index.ts, after setting customUnit from the provided parameter (~line 512), also update customUnit.distanceUnit to the current policy unit by calling DistanceRequestUtils.getUpdatedDistanceUnit({transaction: existingTransaction, policy}). This ensures split transactions pick up the workspace's current distance unit setting rather than preserving the stale unit from the original transaction.

    The quantity (distance value) should also be converted from the old unit to the new unit when the units differ (e.g. miles → km), using the existing conversion logic in DistanceRequestUtils, so the displayed distance is correct in the new unit.

    What alternative solutions did you explore? (Optional)

    Updating the distanceUnit at the call site in src/libs/actions/IOU/Split.ts (where splitExpense.customUnit is assembled) was considered, but fixing it in buildOptimisticTransaction is more centralized and prevents the same stale-unit bug from occurring in any other code path that passes customUnit directly.

  16. removed
    Help WantedApply this label when an issue is open to proposals by contributors
    on Mar 3, 2026
  17. lakchote commented on Mar 3, 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.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