Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PAID] [$250] Leaving a group chat with 0 members inside still populates the search as a result #40493

Closed
1 of 6 tasks
m-natarajan opened this issue Apr 18, 2024 · 17 comments
Closed
1 of 6 tasks
Assignees
Labels
Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 Engineering External Added to denote the issue can be worked on by a contributor Reviewing Has a PR in review

Comments

@m-natarajan
Copy link

m-natarajan commented Apr 18, 2024

If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!


Version Number: 1.4.63-0
Reproducible in staging?: y
Reproducible in production?: no new feature
If this was caught during regression testing, add the test name, ID and link from TestRail:
Email or phone of affected tester (no customers):
Logs: https://stackoverflow.com/c/expensify/questions/4856
Expensify/Expensify Issue URL:
Issue reported by: @johnmlee101
Slack conversation: https://expensify.slack.com/archives/C049HHMV9SM/p1713458559012729

Action Performed:

Create a group chat with some group.
Remove each of them then leave the room.

Expected Result:

Group chat should either 1. Be archived or 2. be completely inaccessible.

Actual Result:

Chat shows up like this on the search 's Group Chat and is inaccessible when clicking in.
Chrome - Latest staging

Workaround:

unknown

Platforms:

Which of our officially supported platforms is this issue occurring on?

  • Android: Native
  • Android: mWeb Chrome
  • iOS: Native
  • iOS: mWeb Safari
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

Add any screenshot/video evidence

Recording.2986.mp4

image (3)

image (2)

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01d256e1494b7b0e48
  • Upwork Job ID: 1785022225889374208
  • Last Price Increase: 2024-04-29
  • Automatic offers:
    • jjcoffee | Reviewer | 0
    • bernhardoj | Contributor | 0
@m-natarajan m-natarajan added DeployBlockerCash This issue or pull request should block deployment Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Apr 18, 2024
Copy link

melvin-bot bot commented Apr 18, 2024

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

Copy link

melvin-bot bot commented Apr 18, 2024

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

@m-natarajan m-natarajan changed the title Bug Leaving a group chat with 0 members inside still populates the search as a result Leaving a group chat with 0 members inside still populates the search as a result Apr 18, 2024
@github-actions github-actions bot added Engineering Hourly KSv2 and removed Daily KSv2 labels Apr 18, 2024
Copy link
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.

@marcaaron
Copy link
Contributor

This doesn't feel like a deploy blocker to me. @johnmlee101 I can grab this from you if you'd like as it's related to Group Chats.

@marcaaron marcaaron added Weekly KSv2 and removed DeployBlockerCash This issue or pull request should block deployment Hourly KSv2 labels Apr 18, 2024
@johnmlee101
Copy link
Contributor

Sure go right ahead!

@johnmlee101 johnmlee101 assigned marcaaron and unassigned johnmlee101 Apr 18, 2024
@melvin-bot melvin-bot bot added the Overdue label Apr 26, 2024
@bernhardoj
Copy link
Contributor

Proposal

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

When we leave a from a group chat, the group chat is still accessible from the search page. You don't need to remove other members first, just leave from the group and the issue happens.

What is the root cause of that problem?

This is an issue with the options list cache in OptionListContextProvider. Currently, we have a logic to update the list cache whenever the report is either updated or added,

/**
* This effect is used to update the options list when a report is updated.
*/
useEffect(() => {
// there is no need to update the options if the options are not initialized
if (!areOptionsInitialized.current) {
return;
}
const lastUpdatedReport = ReportUtils.getLastUpdatedReport();
if (!lastUpdatedReport) {
return;
}
const newOption = OptionsListUtils.createOptionFromReport(lastUpdatedReport, personalDetails);
const replaceIndex = options.reports.findIndex((option) => option.reportID === lastUpdatedReport.reportID);
if (replaceIndex === -1) {
return;
}
setOptions((prevOptions) => {
const newOptions = {...prevOptions};
newOptions.reports[replaceIndex] = newOption;
return newOptions;
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [reports]);
/**
* This effect is used to add a new report option to the list of options when a new report is added to the collection.
*/
useEffect(() => {
if (!areOptionsInitialized.current || !reports) {
return;
}
const missingReportIds = Object.keys(reports).filter((key) => prevReports && !(key in prevReports));
setOptions((prevOptions) => {
const newOptions = {...prevOptions};
missingReportIds.forEach((missingReportId) => {
const report = missingReportId ? reports[missingReportId] : null;
if (!missingReportId || !report) {
return;
}
const reportOption = OptionsListUtils.createOptionFromReport(report, personalDetails);
newOptions.reports.push(reportOption);
});
return newOptions;
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [reports]);

but we don't have the logic to update the cache when a report is removed. Leaving a group chat will remove the report. So, when we open the search page, we still see the group chat in the list, but it looks broken because the data is not available anymore.

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

Update the cache list when a report is deleted. We can follow the update pattern from the add report logic,

useEffect(() => {
    if (!areOptionsInitialized.current || !reports || !prevReports) {
        return;
    }
    const removedReportKeys = Object.keys(reports).filter((key) => reports[key] === null);

    setOptions((prevOptions) => {
        const newOptions = {...prevOptions};
        removedReportKeys.forEach((removedReportKey) => {
            const removedReportID = removedReportKey.replace(ONYXKEYS.COLLECTION.REPORT, '');
            const removedReportIdx = newOptions.reports.findIndex((report) => report.reportID === removedReportID);
            newOptions.reports.splice(removedReportIdx, 1);
        });
        return newOptions;
    });
    // eslint-disable-next-line react-hooks/exhaustive-deps
}, [reports]);

or we can simplify it just like this,

useEffect(() => {
    if (!areOptionsInitialized.current || !reports || !prevReports) {
        return;
    }
    setOptions((prevOptions) => ({
        ...prevOptions,
        reports: prevOptions.reports.filter((report) => reports[`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`] !== null),
    }))
    // eslint-disable-next-line react-hooks/exhaustive-deps
}, [reports]);

If we decided to use the 2nd logic, I think we can add the code in the add logic here,

/**
* This effect is used to add a new report option to the list of options when a new report is added to the collection.
*/
useEffect(() => {
if (!areOptionsInitialized.current || !reports) {
return;
}
const missingReportIds = Object.keys(reports).filter((key) => prevReports && !(key in prevReports));
setOptions((prevOptions) => {
const newOptions = {...prevOptions};

so we are not adding another useEffect. So, the above useEffect will handle both added/deleted report

@melvin-bot melvin-bot bot added Daily KSv2 and removed Weekly KSv2 Overdue labels Apr 29, 2024
@marcaaron marcaaron added the External Added to denote the issue can be worked on by a contributor label Apr 29, 2024
@melvin-bot melvin-bot bot changed the title Leaving a group chat with 0 members inside still populates the search as a result [$250] Leaving a group chat with 0 members inside still populates the search as a result Apr 29, 2024
Copy link

melvin-bot bot commented Apr 29, 2024

Job added to Upwork: https://www.upwork.com/jobs/~01d256e1494b7b0e48

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Apr 29, 2024
Copy link

melvin-bot bot commented Apr 29, 2024

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

@jjcoffee
Copy link
Contributor

jjcoffee commented Apr 30, 2024

@bernhardoj's proposal LGTM! I like the idea of combining the logic in one useEffect.

🎀👀🎀 C+ reviewed

Copy link

melvin-bot bot commented Apr 30, 2024

Current assignee @marcaaron is eligible for the choreEngineerContributorManagement assigner, not assigning anyone new.

@melvin-bot melvin-bot bot removed the Help Wanted Apply this label when an issue is open to proposals by contributors label Apr 30, 2024
Copy link

melvin-bot bot commented Apr 30, 2024

📣 @jjcoffee 🎉 An offer has been automatically sent to your Upwork account for the Reviewer role 🎉 Thanks for contributing to the Expensify app!

Offer link
Upwork job

Copy link

melvin-bot bot commented Apr 30, 2024

📣 @bernhardoj 🎉 An offer has been automatically sent to your Upwork account for the Contributor role 🎉 Thanks for contributing to the Expensify app!

Offer link
Upwork job
Please accept the offer and leave a comment on the Github issue letting us know when we can expect a PR to be ready for review 🧑‍💻
Keep in mind: Code of Conduct | Contributing 📖

@melvin-bot melvin-bot bot added Reviewing Has a PR in review Weekly KSv2 and removed Daily KSv2 labels May 1, 2024
@bernhardoj
Copy link
Contributor

PR is ready

cc: @jjcoffee

@jjcoffee
Copy link
Contributor

Looks like automation failed here, this hit production May 9, so payment is due May 16. cc @strepanier03

@jjcoffee
Copy link
Contributor

jjcoffee commented May 20, 2024

  • The PR that introduced the bug has been identified. Link to the PR: perf: Cache search options #38207
  • The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake. Link to comment: https://github.com/Expensify/App/pull/38207/files#r1606552466
  • A discussion in #expensify-bugs has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner. Link to discussion: N/A
  • Determine if we should create a regression test for this bug. Yes
  • If we decide to create a regression test for the bug, please propose the regression test steps to ensure the same bug will not reach production again.

Regression Test Proposal

  1. Create a new group chat
  2. Open the search page and verify the group chat is in the search list
  3. Open the group chat and press the header
  4. Press Leave to leave the group
  5. Open the search page again
  6. Verify the group chat isn't in the search list anymore

Do we agree 👍 or 👎

@jjcoffee
Copy link
Contributor

@strepanier03 Checklist complete! Friendly bump for payment (the PR hit production May 9) 🙇

@strepanier03 strepanier03 changed the title [$250] Leaving a group chat with 0 members inside still populates the search as a result [Pay 2024-05-28] [$250] Leaving a group chat with 0 members inside still populates the search as a result May 28, 2024
@strepanier03 strepanier03 added Daily KSv2 and removed Weekly KSv2 labels May 28, 2024
@strepanier03
Copy link
Contributor

Payments for @bernhardoj and @jjcoffee are completed via Upwork, contracts are also closed. Reg test GH is created so this is ready to be closed.

Thank you all!

@strepanier03 strepanier03 changed the title [Pay 2024-05-28] [$250] Leaving a group chat with 0 members inside still populates the search as a result [PAID] [$250] Leaving a group chat with 0 members inside still populates the search as a result May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 Engineering External Added to denote the issue can be worked on by a contributor Reviewing Has a PR in review
Projects
None yet
Development

No branches or pull requests

6 participants