Skip to content

[Due for payment 2025-09-09] Task - App crashes when opening task share destination list #69244

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: 9.1.99-0
Reproducible in staging?: Yes
Reproducible in production?: Yes
If this was caught during regression testing, add the test name, ID and link from TestRail: Exp #67772
Email or phone of affected tester (no customers): sdondsijsodios@gmail.com
Issue reported by: Applause Internal Team
Device used: Mac 15.5 / Chrome
App Component: Other

Action Performed:

  1. Go to staging.new.expensify.com
  2. Go to workspace chat.
  3. Create a task in the workspace chat.
  4. Delete the workspace.
  5. Click FAB.
  6. Click Assign task under Quick action.
  7. Enter title > Next.
  8. Click Share field.

Expected Result:

App will not crash.

Actual Result:

App crashes when opening task share destination list.

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

1.mp4

logs.txt

View all open jobs on GitHub

Issue OwnerCurrent Issue Owner: @joekaufmanexpensify

Activity

  1. added
    Daily
    Bug
    on Aug 26, 2025
  2. melvin-bot commented on Aug 26, 2025

    @melvin-bot

    Triggered auto assignment to @joekaufmanexpensify (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. nkdengineer commented on Aug 26, 2025

    @nkdengineer
    Contributor

    Proposal

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

    App crashes when opening task share destination list.

    What is the root cause of that problem?

    We use useReportIsArchived that subscribes a useOnyx inside useMemo, then the App crashes due to React's lifecycle

    const filteredReports = reportFilter(optionList.reports);

    const reportFilter = (reportOptions: Array<SearchOption<Report>>) =>
    (reportOptions ?? []).reduce((filtered: Array<SearchOption<Report>>, option) => {
    const report = option.item;
    const isReportArchived = useReportIsArchived(report?.reportID);
    if (canUserPerformWriteAction(report, isReportArchived) && canCreateTaskInReport(report) && !isCanceledTaskReport(report)) {
    filtered.push(option);
    }
    return filtered;
    }, []);
    function TaskShareDestinationSelectorModal() {

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

    We need to get all reportNameValuePairs in TaskShareDestinationSelectorModal and pass them to reportFilter function

    const reportFilter = (reportOptions: Array<SearchOption<Report>>, allReportNameValuePairs: OnyxCollection<ReportNameValuePairs>) =>
    (reportOptions ?? []).reduce((filtered: Array<SearchOption<Report>>, option) => {
        const report = option.item;
        const isReportArchived = isArchivedReport(allReportNameValuePairs?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.reportID}`]);
        if (canUserPerformWriteAction(report, isReportArchived) && canCreateTaskInReport(report) && !isCanceledTaskReport(report)) {
            filtered.push(option);
        }
        return filtered;
    }, []);
    const [allReportNameValuePairs] = useOnyx(ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS, {canBeMissing: true});
    const filteredReports = reportFilter(optionList.reports, allReportNameValuePairs);
    

    const filteredReports = reportFilter(optionList.reports);

    const reportFilter = (reportOptions: Array<SearchOption<Report>>) =>
    (reportOptions ?? []).reduce((filtered: Array<SearchOption<Report>>, option) => {
    const report = option.item;
    const isReportArchived = useReportIsArchived(report?.reportID);
    if (canUserPerformWriteAction(report, isReportArchived) && canCreateTaskInReport(report) && !isCanceledTaskReport(report)) {
    filtered.push(option);
    }
    return filtered;
    }, []);
    function TaskShareDestinationSelectorModal() {

    What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

    None

    What alternative solutions did you explore? (Optional)

    Reminder: Please use plain English, be brief and avoid jargon. Feel free to use images, charts or pseudo-code if necessary. Do not post large multi-line diffs or write walls of text. Do not create PRs unless you have been hired for this job.

  4. ryntgh commented on Aug 26, 2025

    @ryntgh
    Contributor

    Proposal

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

    Task - App crashes when opening task share destination list

    What is the root cause of that problem?

    useReportIsArchived is being called inside an Array.reduce within the reportFilter which cause a React Hooks rules violation

    const reportFilter = (reportOptions: Array<SearchOption<Report>>) =>
    (reportOptions ?? []).reduce((filtered: Array<SearchOption<Report>>, option) => {
    const report = option.item;
    const isReportArchived = useReportIsArchived(report?.reportID);
    if (canUserPerformWriteAction(report, isReportArchived) && canCreateTaskInReport(report) && !isCanceledTaskReport(report)) {
    filtered.push(option);
    }
    return filtered;
    }, []);

    When the workspace is deleted, the reports array changes, causing different numbers of useReportIsArchived hooks to be called on different renders, which breaks React hook consistency requirement

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

    We can follow the pattern used in here to pre-compute archived reports at the component top level

    1. Add archived reports computation at the top level of TaskShareDestinationSelectorModal
        const [archivedReportsIdSet = new Set<string>()] = useOnyx(ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS, {
            canBeMissing: true,
            selector: (all) => {
                const ids = new Set<string>();
                if (!all) {
                    return ids;
                }
    
                const prefixLength = ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS.length;
                for (const [key, value] of Object.entries(all)) {
                    if (isArchivedReport(value)) {
                        const reportID = key.slice(prefixLength);
                        ids.add(reportID);
                    }
                }
                return ids;
            },
        });
    1. Update the reportFilter to use the pre-computed set instead of calling the hook
    const reportFilter = (reportOptions: Array<SearchOption<Report>>, archivedReportsSet: Set<string>) =>
        (reportOptions ?? []).reduce((filtered: Array<SearchOption<Report>>, option) => {
            const report = option.item;
            const isReportArchived = archivedReportsSet.has(report?.reportID ?? '');
            if (canUserPerformWriteAction(report, isReportArchived) && canCreateTaskInReport(report) && !isCanceledTaskReport(report)) {
                filtered.push(option);
            }
            return filtered;
        }, []);

    const reportFilter = (reportOptions: Array<SearchOption<Report>>) =>
    (reportOptions ?? []).reduce((filtered: Array<SearchOption<Report>>, option) => {
    const report = option.item;
    const isReportArchived = useReportIsArchived(report?.reportID);
    if (canUserPerformWriteAction(report, isReportArchived) && canCreateTaskInReport(report) && !isCanceledTaskReport(report)) {
    filtered.push(option);
    }
    return filtered;
    }, []);

    1. And update the function call to pass the archived reports set
            const filteredReports = reportFilter(optionList.reports, archivedReportsIdSet);

    const filteredReports = reportFilter(optionList.reports);

    What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

    N/A


    What alternative solutions did you explore? (Optional)

    N/A


  5. daledah commented on Aug 26, 2025

    @daledah
    Contributor

    Proposal

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

    App crashes when opening task share destination list.

    What is the root cause of that problem?

    We're using a hook inside a normal function here:

    const isReportArchived = useReportIsArchived(report?.reportID);

    And that function is used inside a memo:

    const filteredReports = reportFilter(optionList.reports);

    This violates React's rule of hooks and cause app crash.

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

    This change was added in #68269 to remove usage of reportNameValuePairs. Following that rule, we should update to change reportFilter into a hook instead.

    Implement like below

    const useReportFilter = (reportOptions: Array<SearchOption<Report>>) => {
        const [allReportNameValuePairs] = useOnyx(ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS, {canBeMissing: true});
        const filteredReportOptions = useMemo(
            () =>
                (reportOptions ?? []).reduce((filtered: Array<SearchOption<Report>>, option) => {
                    const report = option.item;
                    const reportNameValuePairs = allReportNameValuePairs?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID}`];
                    const isReportArchived = isArchivedReport(reportNameValuePairs);
                    if (canUserPerformWriteAction(report, isReportArchived) && canCreateTaskInReport(report) && !isCanceledTaskReport(report)) {
                        filtered.push(option);
                    }
                    return filtered;
                }, []),
            [allReportNameValuePairs, reportOptions],
        );
        return filteredReportOptions;
    };

    Use the hook inside TaskShareDestinationSelectorModal and use it here instead

    const filteredReports = reportFilter(optionList.reports);
    const {recentReports} = getShareDestinationOptions(filteredReports, optionList.personalDetails, [], [], {}, true);

    What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

    We should add a new lint rule to detect violated usage of hooks. We can use the same rule as eslint-plugin-react-hooks.

    What alternative solutions did you explore? (Optional)

    Reminder: Please use plain English, be brief and avoid jargon. Feel free to use images, charts or pseudo-code if necessary. Do not post large multi-line diffs or write walls of text. Do not create PRs unless you have been hired for this job.

  6. joekaufmanexpensify commented on Aug 26, 2025

    @joekaufmanexpensify
    Contributor

    Looks like #68269 (comment) just went out to prod 4 days ago. If that is what introduced this, could you guys take a look @thelullabyy @DylanDylann as this would still be within regression period

  7. added
    Reviewing
    Weekly
    and removed
    Daily
    on Aug 27, 2025
  8. thelullabyy commented on Aug 27, 2025

    @thelullabyy
    Contributor

    @joekaufmanexpensify @DylanDylann Opened PR to handle this

  9. joekaufmanexpensify commented on Aug 27, 2025

    @joekaufmanexpensify
    Contributor

    Great. TY!

  10. melvin-bot commented on Aug 27, 2025

    @melvin-bot

    Triggered auto assignment to @yuwenmemon, see https://stackoverflow.com/c/expensify/questions/7972 for more details.

  11. joekaufmanexpensify commented on Sep 1, 2025

    @joekaufmanexpensify
    Contributor

    PR on staging

  12. added
    Weekly
    Awaiting Payment
    and removed
    Weekly
    on Sep 2, 2025
  13. changed the title [-]Task - App crashes when opening task share destination list[/-] [+][Due for payment 2025-09-09] Task - App crashes when opening task share destination list[/+] on Sep 2, 2025
  14. melvin-bot commented on Sep 2, 2025

    @melvin-bot

    Reviewing label has been removed, please complete the "BugZero Checklist".

  15. removed
    Reviewing
    on Sep 2, 2025
  16. melvin-bot commented on Sep 2, 2025

    @melvin-bot

    The solution for this issue has been 🚀 deployed to production 🚀 in version 9.2.0-5 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 2025-09-09. 🎊

    For reference, here are some details about the assignees on this issue:

    • @DylanDylann requires payment through NewDot Manual Requests
    • @thelullabyy requires payment (Needs manual offer from BZ)
  17. melvin-bot commented on Sep 2, 2025

    @melvin-bot

    @DylanDylann @joekaufmanexpensify The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed. Please copy/paste the BugZero 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]

  18. joekaufmanexpensify commented on Sep 4, 2025

    @joekaufmanexpensify
    Contributor

    @DylanDylann could you handle checklist so we can prep for payment next week?

  19. DylanDylann commented on Sep 4, 2025

    @DylanDylann
    Contributor

    No, this is a regression from our PR. We can close it out

  20. joekaufmanexpensify commented on Sep 8, 2025

    @joekaufmanexpensify
    Contributor

    Sounds good!

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

Metadata

Metadata

Labels

Awaiting PaymentBugWeekly

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions