Skip to content

[Due for payment 2026-10-01] Web - Expense - Back button does not trigger discard change modal on Description #102010

Closed

Description

@applause-bot

If you haven’t already, check out our contributing guidelines for onboarding. To join our Slack channel, fill out this form.


Version Number: v9.4.92-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: https://test-management.browserstack.com/projects/2219752/test-runs/75291760/folder/57599980/41237150/1789798374?sort=%2Bidentifier
Email or phone of affected tester (no customers): leungbratt6+2009@gmail.com
Issue reported by: Applause Internal Team
Bug source: Exploratory - Significant User Experience Deterioration
Device used: Windows 10/Chrome
App Component: Chat Report View

Action Performed:

  1. Open the New Dot app
  2. Create an expense in Workspace chat
  3. Click on the expense - Description - enter something - click Back button on RHP

Expected Result:

Discard change modal appear

Actual Result:

Discard change modal does not appear
Same for the Merchant field.

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

Bug7266970_1790150951501.back_button.1.mp4

View all open jobs on GitHub

Applause Internal Information
Exported by: Julia Ponikarchuk
Bug ID: 7266970

Issue OwnerCurrent Issue Owner: @huult

Activity

  1. added
    DeployBlockerCash
    Bug
    on Sep 23, 2026
  2. applause-bot commented on Sep 23, 2026

    @applause-bot
    Author

    While Applause doesn't embed attachments for this bug, here are the links for quick view:
    https://platform.applause.com/services/links/v1/external/60c4390379caee66e87ef2e4d42ed1f91a0fe475012fa98cc2fac78c0efb06ab

  3. github-actions commented on Sep 23, 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.
  4. melvin-bot commented on Sep 23, 2026

    @melvin-bot

    Triggered auto assignment to @blimpich (DeployBlockerCash), see https://stackoverflowteams.com/c/expensify/questions/9980/ for more details.

  5. melvin-bot commented on Sep 23, 2026

    @melvin-bot

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

  6. MelvinBot commented on Sep 23, 2026

    @MelvinBot
    Contributor

    🔍 Investigation Summary

    Classification: Frontend bug
    Causing PR: #101180 - "Try it out button opens More features page of invited workspace as member" by @WojtekBoman (High confidence)
    Related Issues: none found

    Recommendation: REVERT

    goUp() now dispatches the same back action twice, and the second dispatch immediately closes the discard prompt the first one opened. Nothing merged on top of the files this PR touches, so it reverts cleanly, and the UX issue it fixed is far less severe than silently dropping a user's typed input.

    Assigned: @WojtekBoman (PR author), @Julesssss, @collectioneur, @huult (approving reviewers) from the highest-confidence causing PR only
    Labels: No changes. DeployBlockerCash is kept (an App PR caused it, so the App deploy stays blocked). DeployBlocker was not present, so nothing was removed.

    📋 Detailed Analysis

    Evidence

    • Staging-only, not reproducible on production, and v9.4.92-0 is the first build containing #101180 (merged 2026-09-22 17:55 UTC, position 60 in the chronological list on the deploy checklist).
    • Diffing production...staging shows the pages themselves (DynamicIOURequestStepDescription.tsx, DynamicIOURequestStepMerchant.tsx), the guard hook (useDiscardChangesConfirmation), useBeforeRemove, StepScreenWrapper and HeaderWithBackButton are all unchanged. The only changed file on the RHP back-button path is src/libs/Navigation/Navigation.ts, rewritten by this PR.
    • The RHP back button on these dynamic-route steps calls Navigation.goBack(backPath) with an explicit backTo (computed by useDynamicBackPath), which routes into goUp(). Plain RHP pages that call Navigation.goBack() with no backTo take the navigationRef.goBack() branch and are unaffected — which is exactly why this shows up on the migrated dynamic steps (Description, Merchant, and by the same mechanism Date/Category/etc.) rather than everywhere.

    Verification

    Affected files:

    gh pr view 101180 --json files confirms the PR modifies src/libs/Navigation/Navigation.ts, src/libs/Navigation/helpers/linkTo/getMinimalAction.ts, src/libs/Navigation/helpers/linkTo/index.ts and adds src/libs/Navigation/helpers/hasDifferentSplitScope.ts. git log f04c5569b0e..staging on those paths is empty — no follow-up commits depend on it.

    Note: this analysis is code, git-history and static-analysis only. Browser control was unavailable in this run, so the reproduction was not re-run interactively.

    Root Cause

    On the Description step the state is root: [TabNavigator, RightModalNavigator] with index: 1, and the back path is r/<reportID>, which resolves to the TabNavigator route at root index 0.

    Before this PR, goUp() resolved the target once and dispatched exactly one action: StackActions.pop(1) targeted at the root stack.

    After this PR, goUp() runs in two phases:

    1. getPopsToNavigatorWithBackToRoute() walks from the root, finds the TabNavigator route at index 0 with distanceToPop = 1, and dispatches StackActions.pop(1) targeted at the root key.
    2. It then re-reads the root state — the comment says "dispatch updates the state ref synchronously, and this must resolve against what the pops left" — and resolves the target again.

    Phase 2 assumes phase 1 was applied. That holds on the happy path (after the pop, distanceToPop becomes 0 and the distanceToPop <= 0 early return fires). It does not hold when a screen guards the transition: useDiscardChangesConfirmation calls e.preventDefault() in its beforeRemove listener, so the root state is unchanged, phase 2 recomputes the identical distanceToPop = 1, and dispatches a second StackActions.pop(1).

    That second dispatch re-enters the same beforeRemove listener, and this time isDiscardModalOpen.current is already true, so it takes the branch that treats the event as a back-press over an already-open prompt and calls closeModal(). Because both showModal and closeModal are functional setModalStack updaters queued in the same React batch, the prompt is pushed and popped before it ever renders. Net result: navigation stays blocked (the user remains in the field) and no modal is ever painted — precisely the reported symptom, for Description, Merchant, and any other guarded step that passes an explicit backTo.

    If a roll-forward is preferred over a revert, the minimal fix is to make phase 2 a no-op when phase 1 did not actually change anything — e.g. snapshot the root state before the pops and bail out (return didPopToNavigator) when getRootState() comes back identical, which means the action was prevented.

    💡 Suggested AI code review rule

    This bug looks like a recurring, mechanically detectable pattern, so it may be worth a coding-standards rule so the AI reviewer catches the next one. Proposed for Expensify/App:

    • Rule: CONSISTENCY-18 Do not assume a dispatched navigation action was applied
    • Condition: Flag code that dispatches a navigation action and then re-reads getRootState() / navigationRef.current.getState() to compute and dispatch a follow-up action. A screen's beforeRemove listener can call preventDefault(), leaving the state untouched, so the follow-up re-issues the same action and re-enters the guard. Snapshot the state before dispatching and bail out when it is unchanged, or derive every action from a single state read.
    • Why: goUp() dispatched the same root StackActions.pop(1) twice when the discard-changes guard blocked the first one; the second entry into beforeRemove closed the prompt it had just opened, so Back did nothing and the user got no discard prompt (#102010).
    • Search pattern: rg -U 'dispatch\([\s\S]{0,600}?getRootState\(\)' src/libs/Navigation — any function body containing a dispatch( call followed by a getRootState() read.
    • Offending code (❌): Navigation.ts#L539-L547 plus the follow-up dispatch at Navigation.ts#L604
    • Fix (✅): the pre-PR single-dispatch shape in Navigation.ts on production

    The full rule file, with the ❌/✅ code inline in Expensify/App's app-coding-standards format, would go in Expensify/App itself. If it's worth adding, a maintainer can open it there as a draft PR.

  7. 3 remaining items

  8. WojtekBoman commented on Sep 23, 2026

    @WojtekBoman
    Contributor

    I prepared a draft PR including the adjustment to the original solution @huult @KJ21-ENG Could you take a look please?

  9. added
    Reviewing
    on Sep 23, 2026
  10. blimpich commented on Sep 23, 2026

    @blimpich
    Contributor

    Going to unassign my self since @Julesssss is already assigned and has context from this PR

  11. removed their assignment
    on Sep 23, 2026
  12. Julesssss commented on Sep 23, 2026

    @Julesssss
    Contributor

    PR merged and being deployed

  13. Julesssss commented on Sep 23, 2026

    @Julesssss
    Contributor

    PR Requested QA retest here. QA retest

  14. m-natarajan commented on Sep 23, 2026

    @m-natarajan

    Chrome / v9.4.92-5, Passed

    bandicam.2026-09-23.20-31-44-758.mp4
  15. removed
    DeployBlockerCash
    on Sep 24, 2026
  16. added
    Daily
    and removed
    Reviewing
    Hourly
    on Sep 24, 2026
  17. changed the title [-]Web - Expense - Back button does not trigger discard change modal on Description[/-] [+][Due for payment 2026-10-01] Web - Expense - Back button does not trigger discard change modal on Description[/+] on Sep 24, 2026
  18. melvin-bot commented on Sep 24, 2026

    @melvin-bot

    @huult

    The solution for this issue has been 🚀 deployed to production 🚀 in version 9.4.92-8 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

    If no regressions arise, payment will be issued on 2026-10-01. 🎊

    The following checklist (instructions) will need to be completed before the issue can be closed. Please copy/paste the Contributor+ Checklist from here into a new comment on this GH and complete it. If you have the K2 extension, you can simply click: [this button]. If no checklist is needed for this issue, you can click: [no checklist button]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugDailyEngineering

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions