You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[$250] Distance - Distance format on the report header changes after changing rate #83958
BugSomething is broken. Auto assigns a BugZero manager.DailyKSv2EngineeringInternalRequires API changes or must be handled by Expensify staffReviewingHas a PR in review
Version Number: 9.3.28-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:#74967 Email or phone of affected tester (no customers):isodjnosidjiojiojiso@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:
Workspace has at least two distance rates.
Go to staging.new.expensify.com
Go to self DM.
Create a manual distance expense with 10 miles.
Open the expense.
→ Header shows amount for 10.00 mi @ rate.
Click Rate and select another rate.
Expected Result:
Distance on the report header will show 10.00 mi.
Actual Result:
Distance on the report header changes from 10.00 mi to 10 mi after changing rate.
👋 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:
Identify the pull request that introduced this issue and revert it.
Classification: Frontend bug Causing PR: #74967 - "Fix - [Unreported] Add distance rate to the distance expenses tracked in selfDM" by @FitseTLT (High confidence) Related Issues: None
Recommendation: ROLL FORWARD
The PR introduced logic to handle distance rate changes for track expenses in selfDM, but has an inconsistency bug in how the distance is displayed after changing rates. The fix is straightforward - use the correct variables for display consistency.
Labels: No label changes needed. This is a Frontend bug that blocks the App deploy, so DeployBlockerCash should remain.
The Bug: Line 432 uses unit and rate for displaying distance, but line 431 correctly uses distanceUnit and distanceRate for displaying the rate. This inconsistency causes the distance format to change after rate selection because unit is derived from the new rate while distance is calculated from the transaction data with the old unit.
Root Cause
When a user changes the distance rate for a track expense:
Lines 427-428 correctly calculate distanceUnit and distanceRate from the transaction data for track expenses without a rate
Line 431 uses these values to display the rate correctly
Line 432 incorrectly uses the original unit and rate variables instead of distanceUnit and distanceRate
This causes a mismatch: the rate display uses one set of values while the distance display uses a different set, leading to the formatting inconsistency described in the bug (distance changes from "10.00 mi" to "10 mi").
The fix is simple: Line 432 should use distanceUnit and distanceRate instead of unit and rate for consistency with line 431.
Please re-state the problem that we are trying to solve in this issue.
After creating a manual distance expense with 10 miles in selfDM, the report header correctly shows "10.00 mi @ rate". However, when the user changes the rate to a different one, the distance format in the report header changes from "10.00 mi" to "10 mi" — losing the decimal places.
What is the root cause of that problem?
The root cause is a policy context mismatch between the optimistic update path and the rendering path, introduced by PR #74967.
During a rate change, the optimistic update in getUpdatedTransaction() (TransactionUtils/index.ts:785-800) correctly computes modifiedMerchant via getDistanceMerchant(), which always formats with 2 decimal places using getRoundedDistanceInUnits() → toFixed(2). This works because getUpdatedTransaction receives the correct workspace policy parameter.
During rendering, getMerchant() (TransactionUtils/index.ts:1134-1163) derives the policy from getPolicy(report?.policyID). For a selfDM expense, this returns the personal policy which has no customUnits. Because policy?.customUnits is falsy at line 1144, getMerchant does NOT recalculate the merchant with proper formatting — it falls through to returning the raw stored modifiedMerchant or merchant field at line 1162.
PR #74967 also changed getRate() (DistanceRequestUtils.ts:412-413) to return undefined for unreported expenses when the rate isn't found in available mileage rates (instead of falling back to defaultMileageRate). Combined with track distance expenses now getting real policy rate IDs instead of FAKE_P2P_ID, getMerchant called from display contexts can no longer resolve the rate to recalculate.
The API call only sends customUnitRateID in the params (not the merchant — see line 5110 of IOU/index.ts), so the server recalculates the merchant independently. If the server formats without preserving 2 decimal places (e.g. "10 mi" instead of "10.00 mi"), this overwrites the optimistic modifiedMerchant when the response is merged back into Onyx.
What changes do you think we should make in order to solve the problem?
The fix should ensure getMerchant() in TransactionUtils/index.ts can properly recalculate the distance merchant for selfDM/unreported track expenses, rather than falling through to the raw stored value.
Specifically, in getMerchant() at TransactionUtils/index.ts:1143-1146, the condition should be expanded to also recalculate when the transaction is a distance request with a modifiedMerchant — even if the policy doesn't have customUnits. For selfDM distance expenses, the unit can be derived from getDistanceUnit (which falls back to the transaction's stored unit), and the rate from the mileage rate. The function already has unit and rate resolved at lines 1140-1141 — it just needs to use them when rate is available, regardless of whether policy?.customUnits is truthy.
Alternatively, the getRate call inside getMerchant could be updated to also check policyForMovingExpenses (the workspace policy associated with the expense) when the direct policy lookup fails for selfDM expenses.
What alternative solutions did you explore? (Optional)
Including merchant in the API params: Modify getUpdateTrackExpenseParams to always include the correctly-formatted merchant when sending rate changes. However, this duplicates server-side logic and doesn't fix the rendering mismatch.
Server-side fix: Ensure the server always formats distance with 2 decimal places. This would fix the symptom but not the underlying client-side issue where getMerchant can't recalculate for selfDM expenses.
Next Steps for Contributor+ team: Reply with @MelvinBot implement this to create a draft PR, or @MelvinBot <your feedback> to refine this analysis.
If this was a selfDM P2P thing I would probably say yes, but given that in FItsum's video the format changes when modifying the rate of an expense on an expense report - I think it would be worthwhile to address because it makes the product feel a bit janky.
BugSomething is broken. Auto assigns a BugZero manager.DailyKSv2EngineeringInternalRequires API changes or must be handled by Expensify staffReviewingHas a PR in review
Activity
melvin-bot commentedon Mar 2, 2026
You have been assigned to this deploy blocker because you recently merged this PR: #74967
melvin-bot commentedon Mar 2, 2026
💬 A slack conversation has been started in #expensify-open-source
melvin-bot commentedon Mar 2, 2026
Triggered auto assignment to @laurenreidexpensify (
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.github-actions commentedon Mar 2, 2026
👋 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:
OSBotify commentedon Mar 2, 2026
Investigation Summary
Classification: Frontend bug
Causing PR: #74967 - "Fix - [Unreported] Add distance rate to the distance expenses tracked in selfDM" by @FitseTLT (High confidence)
Related Issues: None
Recommendation: ROLL FORWARD
The PR introduced logic to handle distance rate changes for track expenses in selfDM, but has an inconsistency bug in how the distance is displayed after changing rates. The fix is straightforward - use the correct variables for display consistency.
Labels: No label changes needed. This is a Frontend bug that blocks the App deploy, so
DeployBlockerCashshould remain.Detailed Analysis
Evidence
MoneyRequestView.tsxand related filesVerification
In
/home/runner/_work/App/App/src/components/ReportActionItem/MoneyRequestView.tsxlines 426-432:The Bug: Line 432 uses
unitandratefor displaying distance, but line 431 correctly usesdistanceUnitanddistanceRatefor displaying the rate. This inconsistency causes the distance format to change after rate selection becauseunitis derived from the new rate whiledistanceis calculated from the transaction data with the old unit.Root Cause
When a user changes the distance rate for a track expense:
distanceUnitanddistanceRatefrom the transaction data for track expenses without a rateunitandratevariables instead ofdistanceUnitanddistanceRateThis causes a mismatch: the rate display uses one set of values while the distance display uses a different set, leading to the formatting inconsistency described in the bug (distance changes from "10.00 mi" to "10 mi").
The fix is simple: Line 432 should use
distanceUnitanddistanceRateinstead ofunitandratefor consistency with line 431.MelvinBot commentedon Mar 2, 2026
Proposal
Please re-state the problem that we are trying to solve in this issue.
After creating a manual distance expense with 10 miles in selfDM, the report header correctly shows "10.00 mi @ rate". However, when the user changes the rate to a different one, the distance format in the report header changes from "10.00 mi" to "10 mi" — losing the decimal places.
What is the root cause of that problem?
The root cause is a policy context mismatch between the optimistic update path and the rendering path, introduced by PR #74967.
During a rate change, the optimistic update in
getUpdatedTransaction()(TransactionUtils/index.ts:785-800) correctly computesmodifiedMerchantviagetDistanceMerchant(), which always formats with 2 decimal places usinggetRoundedDistanceInUnits()→toFixed(2). This works becausegetUpdatedTransactionreceives the correct workspacepolicyparameter.During rendering,
getMerchant()(TransactionUtils/index.ts:1134-1163) derives the policy fromgetPolicy(report?.policyID). For a selfDM expense, this returns the personal policy which has nocustomUnits. Becausepolicy?.customUnitsis falsy at line 1144,getMerchantdoes NOT recalculate the merchant with proper formatting — it falls through to returning the raw storedmodifiedMerchantormerchantfield at line 1162.PR #74967 also changed
getRate()(DistanceRequestUtils.ts:412-413) to returnundefinedfor unreported expenses when the rate isn't found in available mileage rates (instead of falling back todefaultMileageRate). Combined with track distance expenses now getting real policy rate IDs instead ofFAKE_P2P_ID,getMerchantcalled from display contexts can no longer resolve the rate to recalculate.The API call only sends
customUnitRateIDin the params (not the merchant — see line 5110 ofIOU/index.ts), so the server recalculates the merchant independently. If the server formats without preserving 2 decimal places (e.g. "10 mi" instead of "10.00 mi"), this overwrites the optimisticmodifiedMerchantwhen the response is merged back into Onyx.What changes do you think we should make in order to solve the problem?
The fix should ensure
getMerchant()inTransactionUtils/index.tscan properly recalculate the distance merchant for selfDM/unreported track expenses, rather than falling through to the raw stored value.Specifically, in
getMerchant()atTransactionUtils/index.ts:1143-1146, the condition should be expanded to also recalculate when the transaction is a distance request with amodifiedMerchant— even if the policy doesn't havecustomUnits. For selfDM distance expenses, theunitcan be derived fromgetDistanceUnit(which falls back to the transaction's stored unit), and theratefrom the mileage rate. The function already hasunitandrateresolved at lines 1140-1141 — it just needs to use them whenrateis available, regardless of whetherpolicy?.customUnitsis truthy.Alternatively, the
getRatecall insidegetMerchantcould be updated to also checkpolicyForMovingExpenses(the workspace policy associated with the expense) when the direct policy lookup fails for selfDM expenses.What alternative solutions did you explore? (Optional)
Including merchant in the API params: Modify
getUpdateTrackExpenseParamsto always include the correctly-formatted merchant when sending rate changes. However, this duplicates server-side logic and doesn't fix the rendering mismatch.Server-side fix: Ensure the server always formats distance with 2 decimal places. This would fix the symptom but not the underlying client-side issue where
getMerchantcan't recalculate for selfDM expenses.Next Steps for Contributor+ team: Reply with
@MelvinBot implement thisto create a draft PR, or@MelvinBot <your feedback>to refine this analysis.31 remaining items
FitseTLT commentedon Mar 4, 2026
What is the expected result? according to the OP the BE is setting the wrong value @cristipaval
cristipaval commentedon Mar 5, 2026
honestly, I would close this one. Thoughts @dylanexpensify @trjExpensify?
trjExpensify commentedon Mar 5, 2026
If this was a selfDM P2P thing I would probably say yes, but given that in FItsum's video the format changes when modifying the rate of an expense on an expense report - I think it would be worthwhile to address because it makes the product feel a bit janky.
cristipaval commentedon Mar 5, 2026
Thanks @trjExpensify. So, should we make the backend always return distances with 2 digits? Or what is the expected result?
trjExpensify commentedon Mar 5, 2026
Yeah, not killing the decimals when it's a round number seems to be what we're using everywhere else:
cristipaval commentedon Mar 5, 2026
Ok ok, thanks a lot! I'll fix the backend then!
melvin-bot commentedon Mar 9, 2026
@parasharrajat Eep! 4 days overdue now. Issues have feelings too...
cristipaval commentedon Mar 10, 2026
Backend PR is up and ready for review
cristipaval commentedon Mar 12, 2026
The backend fix has been deployed.