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
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:#78291 Email or phone of affected tester (no customers):applausetester+sd2d2d@applause.expensifail.com (you) 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:
Log in with Expensifail account.
Go to staging.new.expensify.com
Go to workspace chat.
Click + > Track distance > Odometer.
Enter Start and End reading > Next.
Click Create expense.
Expected Result:
Discard changes modal will not open.
Actual Result:
Discard changes modal opens after creating Odometer expense.
On iOS app, confirm page becomes blank. Swiping back reveals Discard changes modal.
👋 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: #78291 - "Migrate useBeforeRemove to usePreventRemove in DiscardChangesConfirmation" by @mkzie2 (High confidence) Related Issues: None
Recommendation: REVERT
This PR introduced a regression in the odometer distance flow. The migration from useBeforeRemove to usePreventRemove changed how the "unsaved changes" state is tracked, and the new implementation fails to reset the baseline state after successfully creating an expense.
Labels: Keeping DeployBlockerCash - this is a frontend bug that blocks the App deploy. No label changes needed.
📋 Detailed Analysis
Evidence
PR #78291 modified the IOURequestStepDistanceOdometer.tsx file and changed how "unsaved changes" are detected for the DiscardChangesConfirmation component.
The issue is reproducible only on staging (where PR #78291 was deployed) and not on production (where it has not yet been deployed), which confirms this PR as the cause.
Verification
The affected file is /home/runner/_work/App/App/src/pages/iou/request/step/IOURequestStepDistanceOdometer.tsx, which was modified by PR #78291.
Looking at the PR diff, the following changes were made:
Changed DiscardChangesConfirmation prop from getHasUnsavedChanges (callback function) to hasUnsavedChanges (computed boolean)
Replaced refs for tracking initial values with state: const [initialReadings, setInitialReadings] = useState<{start: string; end: string}>({start: "", end: ""})
Added a useMemo to compute hasUnsavedChanges by comparing current readings with initialReadings
Root Cause
The bug occurs because of a state management flaw in the new implementation:
Lines 166-184: The initialReadings state is initialized ONCE on mount and never updated again:
useEffect(()=>{if(hasInitializedRefs.current){return;// Early return prevents re-initialization}// ... sets initialReadings ...hasInitializedRefs.current=true;},[...]);
Lines 354-497: When the user creates an expense via navigateToNextPage():
The transaction is updated with the new odometer readings via setMoneyRequestOdometerReading()
However, the initialReadings state is NEVER updated to reflect this save
The component continues to exist (navigation has not completed yet)
Lines 500-505: The hasUnsavedChanges computed value:
This still compares against the stale initialReadings from mount time, not the newly saved values. Therefore hasUnsavedChanges remains true even after successfully saving.
Result: The DiscardChangesConfirmation with usePreventRemove triggers the discard modal because it thinks there are still unsaved changes, even though the expense was just saved.
The old implementation using useBeforeRemove with a callback function getHasUnsavedChanges() would have checked the refs dynamically and avoided this issue, but the new state-based approach fails to update the baseline after save.
Please re-state the problem that we are trying to solve in this issue.
After creating an Odometer expense (Track distance > Odometer) in a workspace chat, a "Discard changes" modal incorrectly appears. On iOS, the confirm page becomes blank and swiping back reveals the Discard changes modal. This was introduced by PR #78291 which migrated DiscardChangesConfirmation from useBeforeRemove to usePreventRemove.
What is the root cause of that problem?
PR #78291 changed DiscardChangesConfirmation from accepting a getHasUnsavedChanges callback (evaluated lazily on navigation) to a reactive hasUnsavedChanges boolean prop. The IOURequestStepDescription and IOURequestStepMerchant components were updated to use useState for this flag and explicitly call setHasUnsavedChanges(false) at the top of their submit handlers before any navigation occurs. However, IOURequestStepDistanceOdometer computes hasUnsavedChanges as a useMemo derived value that compares current readings against initial readings — and never resets it during submission.
When the user enters odometer readings and submits, navigateToNextPage() stores the data in Onyx and triggers navigation, but hasUnsavedChanges remains true because startReading/endReading still differ from initialReadings (which are empty strings for a new expense).
On web, the transitionStart listener in DiscardChangesConfirmation/index.tsx fires for all navigation transitions (forward and backward). It sees the stale hasUnsavedChanges=true, calls window.history.go(1) to undo the navigation, and shows the discard modal.
On native, usePreventRemove(hasUnsavedChanges, ...) blocks the screen removal because hasUnsavedChanges is still true when the navigation stack tries to remove the odometer screen.
The only path that handles this is shouldSkipConfirmation, which calls setShouldEnableDiscardConfirmation(false) — but the normal creation flow does not.
Relevant code:
src/pages/iou/request/step/IOURequestStepDistanceOdometer.tsx — hasUnsavedChanges computed at ~line 500, navigateToNextPage at ~line 354 never resets it
src/pages/iou/request/step/DiscardChangesConfirmation/index.tsx — transitionStart listener at ~line 35 triggers the modal on forward navigation
src/pages/iou/request/step/IOURequestStepMerchant.tsx:107 and IOURequestStepDescription.tsx:138 — both correctly call setHasUnsavedChanges(false) at the start of their submit handlers
What changes do you think we should make in order to solve the problem?
In IOURequestStepDistanceOdometer.tsx, call setShouldEnableDiscardConfirmation(false) at the top of navigateToNextPage() for all submission paths (not just the shouldSkipConfirmation branch). This mirrors the pattern used by Description and Merchant components and ensures hasUnsavedChanges evaluates to false before any navigation is triggered.
Move the existing setShouldEnableDiscardConfirmation(false) call (currently inside if (shouldSkipConfirmation) at ~line 422) to the beginning of navigateToNextPage() so it runs unconditionally.
What alternative solutions did you explore? (Optional)
Reset initialReadings to match current readings — calling setInitialReadings({start: startReading, end: endReading}) would make the useMemo evaluate to false. However, this is semantically misleading (initial readings haven't changed) and adds unnecessary state coupling.
Convert to explicit useState for hasUnsavedChanges like Description/Merchant — this would work but requires a larger refactor of the Odometer component. Using the existing shouldEnableDiscardConfirmation state is simpler and already part of the hasUnsavedChanges computation.
Next Steps for Contributor+ team: Reply with @MelvinBot implement this to create a draft PR, or @MelvinBot <your feedback> to refine this analysis.
Activity
melvin-bot commentedon Mar 4, 2026
You have been assigned to this deploy blocker because you recently merged this PR: #78291
melvin-bot commentedon Mar 4, 2026
💬 A slack conversation has been started in #expensify-open-source
melvin-bot commentedon Mar 4, 2026
Triggered auto assignment to @NicMendonca (
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 4, 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 4, 2026
🔍 Investigation Summary
Classification: Frontend bug
Causing PR: #78291 - "Migrate
useBeforeRemovetousePreventRemoveinDiscardChangesConfirmation" by @mkzie2 (High confidence)Related Issues: None
Recommendation: REVERT
This PR introduced a regression in the odometer distance flow. The migration from
useBeforeRemovetousePreventRemovechanged how the "unsaved changes" state is tracked, and the new implementation fails to reset the baseline state after successfully creating an expense.Labels: Keeping
DeployBlockerCash- this is a frontend bug that blocks the App deploy. No label changes needed.📋 Detailed Analysis
Evidence
PR #78291 modified the
IOURequestStepDistanceOdometer.tsxfile and changed how "unsaved changes" are detected for theDiscardChangesConfirmationcomponent.The issue is reproducible only on staging (where PR #78291 was deployed) and not on production (where it has not yet been deployed), which confirms this PR as the cause.
Verification
The affected file is
/home/runner/_work/App/App/src/pages/iou/request/step/IOURequestStepDistanceOdometer.tsx, which was modified by PR #78291.Looking at the PR diff, the following changes were made:
DiscardChangesConfirmationprop fromgetHasUnsavedChanges(callback function) tohasUnsavedChanges(computed boolean)const [initialReadings, setInitialReadings] = useState<{start: string; end: string}>({start: "", end: ""})useMemoto computehasUnsavedChangesby comparing current readings withinitialReadingsRoot Cause
The bug occurs because of a state management flaw in the new implementation:
Lines 166-184: The
initialReadingsstate is initialized ONCE on mount and never updated again:Lines 354-497: When the user creates an expense via
navigateToNextPage():setMoneyRequestOdometerReading()initialReadingsstate is NEVER updated to reflect this saveLines 500-505: The
hasUnsavedChangescomputed value:This still compares against the stale
initialReadingsfrom mount time, not the newly saved values. ThereforehasUnsavedChangesremainstrueeven after successfully saving.Result: The
DiscardChangesConfirmationwithusePreventRemovetriggers the discard modal because it thinks there are still unsaved changes, even though the expense was just saved.The old implementation using
useBeforeRemovewith a callback functiongetHasUnsavedChanges()would have checked the refs dynamically and avoided this issue, but the new state-based approach fails to update the baseline after save.MelvinBot commentedon Mar 4, 2026
Proposal
Please re-state the problem that we are trying to solve in this issue.
After creating an Odometer expense (Track distance > Odometer) in a workspace chat, a "Discard changes" modal incorrectly appears. On iOS, the confirm page becomes blank and swiping back reveals the Discard changes modal. This was introduced by PR #78291 which migrated
DiscardChangesConfirmationfromuseBeforeRemovetousePreventRemove.What is the root cause of that problem?
PR #78291 changed
DiscardChangesConfirmationfrom accepting agetHasUnsavedChangescallback (evaluated lazily on navigation) to a reactivehasUnsavedChangesboolean prop. TheIOURequestStepDescriptionandIOURequestStepMerchantcomponents were updated to useuseStatefor this flag and explicitly callsetHasUnsavedChanges(false)at the top of their submit handlers before any navigation occurs. However,IOURequestStepDistanceOdometercomputeshasUnsavedChangesas auseMemoderived value that compares current readings against initial readings — and never resets it during submission.When the user enters odometer readings and submits,
navigateToNextPage()stores the data in Onyx and triggers navigation, buthasUnsavedChangesremainstruebecausestartReading/endReadingstill differ frominitialReadings(which are empty strings for a new expense).On web, the
transitionStartlistener inDiscardChangesConfirmation/index.tsxfires for all navigation transitions (forward and backward). It sees the stalehasUnsavedChanges=true, callswindow.history.go(1)to undo the navigation, and shows the discard modal.On native,
usePreventRemove(hasUnsavedChanges, ...)blocks the screen removal becausehasUnsavedChangesis stilltruewhen the navigation stack tries to remove the odometer screen.The only path that handles this is
shouldSkipConfirmation, which callssetShouldEnableDiscardConfirmation(false)— but the normal creation flow does not.Relevant code:
src/pages/iou/request/step/IOURequestStepDistanceOdometer.tsx—hasUnsavedChangescomputed at ~line 500,navigateToNextPageat ~line 354 never resets itsrc/pages/iou/request/step/DiscardChangesConfirmation/index.tsx—transitionStartlistener at ~line 35 triggers the modal on forward navigationsrc/pages/iou/request/step/IOURequestStepMerchant.tsx:107andIOURequestStepDescription.tsx:138— both correctly callsetHasUnsavedChanges(false)at the start of their submit handlersWhat changes do you think we should make in order to solve the problem?
In
IOURequestStepDistanceOdometer.tsx, callsetShouldEnableDiscardConfirmation(false)at the top ofnavigateToNextPage()for all submission paths (not just theshouldSkipConfirmationbranch). This mirrors the pattern used by Description and Merchant components and ensureshasUnsavedChangesevaluates tofalsebefore any navigation is triggered.Move the existing
setShouldEnableDiscardConfirmation(false)call (currently insideif (shouldSkipConfirmation)at ~line 422) to the beginning ofnavigateToNextPage()so it runs unconditionally.What alternative solutions did you explore? (Optional)
Reset
initialReadingsto match current readings — callingsetInitialReadings({start: startReading, end: endReading})would make theuseMemoevaluate tofalse. However, this is semantically misleading (initial readings haven't changed) and adds unnecessary state coupling.Convert to explicit
useStateforhasUnsavedChangeslike Description/Merchant — this would work but requires a larger refactor of the Odometer component. Using the existingshouldEnableDiscardConfirmationstate is simpler and already part of thehasUnsavedChangescomputation.Next Steps for Contributor+ team: Reply with
@MelvinBot implement thisto create a draft PR, or@MelvinBot <your feedback>to refine this analysis.1 remaining item
Julesssss commentedon Mar 5, 2026
Not a blocker, Odometer feature behind beta.
DylanDylann commentedon Mar 5, 2026
@MelvinBot Implement this
MelvinBot commentedon Mar 5, 2026
🤖 Draft PR created: #84255
Please mark it as "Ready for review" when it is ready for review.
DylanDylann commentedon Mar 5, 2026
Discussing the next step here
Julesssss commentedon Mar 5, 2026
We reverted the discard modal bug here.
Julesssss commentedon Mar 12, 2026
Fixed here