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

mWeb - Group chat - After removing member, admin leaving group chat app crashes #48072

Closed
1 of 6 tasks
IuliiaHerets opened this issue Aug 27, 2024 · 17 comments
Closed
1 of 6 tasks
Assignees
Labels
Bug Something is broken. Auto assigns a BugZero manager. Engineering Monthly KSv2 Reviewing Has a PR in review

Comments

@IuliiaHerets
Copy link

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.0.25-1
Reproducible in staging?: Y
Reproducible in production?: N
If this was caught during regression testing, add the test name, ID and link from TestRail: https://expensify.testrail.io/index.php?/tests/view/4895730
Issue reported by: Applause Internal Team

Action Performed:

  1. Go to https://staging.new.expensify.com/home
  2. Tap fab -- start chat
  3. Select a user and create a group
  4. Tap header -- members
  5. Long press the members and select "remove" member
  6. Navigate back to "details" page and tap "Leave"

Expected Result:

After removing member, admin leaving group chat app must not crash.

Actual Result:

After removing member, admin leaving group chat app crashes.

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

2708_2.txt

Bug6583856_1724733050917.sh.mp4

View all open jobs on GitHub

@IuliiaHerets IuliiaHerets added DeployBlockerCash This issue or pull request should block deployment Bug Something is broken. Auto assigns a BugZero manager. labels Aug 27, 2024
Copy link

melvin-bot bot commented Aug 27, 2024

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

Copy link

melvin-bot bot commented Aug 27, 2024

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

@melvin-bot melvin-bot bot added the Daily KSv2 label Aug 27, 2024
@github-actions github-actions bot added Engineering Hourly KSv2 and removed Daily KSv2 labels Aug 27, 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.

@daledah
Copy link
Contributor

daledah commented Aug 27, 2024

Proposal

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

After removing member, admin leaving group chat app crashes.

What is the root cause of that problem?

draftMessage here somehow turns to empty object {}:

const [draftMessage] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS}${originalReportID}`, {
selector: (draftMessagesForReport) => {
const matchingDraftMessage = draftMessagesForReport?.[action.reportActionID];
return typeof matchingDraftMessage === 'string' ? matchingDraftMessage : matchingDraftMessage?.message;
},
});

That fails the line here even though we have a safeguard for undefined value:

const parsedEmojis = text.match(CONST.REGEX.EMOJIS);

App/src/libs/EmojiUtils.ts

Lines 283 to 285 in 1ea6781

if (!text) {
return [];
}

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

Check type of text as string instead of just undefined value:

App/src/libs/EmojiUtils.ts

Lines 283 to 285 in 1ea6781

if (!text) {
return [];
}

@bernhardoj
Copy link
Contributor

Proposal

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

App crashes when leaving a group chat as the last member.

What is the root cause of that problem?

The error comes when we try to extract the emoji from the draft message here because the draftMessage is an empty object instead of a string, so {}.match will crash.

const [draft, setDraft] = useState(() => {
if (draftMessage) {
emojisPresentBefore.current = EmojiUtils.extractEmojis(draftMessage);
}

App/src/libs/EmojiUtils.ts

Lines 282 to 288 in 9ddca5c

function extractEmojis(text: string): Emoji[] {
if (!text) {
return [];
}
// Parse Emojis including skin tones - Eg: ['👩🏻', '👩🏻', '👩🏼', '👩🏻', '👩🏼', '👩']
const parsedEmojis = text.match(CONST.REGEX.EMOJIS);

The reason it's an empty object is that after we leave the group, the report is deleted, and report.reportID becomes an empty string because we default it to an empty string,

const report = useMemo(
(): OnyxTypes.Report => ({
lastReadTime: reportOnyx?.lastReadTime,
reportID: reportOnyx?.reportID ?? '',

so, when we try to fetch the draft, it fetches the onyx collection (reportActionsDrafts_) which is an empty object because we don't have any draft.

const originalReportID = useMemo(() => ReportUtils.getOriginalReportID(report.reportID, action) ?? '-1', [report.reportID, action]);
const [draftMessage] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS}${originalReportID}`, {
selector: (draftMessagesForReport) => {
const matchingDraftMessage = draftMessagesForReport?.[action.reportActionID];
return typeof matchingDraftMessage === 'string' ? matchingDraftMessage : matchingDraftMessage?.message;
},
});

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

Use || instead of ?? so it will fallback to -1 if it's an empty string.

const originalReportID = useMemo(() => ReportUtils.getOriginalReportID(report.reportID, action) ?? '-1', [report.reportID, action]);
const [draftMessage] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS}${originalReportID}`, {

OR

Don't default to an empty string

const report = useMemo(
(): OnyxTypes.Report => ({
lastReadTime: reportOnyx?.lastReadTime,
reportID: reportOnyx?.reportID ?? '',

@cristipaval
Copy link
Contributor

@bernhardoj could you also find the offending PR?

@melvin-bot melvin-bot bot added Reviewing Has a PR in review Weekly KSv2 and removed Hourly KSv2 labels Aug 27, 2024
@bernhardoj
Copy link
Contributor

It happens after #47866

@bernhardoj
Copy link
Contributor

PR is ready!

@puneetlath
Copy link
Contributor

@cristipaval confirmed it's fixed on staging. Demoting.

@puneetlath puneetlath removed the DeployBlockerCash This issue or pull request should block deployment label Aug 27, 2024
@melvin-bot melvin-bot bot added Monthly KSv2 and removed Weekly KSv2 labels Sep 19, 2024
Copy link

melvin-bot bot commented Sep 19, 2024

This issue has not been updated in over 15 days. @puneetlath, @cristipaval, @bernhardoj 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!

@puneetlath
Copy link
Contributor

Does anyone need to be paid out here?

@bernhardoj
Copy link
Contributor

Yes, I think it's only me

@puneetlath
Copy link
Contributor

Is it this PR? #48096

Looks like @hungvu193 reviewed that?

@hungvu193
Copy link
Contributor

Is it this PR? #48096

Looks like @hungvu193 reviewed that?

Ah yes but it's regression so no payment needed for me

@puneetlath
Copy link
Contributor

Ok thanks for the clarifications.

Payment summary:

@bernhardoj
Copy link
Contributor

Requested in ND

@JmillsExpensify
Copy link

$250 approved for @bernhardoj

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. Engineering Monthly KSv2 Reviewing Has a PR in review
Projects
None yet
Development

No branches or pull requests

7 participants