Skip to content

[Due for payment 2026-06-30] [$250] iOS mWeb - Date picker stays open after navigating forward/backward #91311

Closed

Description

@arosiclair

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: TBD
Reproducible in staging?: Yes
Reproducible in production?: Yes
If this was caught during regression testing, add the test name, ID and link from BrowserStack: N/A
Email or phone of affected tester (no customers): N/A
Issue reported by: @arosiclair
Bug source: PR testing
Device used: iOS Safari
App Component: User Settings

Action Performed:

  1. Go to staging.expensify.com
  2. Go to Wallet
  3. Click Add bank account
  4. On the Bank Purpose Page choose Make Payments
  5. Choose United States
  6. Go through the flow until confirmation page
  7. Click browser back button to go back to date of birth step
  8. Click browser forward button a few times

Expected Result:

The date picker closes as the next step does not require it.

Actual Result:

The date picker is stuck on screen until clicked.
Same behavior for the date picker in company incorporation date.

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

Screen.Recording.2026-05-19.at.23.17.03.mov

View all open jobs on GitHub

Upwork Automation - Do Not Edit
Issue OwnerCurrent Issue Owner: @mallenexpensify

Activity

  1. self-assigned this
    on May 21, 2026
  2. changed the title [-][HOLD] iOS mWeb - Date picker stays open after navigating forward/backward[/-] [+]iOS mWeb - Date picker stays open after navigating forward/backward[/+] on Jun 1, 2026
  3. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Jun 1, 2026
  4. MelvinBot commented on Jun 1, 2026

    @MelvinBot
    Contributor

    Proposal

    ℹ️ Confidence: Medium — strong code-level evidence for the mechanism below, but the iOS-Safari–specific timing has not been reproduced in a runtime trace. Treat the fix direction as a starting point.

    What is the root cause of that problem?

    The calendar opens through a deferred auto-focus that is decoupled from navigation, and the only auto-close path bails out when the calendar isn't visible yet. So a fast forward/back can leave the calendar opening after you've already navigated to the next sub-step, with nothing left to close it.

    The bank-account sub-steps are React Navigation routes (the subPage param), so the browser back/forward buttons move between them (useSubPage/index.tsx:39-41). The Date-of-Birth sub-step renders the DatePicker with autoFocus (DateOfBirthStep.tsx:99-107), and focusing the field is what opens the calendar (onFocus={showDatePickerModal}, DatePicker/index.tsx:157).

    That focus is deferred — it waits for the screen transition (transitionEnd, or a 1000 ms fallback) and then InteractionManager + isWindowReadyToFocus() before calling input.focus() (useAutoFocusInput.ts:69-126, CONST/index.ts:293).

    The calendar's only browser-navigation close is the Popover popstate listener, which early-returns when the modal isn't visible (Popover/index.tsx:55-74):

    const listener = () => {
        if (!isVisible) { return; }   // <-- bails if the calendar hasn't opened yet
        ...
        onClose?.();
    };

    So in the failing sequence: back → DOB (auto-focus scheduled, calendar not yet visible) → forward (popstate fires, but isVisible is still false, so nothing closes) → the deferred focus then opens the calendar, now stranded on a step that doesn't use it. iOS mWeb Safari is where this reproduces because its slower screen transitions widen the gap between navigation and the deferred open; on desktop the calendar is already visible when popstate fires, so it closes correctly.

    Alternative explanations considered (and ruled out)
    • The internal-popstate guard wrongly suppressing the close — ruled out. The guard (isInternalPopstateInProgress) is only set by withInternalPopstate, which runs only when a modal opts into shouldHandleNavigationBack. DatePickerModal never passes that prop, so the guard is never armed for the calendar.
    • A deterministic logic bug in the popstate handler — ruled out by the platform signature. A pure logic bug would also reproduce on desktop Chrome; this is iOS mWeb Safari only, which points to a timing race, not a static logic error.
    • "Auto-focus reopens on every visit to DOB" — that's expected behavior on the DOB step; the report is specifically that the calendar persists on a step that does not use it, which only the deferred-open race explains.

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

    Make the calendar's open state follow the navigation, so it can't open (or linger) after the user leaves the step. Two complementary guards in DatePicker/index.tsx:

    1. Cancel/suppress the pending open and close the calendar when the field's screen blurs or the DatePicker unmounts. A useFocusEffect cleanup (and/or an unmount effect) that calls cancelAutoFocus() and setIsModalVisible(false) prevents the deferred input.focus() from opening a calendar after navigation has moved on.
    2. Don't open if the screen is no longer focused. Guard showDatePickerModal so a late-firing focus is a no-op when the screen/sub-step is no longer the active one.

    This keeps the fix scoped to the DatePicker rather than weakening the shared Popover popstate logic. Verification should be a manual iOS mWeb Safari repro of the exact back→forward sequence, since the race is platform-timing-dependent.

    What alternative solutions did you explore? (Optional)

    Closing the calendar from the Popover side regardless of isVisible (e.g., always running onClose on popstate) — rejected as too broad: it changes shared behavior for every Popover consumer and still wouldn't stop the deferred auto-focus from re-opening the calendar a moment later.


    Next Steps for Contributor+ team:
    To accept: @MelvinBot implement [this](https://github.com/Expensify/App/issues/91311) to create a draft PR.
    To refine: @MelvinBot <your feedback>
    To reject: Explain why you are rejecting Melvin's proposal.

  5. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Jun 1, 2026
  6. added
    Help WantedApply this label when an issue is open to proposals by contributors
    and removed on Jun 1, 2026
  7. wildan-m commented on Jun 1, 2026

    @wildan-m
    Contributor

    🚨 Edited by proposal-police: This proposal was edited at 2026-06-01 16:35:45 UTC.

    Proposal

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

    On iOS mWeb Safari, the date picker calendar in the Add bank account flow (the date of birth step and the company incorporation date step) stays open on screen after the user navigates with the browser back and then forward buttons. The calendar should dismiss when navigation lands on a step that no longer needs it, but instead it remains stuck on screen until the user taps it.

    What is the root cause of that problem?

    The date picker calendar opens through DatePickerModal, which renders a PopoverWithMeasuredContent:

    return (
    <PopoverWithMeasuredContent
    anchorRef={anchorRef}
    isVisible={isVisible}
    onClose={onClose}
    anchorPosition={anchorPosition}
    popoverDimensions={popoverDimensions}
    shouldCloseWhenBrowserNavigationChanged={shouldCloseWhenBrowserNavigationChanged}

    PopoverWithMeasuredContent is responsive: on small screen widths (which includes iOS mWeb Safari) it does not render a Popover at all — it returns a bottom-docked Modal early:

    if (isSmallScreenWidth) {
    return (
    <Modal
    {...props}
    type={CONST.MODAL.MODAL_TYPE.BOTTOM_DOCKED}
    animationIn="slideInUp"
    animationOut="slideOutDown"
    shouldWrapModalChildrenInScrollViewIfBottomDockedInLandscapeMode={shouldWrapModalChildrenInScrollViewIfBottomDockedInLandscapeMode}
    />
    );
    }

    This matters because the two render targets close on browser navigation through different mechanisms. The Popover (wide-screen) path closes via its own popstate listener, which is gated on shouldCloseWhenBrowserNavigationChanged. The Modal (small-screen) path is different: it only attaches a popstate listener when shouldHandleNavigationBack is set, and it ignores shouldCloseWhenBrowserNavigationChanged entirely:

    const showModal = () => {
    if (shouldHandleNavigationBack) {
    // Preserve React Navigation's state in the guard entry so that if
    // popstate fires for this entry, RN recognizes the current route
    // and does not perform an unexpected back navigation.
    const currentState = (window.history.state ?? {}) as WindowState;
    window.history.pushState({...currentState, shouldGoBack: true}, '', null);
    window.addEventListener('popstate', handlePopState);
    }
    onModalShow?.();
    };

    DatePickerModal forwards shouldCloseWhenBrowserNavigationChanged but never sets shouldHandleNavigationBack. So on iOS mWeb the calendar is a Modal with no popstate listener attached: pressing the browser back/forward buttons fires no handler, onClose is never called, and the calendar stays stuck on screen. The same DatePicker/DatePickerModal path backs both the date of birth field and the company incorporation date field, which is why both reproduce.

    Note that the calendar's own sub-pickers already do the right thing: MonthPickerModal and YearPickerModal render their Modal with shouldHandleNavigationBack, so they dismiss correctly on browser navigation:

    return (
    <Modal
    type={CONST.MODAL.MODAL_TYPE.RIGHT_DOCKED}
    isVisible={isVisible}
    onClose={() => onClose?.()}
    onModalHide={onClose}
    shouldHandleNavigationBack
    shouldUseCustomBackdrop
    onBackdropPress={onClose}
    shouldKeepRightDockedBackdropInNarrowPane={shouldEnableBackdropInNarrowPane}
    enableEdgeToEdgeBottomSafeAreaPadding

    Only the top-level date picker calendar omits it. (A recent change wired the wide-screen Popover path by passing shouldCloseWhenBrowserNavigationChanged from DatePicker, but that prop has no effect on the small-screen Modal path, so the iOS mWeb case remained broken.)

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

    Make the small-screen Modal honor browser back/forward the same way the wide-screen Popover already does. In DatePickerModal, pass shouldHandleNavigationBack to PopoverWithMeasuredContent, scoped to small screens and derived from the existing browser-navigation-close intent:

    shouldHandleNavigationBack={isSmallScreenWidth && shouldCloseWhenBrowserNavigationChanged}

    isSmallScreenWidth is already available in DatePickerModal. With this in place, on iOS mWeb the bottom-docked Modal registers its popstate listener (per Modal's showModal), so pressing browser back/forward fires the handler and calls onClose, which sets the picker invisible and dismisses the calendar. This mirrors what MonthPickerModal/YearPickerModal already do with shouldHandleNavigationBack, and it fixes both the date of birth and company incorporation date pickers because they share this path.

    Scoping the prop to isSmallScreenWidth deliberately leaves the wide-screen Popover path untouched, since that path is already handled by shouldCloseWhenBrowserNavigationChanged and we don't want to alter its existing close behavior.

    Compare branch: https://github.com/Expensify/App/compare/main...wildan-m:App:wildan/91311-date-picker-mweb-nav-close?expand=1

    What alternative solutions did you explore? (Optional)

    An alternative is to map shouldCloseWhenBrowserNavigationChanged to shouldHandleNavigationBack inside PopoverWithMeasuredContent's small-screen branch, so every consumer that opts into browser-navigation close gets it on the Modal path too. This is more general but changes shared behavior for other PopoverWithMeasuredContent consumers (for example the Search filter dropdown), so the targeted change in DatePickerModal is safer and scoped to the reported component.

    Another alternative is to add explicit cleanup in DatePicker (for example a useFocusEffect that closes the calendar when the screen loses focus). This is heavier than needed: the Modal infrastructure already has a dedicated browser-navigation close path via shouldHandleNavigationBack; the date picker simply was not opting into it on small screens.

  8. melvin-bot commented on Jun 1, 2026

    @melvin-bot

    Triggered auto assignment to Contributor-plus team member for initial proposal review - @marufsharifi (External)

  9. KJ21-ENG commented on Jun 1, 2026

    @KJ21-ENG
    Contributor

    Proposal

    What is the root cause of that problem?

    The affected bank-account date fields use the shared DatePicker input. Both DOB and company incorporation date render InputWrapper with InputComponent={DatePicker} and autoFocus:

    <InputWrapper
    InputComponent={DatePicker}
    inputID={dobInputID}
    label={translate('common.dob')}
    placeholder={translate('common.dateFormat')}
    defaultValue={dobDefaultValue}
    minDate={minDate}
    maxDate={maxDate}
    shouldSaveDraft={!isEditing}
    autoFocus
    forwardedFSClass={forwardedFSClass}
    autoComplete="birthdate-full"
    />

    <InputWrapper
    InputComponent={DatePicker}
    inputID={COMPANY_INCORPORATION_DATE_KEY}
    label={translate('businessInfoStep.incorporationDate')}
    placeholder={translate('businessInfoStep.incorporationDatePlaceholder')}
    defaultValue={defaultCompanyIncorporationDate}
    shouldSaveDraft={!isEditing}
    maxDate={new Date()}
    autoFocus
    />

    When the field is focused, DatePicker opens DatePickerModal. The standard DatePicker path opts into browser-navigation dismissal by passing shouldCloseWhenBrowserNavigationChanged to DatePickerModal, and DatePickerModal forwards that intent to PopoverWithMeasuredContent:

    <DatePickerModal
    inputID={inputID}
    minDate={minDate}
    maxDate={maxDate}
    value={getValidDateForCalendar}
    onSelected={handleDateSelected}
    isVisible={isModalVisible}
    onClose={closeDatePicker}
    anchorPosition={popoverPosition}
    shouldPositionFromTop={!isInverted}
    forwardedFSClass={forwardedFSClass}
    shouldCloseWhenBrowserNavigationChanged
    />

    <PopoverWithMeasuredContent
    anchorRef={anchorRef}
    isVisible={isVisible}
    onClose={onClose}
    anchorPosition={anchorPosition}
    popoverDimensions={popoverDimensions}
    shouldCloseWhenBrowserNavigationChanged={shouldCloseWhenBrowserNavigationChanged}
    innerContainerStyle={isSmallScreenWidth ? styles.w100 : {width: CONST.POPOVER_DATE_WIDTH}}
    anchorAlignment={anchorAlignment}
    restoreFocusType={CONST.MODAL.RESTORE_FOCUS_TYPE.DELETE}
    shouldSwitchPositionIfOverflow
    shouldReturnFocus={false}
    shouldMeasureAnchorPositionFromTop={shouldPositionFromTop}
    shouldSkipRemeasurement
    forwardedFSClass={forwardedFSClass}
    shouldDisplayBelowModals
    >

    The app already has close-on-browser-navigation behavior in the normal Popover path: Popover listens for popstate and calls onClose when shouldCloseWhenBrowserNavigationChanged is enabled:

    // Not adding this inside the PopoverProvider
    // because this is an issue on smaller screens as well.
    React.useEffect(() => {
    if (!shouldCloseWhenBrowserNavigationChanged) {
    return;
    }
    const listener = () => {
    if (!isVisible) {
    return;
    }
    // A nested Modal closing itself fires history.back() to drop its guard entry;
    // that popstate is not a real user navigation, so skip closing.
    if (isInternalPopstateInProgress()) {
    return;
    }
    onClose?.();
    };
    window.addEventListener('popstate', listener);
    return () => {
    window.removeEventListener('popstate', listener);
    };
    }, [onClose, isVisible, shouldCloseWhenBrowserNavigationChanged]);

    But iOS Safari mWeb uses the small-screen PopoverWithMeasuredContent path. On small screens, PopoverWithMeasuredContent bypasses Popover and renders Modal directly as a bottom-docked modal:

    if (isSmallScreenWidth) {
    return (
    <Modal
    {...props}
    type={CONST.MODAL.MODAL_TYPE.BOTTOM_DOCKED}
    animationIn="slideInUp"
    animationOut="slideOutDown"
    shouldWrapModalChildrenInScrollViewIfBottomDockedInLandscapeMode={shouldWrapModalChildrenInScrollViewIfBottomDockedInLandscapeMode}
    />
    );

    That direct Modal path does not consume shouldCloseWhenBrowserNavigationChanged. So browser Back/Forward changes the bank-account substep route, but the date picker modal remains visible over the next step because the close intent never reaches a popstate listener in the reproducing layout.

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

    Use the existing browser-navigation-close behavior for the shared date input, and make sure it works in the small-screen web path.

    1. Keep the standard DatePicker path opted into shouldCloseWhenBrowserNavigationChanged, and let DOB/incorporation-date inherit the behavior through the shared date picker rather than adding screen-specific cleanup.
    2. In PopoverWithMeasuredContent, make the small-screen direct-Modal branch honor shouldCloseWhenBrowserNavigationChanged by adding a popstate listener that calls onClose when the popover is visible.
    3. Make that listener web-only (Platform.OS === 'web' and browser event API available), because PopoverWithMeasuredContent is shared with Android/iOS native and browser popstate APIs do not exist there.
    4. Preserve explicit false overrides. Consumers such as search/filter dropdowns that pass shouldCloseWhenBrowserNavigationChanged={false} should not attach this listener and should keep their current nested-selection behavior.
    5. Ignore internal modal cleanup popstates with isInternalPopstateInProgress(), matching the existing Popover behavior.

    This does not use shouldHandleNavigationBack, does not push a modal guard history entry, and does not call history.back(). Browser Forward continues normally; the picker closes as a side effect of the real browser navigation.

    What alternative solutions did you explore? (Optional)

    I considered only passing shouldCloseWhenBrowserNavigationChanged={true} from DatePicker, but that is incomplete for this bug because the iOS mWeb path uses the small-screen PopoverWithMeasuredContent branch that never reaches Popover's listener.

    I considered using shouldHandleNavigationBack, but that would push a modal guard history entry and make browser Back close the picker instead of simply allowing navigation to proceed. The expected behavior here is to allow the browser navigation and close the picker as a consequence of that navigation.

    I also considered moving the listener into DatePickerModal only. That would be narrower, but PopoverWithMeasuredContent already receives the shouldCloseWhenBrowserNavigationChanged prop and the bug is that its small-screen web branch ignores it. Handling the prop in PopoverWithMeasuredContent keeps behavior consistent with the existing Popover path while still preserving explicit opt-outs and native safety through the web-only guard.

    Comparison branch :- https://github.com/Expensify/App/compare/main...KJ21-ENG:App:KJ21-ENG/91311-datepicker-browser-nav-compare?expand=1

    Reproducing issue + proof of working fix :-

    Reproducing issue Proof of working fix
    Screen.Recording.2026-06-02.at.2.03.01.AM.mov
    Screen.Recording.2026-06-02.at.2.06.02.AM.mov
  10. changed the title [-]iOS mWeb - Date picker stays open after navigating forward/backward[/-] [+][$250] iOS mWeb - Date picker stays open after navigating forward/backward[/+] on Jun 1, 2026
  11. 60 remaining items

  12. added
    Awaiting PaymentAuto-added when associated PR is deployed to production
    and removed on Jun 29, 2026
  13. melvin-bot commented on Jun 29, 2026

    @melvin-bot

    Triggered auto assignment to @mallenexpensify (Awaiting Payment)

  14. melvin-bot commented on Jun 29, 2026

    @melvin-bot

    Payment Summary

    Upwork Job

    BugZero Checklist (@mallenexpensify)

    • I have verified the correct assignees and roles are listed above and updated the necessary manual offers
    • I have verified that there are no duplicate or incorrect contracts on Upwork for this job (https://www.upwork.com/ab/applicants/2061472075348511604/hired)
    • I have verified the PR was not reverted
    • I have applied any discounts due to bugs/regressions introduced by this PR
    • I have paid out the Upwork contracts or cancelled the ones that are incorrect
    • I have verified the payment summary above is correct
  15. mallenexpensify commented on Jul 2, 2026

    @mallenexpensify
    Contributor

    @marufsharifi @x-dev90 can you please accept the job below? Please reply here and tag me once you have.
    If you're not sent an offer in Upwork when you're assigned to an issue, please tag me. If an Upwork job exists, please submit a proposal.
    https://www.upwork.com/jobs/~022061472075348511604

    ^ Test case created. Thx

  16. marufsharifi commented on Jul 4, 2026

    @marufsharifi
    Contributor

    @mallenexpensify, I've accepted the offer. thanks.

  17. added and removed on Jul 5, 2026
  18. x-dev90 commented on Jul 6, 2026

    @x-dev90
    Contributor

    @mallenexpensify, The offer accepted, could you please process the payment. thanks.

  19. mallenexpensify commented on Jul 6, 2026

    @mallenexpensify
    Contributor

    Payment Summary

    Contributor: @x-dev90 paid $250 via Upwork
    Contributor+: @marufsharifi paid $250 via Upwork

    Thx!

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

Metadata

Metadata

Labels

Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributor

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions