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
[$175] [CFI] Show the "Discard changes?" modal when exiting the Create expense flow with unsaved edits #104579
When you create an expense, it's easy to lose your work. For example, you add a receipt and start coding the expense on the confirmation page. Then you click outside the RHP or navigate away. The draft disappears with no warning. Classic keeps the draft open until you close it on purpose, so migrating customers notice this.
Solution
If you've made edits anywhere in the Create expense flow and try to leave, show the existing "Discard changes?" modal. Leaving includes clicking outside the RHP, pressing back or Esc, swiping back, or switching tabs.
Use the existing useDiscardChangesConfirmation hook. It already runs on these steps:
changed the title [-]Show the "Discard changes?" modal when exiting the Create expense flow with unsaved edits[/-][+][CFI] Show the "Discard changes?" modal when exiting the Create expense flow with unsaved edits[/+]on Oct 21, 2026
Neither IOURequestStepConfirmation nor IOURequestStepScan calls useDiscardChangesConfirmation, so nothing blocks the RHP from closing. The confirmation page also writes every edit straight to the draft transaction in Onyx. There's no local "dirty" state to compare against, and auto-fill components (category defaults, tax, distance merchant) write to the same draft.
Two limits in the hook also matter once it's added to the confirmation page:
On web it blocks every removal of the screen, so header back to an earlier step would also prompt, even though nothing is lost.
It only prompts on the focused screen. If a sub-step (category, tag, date) sits on top of confirmation and you click outside the RHP, nothing prompts.
What changes do you think we should make in order to solve the problem?
Add shouldPromptForNavigationAction(action) so only actions that close the flow prompt. That covers the overlay click, Esc (DISMISS_MODAL), and a browser back or swipe that leaves the RHP. A pop to an earlier step doesn't prompt.
Add shouldPromptWhenUnfocused so confirmation still prompts when a sub-step is on top.
On Discard, close the flow with Navigation.closeRHPFlow() instead of re-dispatching the blocked action. The overlay sends a GO_BACK without a target, and re-dispatching it would likely pop just one screen and leave the RHP open.
Track real edits on the draft. Add a hasUserEdits flag to the draft transaction. Set it only from user-driven handlers: the inline fields, sub-step save handlers, billable/reimbursable toggles, and receipt replace or drop. Never set it from the auto-fill setters.
onConfirm (Discard): clear the drafts with clearMoneyRequest(OPTIMISTIC_TRANSACTION_ID, [OPTIMISTIC_TRANSACTION_ID, ...draftTransactionIDs]) after the RHP closes, so the page doesn't flash empty.
Call suppressDiscardPrompt() before onConfirm, onSendMoney, and "Remove expense", so submitting never prompts.
Scan step: single scan goes straight to confirmation, so step 3 covers it. Add the hook to ScanGlobalCreate for multi-scan, where receipts pile up on Scan itself. Use "multi-scan is on and any draft has a receipt" as the dirty check, and pass onTabSwitchDiscard so switching tabs prompts too. Also prompt when you're back on Scan with a receipt still attached and close the RHP.
Tests: unit tests for the action filter and the unfocused prompt. UI tests for the issue's steps: Discard closes the flow and clears the draft, Cancel keeps your edits, and no edits means no modal.
Not verified at runtime: that overlay click followed by Discard on a two-screen stack pops one screen instead of closing the RHP. This comes from reading the code (StackRouter turns an untargeted GO_BACK into a POP when the stack has more than one screen).
What alternative solutions did you explore? (Optional)
One guard on the money request navigator that checks the draft. This covers every step and sub-step in one place, but it duplicates the per-step hook and makes tab switching and submit suppression harder.
Snapshot the draft on mount and compare. This was rejected because auto-fill setters write to the draft and would trigger false prompts.
Next Steps for Contributor+ team: To accept:@MelvinBot implement [this](https://github.com/Expensify/App/issues/104579) to create a draft PR. To refine:@MelvinBot <your feedback> To reject: Explain why you are rejecting Melvin's proposal.
changed the title [-][CFI] Show the "Discard changes?" modal when exiting the Create expense flow with unsaved edits[/-][+][$175] [CFI] Show the "Discard changes?" modal when exiting the Create expense flow with unsaved edits[/+]on Oct 26, 2026
Activity
[-]Show the "Discard changes?" modal when exiting the Create expense flow with unsaved edits[/-][+][CFI] Show the "Discard changes?" modal when exiting the Create expense flow with unsaved edits[/+]trjExpensify commentedon Oct 21, 2026
@MelvinBot proposal a solution to this.
MelvinBot commentedon Oct 21, 2026
Proposal
What is the root cause of that problem?
Neither
IOURequestStepConfirmationnorIOURequestStepScancallsuseDiscardChangesConfirmation, so nothing blocks the RHP from closing. The confirmation page also writes every edit straight to the draft transaction in Onyx. There's no local "dirty" state to compare against, and auto-fill components (category defaults, tax, distance merchant) write to the same draft.Two limits in the hook also matter once it's added to the confirmation page:
What changes do you think we should make in order to solve the problem?
shouldPromptForNavigationAction(action)so only actions that close the flow prompt. That covers the overlay click, Esc (DISMISS_MODAL), and a browser back or swipe that leaves the RHP. A pop to an earlier step doesn't prompt.shouldPromptWhenUnfocusedso confirmation still prompts when a sub-step is on top.Navigation.closeRHPFlow()instead of re-dispatching the blocked action. The overlay sends aGO_BACKwithout a target, and re-dispatching it would likely pop just one screen and leave the RHP open.hasUserEditsflag to the draft transaction. Set it only from user-driven handlers: the inline fields, sub-step save handlers, billable/reimbursable toggles, and receipt replace or drop. Never set it from the auto-fill setters.getHasUnsavedChanges:hasReceipt(transaction) || transaction.hasUserEditsonConfirm(Discard): clear the drafts withclearMoneyRequest(OPTIMISTIC_TRANSACTION_ID, [OPTIMISTIC_TRANSACTION_ID, ...draftTransactionIDs])after the RHP closes, so the page doesn't flash empty.suppressDiscardPrompt()beforeonConfirm,onSendMoney, and "Remove expense", so submitting never prompts.ScanGlobalCreatefor multi-scan, where receipts pile up on Scan itself. Use "multi-scan is on and any draft has a receipt" as the dirty check, and passonTabSwitchDiscardso switching tabs prompts too. Also prompt when you're back on Scan with a receipt still attached and close the RHP.Code references
navigation.goBack(): RightModalNavigator.tsx:240-258beforeRemoveand replays throughnavigationRef: useDiscardChangesConfirmation/index.ts:55-133startMoneyRequestdoes: MoneyRequest.ts:498-530. Clear pattern: IOURequestRedirectToStartPage.tsx:49hasReceipt: TransactionUtils/index.ts:404Not verified at runtime: that overlay click followed by Discard on a two-screen stack pops one screen instead of closing the RHP. This comes from reading the code (
StackRouterturns an untargetedGO_BACKinto aPOPwhen the stack has more than one screen).Related work: Fix discard modal in embedded manual is open and adds
shouldPromptForNavigationAction,shouldPromptWhenUnfocused, and thesuppressDiscardPromptwrapping ofonConfirm/onSendMoneyfor the embedded Manual confirmation. Land it first, or coordinate with its author, to avoid conflicts. The hook was first added to IOU steps in fix: Show discard changes modal on browser/device back in money-request flows.What alternative solutions did you explore? (Optional)
Next Steps for Contributor+ team:
To accept:
@MelvinBot implement [this](https://github.com/Expensify/App/issues/104579)to create a draft PR.To refine:
@MelvinBot <your feedback>To reject: Explain why you are rejecting Melvin's proposal.
view run
melvin-bot commentedon Oct 26, 2026
Triggered auto assignment to Contributor-plus team member for initial proposal review - @gijoe0295 (
External)[-][CFI] Show the "Discard changes?" modal when exiting the Create expense flow with unsaved edits[/-][+][$175] [CFI] Show the "Discard changes?" modal when exiting the Create expense flow with unsaved edits[/+]melvin-bot commentedon Oct 26, 2026
Job added to Upwork: https://www.upwork.com/jobs/~022114743789071202645
trjExpensify commentedon Oct 26, 2026
@gijoe0295 can you review Melvin's proposal and progress a PR today please? Thanks!
7 remaining items
melvin-bot commentedon Nov 4, 2026
@gijoe0295 Eep! 4 days overdue now. Issues have feelings too...
gijoe0295 commentedon Nov 4, 2026
@trjExpensify I'm trying to simplify the PR (~1.6k changes now) by re-evaluating the scope. Need your input.
When should the modal show?
I wonder if Option 1 works so we can reduce ~60% changes and avoid regressions.
Which flows should this apply?
The PR currently covers:
Anything to omit?
trjExpensify commentedon Nov 4, 2026
Ah, the Per diem flow is being refactored here, you could wait and follow-up once that PR lands?
jeffrey-graham commentedon Nov 7, 2026
melvin-bot commentedon Nov 7, 2026
gijoe0295 commentedon Nov 16, 2026
Split PRs plan
Ship by guards & pages to apply.
hasUserEditsdraft flag that tells the user's input apart from default values we automatically fill in. Detect user edits in create expense drafts #106978useDiscardChangesConfirmation: The guard currently only applies to the focused screen, a multi-step flow won't trigger the guard if other steps are open on top. We need to keep a screen's guard active while later steps cover it. [HOLD 106972] Let the first screen of a flow guard the whole flow inuseDiscardChangesConfirmation#106977. Depends on 1.