Skip to content

[$250] Android-App crash when invite new member to Workspace #74153

Closed

Description

@mitarachim

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.2.43-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: #72871
Email or phone of affected tester (no customers): duytestnguyen+63@gmail.com
Issue reported by: Applause Internal Team
Device used: Android 16 / Pixel 7A
App Component: Workspace Settings

Action Performed:

Preconditions:

  • [User A] Create new account (A)
  • [User B] User have a workspace (Workspace 1) and add user A to Workspace 1 as member
  • All steps below are run by User A
  1. Open Hybrid app
  2. Navigate to Account > Troubleshoot
  3. Clear cached and restart
  4. Navigate to Workspace
  5. Create new Workspace (Workspace 2)
  6. Leave Workspace 1
  7. Delete Workspace 2
  8. Create new Workspace (Workspace 3)
  9. Tap on Member > Invite member
  10. Enter an email > Next
  11. Tap outside keyboard

Try repeat Step 9, 10 and 11 for twice to three times to experience a crash.

Expected Result:

User can successfully invite member to Workspace

Actual Result:

At step 10 and step 11, app crashes. Try repeat Step 9, 10 and 11 for twice to three times.

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

Bug6993369_1762234036134!logs-2025-11-04_05_12_16.793.txt

Bug6993369_1762234036144.App_Crash_When_Add_New_Member.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021985885561039373168
  • Upwork Job ID: 1985885561039373168
  • Last Price Increase: 2026-02-11
  • Automatic offers:
    • situchan | Contributor | 109439694
Issue OwnerCurrent Issue Owner: @marufsharifi

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Nov 4, 2025
  2. melvin-bot commented on Nov 4, 2025

    @melvin-bot

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

  3. mitarachim commented on Nov 4, 2025

    @mitarachim
    Author

    Issue was found while executing QA for PR #72871

  4. luacmartins commented on Nov 4, 2025

    @luacmartins
    Contributor

    @mitarachim is this a deploy blocker? It seems like it's not reproducible in production, right?

  5. luacmartins commented on Nov 4, 2025

    @luacmartins
    Contributor

    Try repeat Step 9, 10 and 11 for twice to three times to experience a crash.

    This seems like something users won't do, so I won't block the deploy on it.

  6. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Nov 5, 2025
  7. changed the title [-]Android-App crash when invite new member to Workspace[/-] [+][$250] Android-App crash when invite new member to Workspace[/+] on Nov 5, 2025
  8. melvin-bot commented on Nov 5, 2025

    @melvin-bot
  9. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Nov 5, 2025
  10. melvin-bot commented on Nov 5, 2025

    @melvin-bot

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

  11. IjaazA commented on Nov 5, 2025

    @IjaazA
    Contributor

    Proposal

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

    The Android app crashes when inviting a new member to a Workspace.

    What is the root cause of that problem?

    This occurs when navigating between WorkspaceInvitePage and WorkspaceInviteMessageComponent—particularly after sending an initial invitation and attempting to invite another member.

    The crash is caused by asynchronous operations and state updates that continue to execute after the component has unmounted, leading to “state update on unmounted component” errors and inconsistent draft restoration on remount.

    Missing cleanup for async operations:

    searchInServer() in WorkspaceInvitePage lacked cleanup logic.

    Pending requests completed after unmount, triggering state updates on unmounted components.

    Location: src/pages/workspace/WorkspaceInvitePage.tsx:308–310

    State updates after unmount:

    The large useEffect block (lines 125–203) could update state after the component was unmounted.

    Onyx subscriptions continued updating even after navigation.
    No mount guards were used to prevent these updates.

    In WorkspaceInviteMessageComponent, a useEffect (lines 111–128) navigated back when the draft was empty.
    This logic could re-trigger on remount, causing duplicate navigation events.

    firstRenderRef was not reset on remount.
    When inviting a second member, the draft state was not restored correctly.

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

    • Add lifecycle management and cleanup to prevent:
    • State updates after unmount
    • Stale async operations completing after navigation
    • Navigation race conditions
    • Draft state restoration issues
    1. Add Mount Tracking Refs
    • Add isMountedRef to both components to track mount state.
    • Reset on mount and set to false on unmount.
    1. Add Cleanup Functions
    • Cancel pending search requests in useEffect cleanup.
    • Cancel on unmount and when search term changes.
    1. Guard State Updates
    • Check isMountedRef.current before all setState calls.
    • Early return in useEffect if component is unmounted.
    1. Fix Navigation Logic
    • Add hasNavigatedRef to prevent duplicate navigation.
    • Reset navigation flag on mount.
    • Add mount check before navigation.
    1. Reset Refs on Remount
    • Reset firstRenderRef on mount to restore draft state.
    • Ensures draft state is properly restored when navigating back.

    Code Changes:

    File 1: src/pages/workspace/WorkspaceInvitePage.tsx
    Change 1: Add mount tracking ref

    // Line 60: Add after firstRenderRef

    const isMountedRef = useRef(true);

    Change 2: Reset refs and add cleanup on mount
    // Lines 72-85: Update mount useEffect

    useEffect(() => {
        // Reset refs when component mounts/remounts to properly restore draft state
        isMountedRef.current = true;
        firstRenderRef.current = true;
    
        clearErrors(route.params.policyID);
        openWorkspaceInvitePage();
    
        return () => {
            // Cleanup: cancel any pending search requests when component unmounts
            isMountedRef.current = false;
            HttpUtils.cancelPendingRequests(READ_COMMANDS.SEARCH_FOR_REPORTS);
        };
    }, []);
    

    Change 3: Guard state updates in large useEffect
    // Lines 115-193: Update large useEffect

    useEffect(() => {
        if (!areOptionsInitialized || !isMountedRef.current) {
            return; // Early return if unmounted
        }
    
        // ... existing logic ...
    
        // Only update state if component is still mounted to prevent crashes
        if (isMountedRef.current) {
            setUsersToInvite(Object.values(newUsersToInviteDict));
            setPersonalDetails(Object.values(newPersonalDetailsDict));
            setSelectedOptions(Object.values(newSelectedOptionsDict));
        }
    }, [/* dependencies */]);
    

    Change 4: Add cleanup for search requests
    // Lines 321-329: Update searchInServer useEffect

    useEffect(() => {
        searchInServer(debouncedSearchTerm);
    
        return () => {
            // Cleanup: cancel pending requests when search term changes or component unmounts
            HttpUtils.cancelPendingRequests(READ_COMMANDS.SEARCH_FOR_REPORTS);
        };
    }, [debouncedSearchTerm]);
    

    File 2: src/pages/workspace/members/WorkspaceInviteMessageComponent.tsx

    Change 1: Add mount and navigation tracking refs
    // Lines 73-74: Add after welcomeNote state

    const hasNavigatedRef = useRef(false);
    const isMountedRef = useRef(true);
    

    Change 2: Initialize and cleanup refs
    // Lines 112-119: Add new useEffect after getDefaultWelcomeNote

    useEffect(() => {
        isMountedRef.current = true;
        hasNavigatedRef.current = false;
    
        return () => {
            isMountedRef.current = false;
        };
    }, []);
    

    Change 3: Fix navigation logic with guards

    // Lines 121-143: Update navigation useEffect

    useEffect(() => {
        if (isOnyxLoading || !isMountedRef.current) {
            return; // Guard: don't navigate if unmounted or loading
        }
    
        if (!isEmptyObject(invitedEmailsToAccountIDsDraft)) {
            setWelcomeNote(getDefaultWelcomeNote());
            return;
        }
    
        if (isEmptyObject(policy)) {
            return;
        }
    
        // Only navigate back if we haven't already navigated and the draft is empty
        if (!hasNavigatedRef.current) {
            hasNavigatedRef.current = true;
            Navigation.goBack(backTo);
        }
    }, [isOnyxLoading, invitedEmailsToAccountIDsDraft, policy, backTo]);
    

    What alternative solutions did you explore? (Optional)
    Use AbortController for per-request cancellation

  12. 132 remaining items

  13. marufsharifi commented on Mar 17, 2026

    @marufsharifi

    @brianlee-expensify, the automation failed for this issue. Could you please process the payment for this issue? since it was deployed to production last week. thanks.

  14. marufsharifi commented on Mar 23, 2026

    @marufsharifi

    @brianlee-expensify, gentle bump. thanks.

  15. added
    Awaiting PaymentAuto-added when associated PR is deployed to production
    and removed on Mar 24, 2026
  16. melvin-bot commented on Mar 24, 2026

    @melvin-bot

    Triggered auto assignment to @mallenexpensify (Awaiting Payment)

  17. mallenexpensify commented on Mar 24, 2026

    @mallenexpensify
    Contributor

    Payment Summary

    Contributor: @marufsharifi paid $250 via Upwork
    Contributor+: @situchan paid $250 via Upwork

    @marufsharifi @situchan can you please accept the job below? Please reply here and tag me once you have.
    https://www.upwork.com/jobs/~022036551178480319333

  18. marufsharifi commented on Mar 25, 2026

    @marufsharifi

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

  19. mallenexpensify commented on Mar 26, 2026

    @mallenexpensify
    Contributor

    @marufsharifi paid, summary updated above. Thx.

  20. situchan commented on Mar 30, 2026

    @situchan
    Contributor

    @mallenexpensify I haven't received payment

  21. mallenexpensify commented on Apr 2, 2026

    @mallenexpensify
    Contributor

    Apologies @situchan , paid, summary updated above. 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

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions