Skip to content

[$250] Distance - App keep crashing after start GPS and switch to OD #80593

Closed

Description

@jponikarchuk

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: v9.3.9-1
Reproducible in staging?: Yes
Reproducible in production?: Yes
If this was caught during regression testing, add the test name, ID and link from BrowserStack: #79587
Email or phone of affected tester (no customers): applausetester+vq+260103@applause.expensifail.com
Issue reported by: Applause Internal Team
Bug source: Exploratory - Significant User Experience Deterioration
Device used: Pixel 7 Pro /Android 16
App Component: Money Requests

Action Performed:

Preconditions: Use the Expensifail account to have the beta enabled for GPS

  1. Open the Hybrid app
  2. Tap on the FAB
  3. Select Track distance
  4. Select GPS and allow the background running
  5. Tap on the Account > Troubleshoot
  6. Switch to OD
  7. Tap on the App to open again

Expected Result:

The app should display a warning about GPS when switching between ND and OD

Actual Result:

Android: The app keeps crashing.
iOS: No warning when the user switches to OD and logs out, after that, can't log in to the iOS app again with the Magic code

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

Android_app.mp4
iOS_app.mp4

logs.txt

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~022016059787841281593
  • Upwork Job ID: 2016059787841281593
  • Last Price Increase: 2026-01-27
Issue OwnerCurrent Issue Owner: @suneox

Activity

  1. added
    ExternalAdded to denote the issue can be worked on by a contributor
    BugSomething is broken. Auto assigns a BugZero manager.
    on Jan 27, 2026
  2. changed the title [-]Distance - App keep crashing after start GPS and switch to OD[/-] [+][$250] Distance - App keep crashing after start GPS and switch to OD[/+] on Jan 27, 2026
  3. melvin-bot commented on Jan 27, 2026

    @melvin-bot
  4. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Jan 27, 2026
  5. melvin-bot commented on Jan 27, 2026

    @melvin-bot

    Triggered auto assignment to @bfitzexpensify (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.

  6. melvin-bot commented on Jan 27, 2026

    @melvin-bot

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

  7. yatin-italy commented on Jan 27, 2026

    @yatin-italy

    Proposal

    Restate the problem this issue is trying to solve.

    When GPS distance tracking is active and the user switches from NewDot to OldDot using Troubleshoot, the app does not handle the transition safely. On Android, the app crashes in a loop after the switch. On iOS, no GPS warning is shown, and after logout the user cannot log back in with the magic code. The system allows a mode switch while GPS tracking is still active.

    What is the root cause of that problem?

    The root cause is an incorrect assumption in src/libs/actions/HybridApp/index.ts inside the closeReactNativeApp() function. The code assumes it is safe to close the React Native app without stopping GPS tracking or clearing GPS_DRAFT_DETAILS. This assumption is wrong because GPS tracking state can still be active. When the app closes with isTracking: true persisted in Onyx, the background GPS service continues to run. This creates inconsistent state that directly causes crashes on reopen and blocks login flows.

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

    • Stop GPS tracking and clear GPS state before closing the React Native app.
    • Ensure GPS state is also cleared when returning from OldDot to NewDot.
    • Show a GPS warning modal before switching modes if GPS tracking is active.

    File 1: src/libs/actions/HybridApp/index.ts
    Add GPS cleanup in closeReactNativeApp() before closing the app.

    import HybridAppModule from '@expensify/react-native-hybrid-app';
    import Onyx from 'react-native-onyx';
    import Navigation from '@libs/Navigation/Navigation';
    import {resetGPSDraftDetails, setIsTracking} from '@libs/actions/GPSDraftDetails';
    import CONFIG from '@src/CONFIG';
    import ONYXKEYS from '@src/ONYXKEYS';
    import type {HybridApp} from '@src/types/onyx';
    import type HybridAppSettings from './types';
    
    // ... existing code ...
    
    function closeReactNativeApp({shouldSetNVP}: {shouldSetNVP: boolean}) {
        Navigation.clearPreloadedRoutes();
    
        // Stop GPS tracking and clean up GPS tracking state before switching modes
        setIsTracking(false);
        resetGPSDraftDetails();
    
        if (CONFIG.IS_HYBRID_APP) {
            Onyx.merge(ONYXKEYS.HYBRID_APP, {closingReactNativeApp: true});
        }
    
        // eslint-disable-next-line no-restricted-properties
        HybridAppModule.closeReactNativeApp({shouldSetNVP});
    }

    File 2: src/libs/actions/Session/index.ts
    Clean up GPS state when transitioning back to NewDot.

    import {resetGPSDraftDetails, setIsTracking} from '@libs/actions/GPSDraftDetails';
    
    // ... existing imports ...
    
    function setupNewDotAfterTransitionFromOldDot(hybridAppSettings: HybridAppSettings, tryNewDot?: TryNewDot) {
        const {hybridApp, ...newDotOnyxValues} = hybridAppSettings;
    
        const clearOnyxIfSigningIn = () => {
            if (!hybridApp.useNewDotSignInPage) {
                return Promise.resolve();
            }
    
            Log.info(`[HybridApp] Clearing onyx after transition from OldDot. useNewDotSignInPage set to ${hybridApp.useNewDotSignInPage}`);
            return redirectToSignIn();
        };
    
        const resetDidUserLoginDuringSessionIfNeeded = () => {
            if (newDotOnyxValues.nvp_tryNewDot === undefined || tryNewDot?.classicRedirect?.dismissed !== true) {
                return Promise.resolve();
            }
    
            Log.info("[HybridApp] OpenApp hasn't been called yet. Calling `resetDidUserLogInDuringSession`");
            resetDidUserLogInDuringSession();
        };
    
        return clearOnyxIfSigningIn()
            .then(() => {
                // Stop GPS tracking and clean up GPS tracking state during mode transitions
                setIsTracking(false);
                resetGPSDraftDetails();
    
                const currentUserEmail = getCurrentUserEmail();
    
                if (hybridApp?.delegateAccessData?.oldDotCurrentUserEmail === currentUserEmail) {
                    Log.info('[HybridApp] User did not switch account on OldDot side');
                    return;
                }
    
                // ... rest of existing transition logic ...
            })
            .then(resetDidUserLoginDuringSessionIfNeeded)
            .then(() =>
                Promise.all([
                    HybridAppActions.prepareHybridAppAfterTransitionToNewDot({
                        ...hybridApp,
                        closingReactNativeApp: false,
                    }),
                    ...Object.entries(newDotOnyxValues).map(([key, value]) => Onyx.merge(key as OnyxKey, value ?? {})),
                ]),
            )
            .then(() => {
                Log.info('[HybridApp] Setup after transition from OldDot finished');
                isHybridAppSetupFinished = true;
                return Promise.resolve();
            })
            .catch((error) => {
                Log.hmmm('[HybridApp] Initialization of HybridApp has failed. Forcing transition', {error});
            });
    }

    File 3: src/pages/settings/Troubleshoot/TroubleshootPage.tsx
    Show a GPS warning modal before switching to OldDot.

    import {resetGPSDraftDetails, setIsTracking} from '@libs/actions/GPSDraftDetails';
    
    // ... existing imports ...
    
    function TroubleshootPage() {
        const [isGpsWarningModalVisible, setIsGpsWarningModalVisible] = useState(false);
        const [gpsDraftDetails] = useOnyx(ONYXKEYS.GPS_DRAFT_DETAILS, {canBeMissing: true});
    
        const handleSwitchToOldDot = useCallback(() => {
            if (gpsDraftDetails?.isTracking) {
                setIsGpsWarningModalVisible(true);
                return;
            }
            closeReactNativeApp({shouldSetNVP: true});
        }, [gpsDraftDetails?.isTracking]);
    
        const handleConfirmGpsWarning = useCallback(() => {
            setIsGpsWarningModalVisible(false);
            setIsTracking(false);
            resetGPSDraftDetails();
            closeReactNativeApp({shouldSetNVP: true});
        }, []);
    
        // ... existing code ...
    
        return (
            <ScreenWrapper
                shouldEnablePickerAvoiding={false}
                shouldShowOfflineIndicatorInWideScreen
                testID="TroubleshootPage"
            >
                {/* ... existing JSX ... */}
    
                <ConfirmModal
                    danger
                    title={translate('gps.stopGpsTrackingModal.title')}
                    isVisible={isGpsWarningModalVisible}
                    onConfirm={handleConfirmGpsWarning}
                    onCancel={() => setIsGpsWarningModalVisible(false)}
                    confirmText={translate('gps.stopGpsTrackingModal.confirm')}
                    cancelText={translate('gps.stopGpsTrackingModal.cancel')}
                    prompt={translate('gps.stopGpsTrackingModal.prompt')}
                />
    
                {/* ... rest of existing JSX ... */}
            </ScreenWrapper>
        );
    }

    File 4: src/components/ConfirmNavigateExpensifyClassicModal/BaseConfirmNavigateExpensifyClassicModal.tsx
    Block navigation and show GPS warning if tracking is active.

    import React, {useCallback, useState} from 'react';
    import ConfirmModal from '@components/ConfirmModal';
    import useLocalize from '@hooks/useLocalize';
    import useOnyx from '@hooks/useOnyx';
    import {closeReactNativeApp} from '@libs/actions/HybridApp';
    import {resetGPSDraftDetails, setIsTracking} from '@libs/actions/GPSDraftDetails';
    import {setIsOpenConfirmNavigateExpensifyClassicModalOpen} from '@libs/actions/isOpenConfirmNavigateExpensifyClassicModal';
    import {openOldDotLink} from '@libs/actions/Link';
    import CONFIG from '@src/CONFIG';
    import CONST from '@src/CONST';
    import ONYXKEYS from '@src/ONYXKEYS';
    
    function BaseConfirmNavigateExpensifyClassicModal() {
        const [isOpenAppConfirmNavigateExpensifyClassicModalOpen = false] = useOnyx(
            ONYXKEYS.IS_OPEN_CONFIRM_NAVIGATE_EXPENSIFY_CLASSIC_MODAL_OPEN,
            {canBeMissing: true},
        );
        const [gpsDraftDetails] = useOnyx(ONYXKEYS.GPS_DRAFT_DETAILS, {canBeMissing: true});
        const [isGpsWarningModalVisible, setIsGpsWarningModalVisible] = useState(false);
        const {translate} = useLocalize();
    
        const handleConfirm = useCallback(() => {
            setIsOpenConfirmNavigateExpensifyClassicModalOpen(false);
    
            if (CONFIG.IS_HYBRID_APP) {
                if (gpsDraftDetails?.isTracking) {
                    setIsGpsWarningModalVisible(true);
                    return;
                }
                closeReactNativeApp({shouldSetNVP: true});
                return;
            }
    
            openOldDotLink(CONST.OLDDOT_URLS.INBOX);
        }, [gpsDraftDetails?.isTracking]);
    
        const handleConfirmGpsWarning = useCallback(() => {
            setIsGpsWarningModalVisible(false);
            setIsTracking(false);
            resetGPSDraftDetails();
            closeReactNativeApp({shouldSetNVP: true});
        }, []);
    
        const handleCancel = useCallback(() => {
            setIsOpenConfirmNavigateExpensifyClassicModalOpen(false);
        }, []);
    
        return (
            <>
                <ConfirmModal
                    prompt={translate('sidebarScreen.redirectToExpensifyClassicModal.description')}
                    isVisible={isOpenAppConfirmNavigateExpensifyClassicModalOpen}
                    onConfirm={handleConfirm}
                    onCancel={handleCancel}
                    title={translate('sidebarScreen.redirectToExpensifyClassicModal.title')}
                    confirmText={translate('exitSurvey.goToExpensifyClassic')}
                    cancelText={translate('common.cancel')}
                />
                <ConfirmModal
                    danger
                    title={translate('gps.stopGpsTrackingModal.title')}
                    isVisible={isGpsWarningModalVisible}
                    onConfirm={handleConfirmGpsWarning}
                    onCancel={() => setIsGpsWarningModalVisible(false)}
                    confirmText={translate('gps.stopGpsTrackingModal.confirm')}
                    cancelText={translate('gps.stopGpsTrackingModal.cancel')}
                    prompt={translate('gps.stopGpsTrackingModal.prompt')}
                />
            </>
        );
    }
    
    export default BaseConfirmNavigateExpensifyClassicModal;

    What alternative solutions did you explore? (Optional)

    • Preserving GPS_DRAFT_DETAILS across transitions was rejected because GPS state must not persist between modes.
    • Adding cleanup only in native code was rejected because GPS state is owned in the JS layer.
    • Showing the warning only on iOS was rejected to keep behavior consistent and safer on all platforms.
  8. GCyganek commented on Jan 27, 2026

    @GCyganek
    Contributor

    Part of GPS feature that I'm responsible for as a Software Mansion engineer, will take care of this

  9. removed
    Help WantedApply this label when an issue is open to proposals by contributors
    on Jan 27, 2026
  10. 7 remaining items

  11. melvin-bot commented on Feb 23, 2026

    @melvin-bot

    This issue has not been updated in over 15 days. @suneox, @GCyganek eroding to Monthly issue.

    P.S. Is everyone reading this sure this is really a near-term priority? Be brave: if you disagree, go ahead and close it out. If someone disagrees, they'll reopen it, and if they don't: one less thing to do!

  12. melvin-bot commented on Apr 17, 2026

    @melvin-bot

    ⚠️ Looks like this issue was linked to a Deploy Blocker here

    If you are the assigned CME please investigate whether the linked PR caused a regression and leave a comment with the results.

    If a regression has occurred and you are the assigned CM follow the instructions here.

    If this regression could have been avoided please consider also proposing a recommendation to the PR checklist so that we can avoid it in the future.

  13. suneox commented on May 11, 2026

    @suneox
    Contributor

    Could someone please reassign this issue to me as comment? Thanks!

  14. suneox commented on Jun 3, 2026

    @suneox
    Contributor

    @MelvinBot un-assign this issue to me

  15. MelvinBot commented on Jun 3, 2026

    @MelvinBot
    Contributor

    🤖 Done — I've unassigned suneox from this issue.

  16. melvin-bot commented on Jun 26, 2026

    @melvin-bot

    This issue has not been updated in over 15 days. @GCyganek eroding to Monthly issue.

    P.S. Is everyone reading this sure this is really a near-term priority? Be brave: if you disagree, go ahead and close it out. If someone disagrees, they'll reopen it, and if they don't: one less thing to do!

  17. melvin-bot commented on Aug 24, 2026

    @melvin-bot

    @GCyganek, this Monthly task hasn't been acted upon in 6 weeks; closing.

    If you disagree, feel encouraged to reopen it -- but pick your least important issue to close instead.

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

Metadata

Metadata

Assignees

Labels

BugSomething is broken. Auto assigns a BugZero manager.ExternalAdded to denote the issue can be worked on by a contributorMonthlyKSv2Not a priorityReviewingHas a PR in review

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions