Skip to content

Distance - Distance field shows new unit instead of original unit after changing distance unit #84195

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.31-0
Reproducible in staging?: Yes
Reproducible in production?: No
If this was caught during regression testing, add the test name, ID and link from BrowserStack: #79638
Email or phone of affected tester (no customers): osdjosjdnodnjoijso@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. Go to workspace settings > Distance rates.
  5. Click Settings > Unit.
  6. Change to another unit.
  7. Open the distance expense from Step 3.
    → Distance field shows the new unit instead of the original unit.
  8. Click Distance.
    → Distance field in Step 7 shows the new unit. Distance editor further converts to the same unit.

Expected Result:

In Step 7, Distance field will show the original unit.

Actual Result:

In Step 7, Distance field shows the new unit instead of the original unit.
In Step 8, Distance editor further converts to the same unit.

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

Activity

  1. added
    DeployBlockerCash
    Daily
    Bug
    on Mar 4, 2026
  2. melvin-bot commented on Mar 4, 2026

    @melvin-bot

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

  3. melvin-bot commented on Mar 4, 2026

    @melvin-bot

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

  4. melvin-bot commented on Mar 4, 2026

    @melvin-bot

    Triggered auto assignment to @johncschuster (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 Mar 4, 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 Mar 4, 2026

    @OSBotify
    Contributor

    🔍 Investigation Summary

    Classification: Frontend bug
    Causing PR: #79638 - "Fix distance unit not updating on workspace switch" by @marufsharifi (High confidence)
    Related Issues: #78212 (issue that PR #79638 was fixing)

    Recommendation: REVERT

    PR #79638 fixed one issue (unit not updating when switching between workspaces) but introduced a regression where changing a workspace distance unit setting causes existing distance expenses to immediately display the new unit instead of preserving their original unit at creation time.

    Labels: This is a frontend bug caused by an App PR. Keeping DeployBlockerCash label. The DeployBlocker label was not present on this issue.

    📋 Detailed Analysis

    Evidence

    PR #79638 modified the getDistanceUnit() function in src/libs/DistanceRequestUtils.ts which directly affects how distance units are displayed for transactions. The change was merged on 2026-03-04 and is included in the current staging deploy (9.3.31-0).

    The issue reproduction steps match exactly what the code change would cause:

    1. Create a manual distance expense (stores the current unit, e.g., miles)
    2. Change workspace distance unit settings (changes the mileage rate unit to km)
    3. View the distance expense - it now shows km instead of the original miles

    Verification

    Files affected by the bug:

    • src/libs/DistanceRequestUtils.ts - contains getDistanceUnit() function
    • src/pages/iou/request/step/IOURequestStepDistanceRate.tsx - uses getDistanceUnit() to display distance units (line 100, 132)

    PR #79638 modifies DistanceRequestUtils.ts and its test file, confirming it touches the exact code path responsible for this issue.

    Root Cause

    Original logic (before PR #79638):

    return transaction?.comment?.customUnit?.distanceUnit ?? mileageRate?.unit ?? CONST.CUSTOM_UNITS.DISTANCE_UNIT_MILES;

    This would always prefer the transaction stored unit if present.

    New logic (after PR #79638):

    const transactionUnit = transaction?.comment?.customUnit?.distanceUnit;
    const rateUnit = mileageRate?.unit;
    
    if (transactionUnit && transactionUnit === rateUnit) {
        return transactionUnit;
    }
    
    return rateUnit ?? CONST.CUSTOM_UNITS.DISTANCE_UNIT_MILES;

    The problem: The new logic only returns the transaction unit if it matches the current rate unit. When a workspace admin changes the distance unit setting:

    • Existing transactions have the old unit stored (e.g., miles)
    • The new mileage rate has the new unit (e.g., km)
    • Since they do not match, the function returns the new rate unit instead of preserving the original transaction unit
    • This causes the distance field to display the wrong unit and convert the value incorrectly

    PR #79638 was intended to fix issue #78212 (unit not updating when switching workspaces), but it went too far and now causes units to update even when they should not (when viewing a historical transaction after changing workspace settings).

  7. MelvinBot commented on Mar 4, 2026

    @MelvinBot
    Contributor

    Proposal

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

    After changing the distance unit in workspace settings (e.g., miles → km), existing distance expenses retroactively display the new unit instead of the original unit they were created with. Opening the distance editor further converts the value to the new unit.

    What is the root cause of that problem?

    PR #79638 changed the getDistanceUnit function in src/libs/DistanceRequestUtils.ts (lines 396-405). The old code used a simple nullish coalescing fallback that always preferred the transaction's stored unit:

    return transaction?.comment?.customUnit?.distanceUnit ?? mileageRate?.unit ?? CONST.CUSTOM_UNITS.DISTANCE_UNIT_MILES;
    

    The new code only returns the transaction's stored unit if it equals the policy's current rate unit:

    if (transactionUnit && transactionUnit === rateUnit) {
        return transactionUnit;
    }
    return rateUnit ?? CONST.CUSTOM_UNITS.DISTANCE_UNIT_MILES;
    

    When the workspace admin changes the distance unit (e.g., miles → km), the stored transaction unit (mi) no longer matches the policy's current rate unit (km), so the equality check fails and the function returns the policy's new unit instead of the transaction's original unit. This wrong unit then flows through MoneyRequestView.tsx (line 420) and the distance editors, causing the display and conversion issues.

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

    Revert getDistanceUnit to prefer the transaction's stored distanceUnit when it exists, regardless of whether it matches the policy's current rate unit. The function should return to the simple fallback chain: transaction unit first, then rate unit, then the default (miles).

    The original problem that PR #79638 was solving (unit not updating on workspace switch during creation) should instead be handled by the callers — specifically by passing useTransactionDistanceUnit: false in the workspace-switching creation flow, rather than changing the core getDistanceUnit logic that affects all existing expense displays.

    What alternative solutions did you explore? (Optional)

    An alternative would be to add a separate code path in getDistanceUnit that distinguishes "viewing an existing expense" from "creating/editing and switching workspaces." However, this distinction is already handled by the useTransactionDistanceUnit parameter on getRate() — when it's false, getDistanceUnit receives undefined for the transaction and naturally falls back to the rate unit. The simpler revert is the cleaner fix.


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

  8. inimaga commented on Mar 5, 2026

    @inimaga
    Contributor

    @marufsharifi I'm going to revert your PR for now to resolve this deploy blocker. Please raise a follow-up PR for the original issue later with this regression in mind.

    cc: @mananjadhav

  9. added
    Reviewing
    on Mar 5, 2026
  10. m-natarajan commented on Mar 5, 2026

    @m-natarajan

    Chrome / v9.3.31-5
    Distance field shows original unit.
    Distance editor shows new unit.

    Screen.Recording.2026-03-05.at.17.56.47.mp4
  11. inimaga commented on Mar 5, 2026

    @inimaga
    Contributor

    Thanks for confirming.

  12. removed
    DeployBlockerCash
    Hourly
    on Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugEngineeringReviewing

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions