Skip to content

[Due for payment 2025-07-07] [$250] ComposeBox - When you click on the mention again, extra characters appear #60804

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.32-0
Reproducible in staging?: Yes
Reproducible in production?: Yes
If this was caught on HybridApp, is this reproducible on New Expensify Standalone?: No, reproducible on hybrid only
If this was caught during regression testing, add the test name, ID and link from TestRail: https://expensify.testrail.io/index.php?/tests/view/5995329
Email or phone of affected tester (no customers): sustinov@applausemail.com
Issue reported by: Applause Internal Team
Device used: Macbook/13.7.5/Chrome, OnePlus 9 PRO/Android 14/Chrome, iPhone 12 PRO/iOS 18.4.1
App Component: Chat Report View

Action Performed:

  1. Open https://staging.new.expensify.com
  2. Log in with any HT account
  3. Go to any conversation or create one
  4. In the Compose box, type “ @ ”
  5. Select any user to mention or enter any username
  6. Click on the login of the user in the mention
  7. In the window that appears, click on the same user again
  8. Repeat steps 6-7 several times

Expected Result:

When you click on the mention again, nothing should change

Actual Result:

When you click on a mention again, extra characters appear at the end of the mention.

Workaround:

Unknown

Platforms:

  • Android: Standalone
  • Android: HybridApp
  • Android: mWeb Chrome
  • iOS: Standalone
  • iOS: HybridApp
  • iOS: mWeb Safari
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

1.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021915530953266836404
  • Upwork Job ID: 1915530953266836404
  • Last Price Increase: 2025-04-24
  • Automatic offers:
    • Krishna2323 | Contributor | 107127961
Issue OwnerCurrent Issue Owner: @
Issue OwnerCurrent Issue Owner: @Krishna2323

Activity

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

    @melvin-bot

    Triggered auto assignment to @lydiabarclay (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. Krishna2323 commented on Apr 24, 2025

    @Krishna2323
    Contributor

    🚨 Edited by proposal-police: This proposal was edited at 2025-04-29 20:36:16 UTC.

    Proposal

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

    • When a user clicks on a mention suggestion (e.g., @abcd@gmail.com) after partially typing it (e.g., @abcd), the mention is inserted correctly, but extra characters from the original input (like gmail.com) remain after the inserted mention. This results in duplicated or malformed mentions like @abcd@gmail.com gmail.com.

    What is the root cause of that problem?

    • The issue stems from how the commentAfterMention is computed when inserting the selected mention.
    • Currently, the logic slices the comment based on a fixed offset after the @ symbol — it doesn't account for the full original mention text (like @abcd@gmail.com). As a result, the remaining part of the original input (e.g., gmail.com) gets preserved and appended after the newly inserted mention.

    const insertSelectedMention = useCallback(
    (highlightedMentionIndexInner: number) => {
    const commentBeforeAtSign = value.slice(0, suggestionValues.atSignIndex);
    const mentionObject = suggestionValues.suggestedMentions.at(highlightedMentionIndexInner);
    if (!mentionObject || highlightedMentionIndexInner === -1) {
    return;
    }
    const mentionCode = getMentionCode(mentionObject, suggestionValues.prefixType);
    const commentAfterMention = value.slice(suggestionValues.atSignIndex + suggestionValues.mentionPrefix.length + 1);
    updateComment(`${commentBeforeAtSign}${mentionCode} ${trimLeadingSpace(commentAfterMention)}`, true);
    const selectionPosition = suggestionValues.atSignIndex + mentionCode.length + CONST.SPACE_LENGTH;
    setSelection({
    start: selectionPosition,
    end: selectionPosition,
    });
    suggestionInsertionIndexRef.current = selectionPosition;
    setSuggestionValues((prevState) => ({
    ...prevState,
    suggestedMentions: [],
    shouldShowSuggestionMenu: false,
    }));
    },

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

    • Instead of slicing a fixed number of characters after the @, dynamically determine the length of the original mention string (e.g., @abcd@gmail.com) by matching the text from atSignIndex.

    • Then, slice the value only after that full match to get the accurate commentAfterMention.

    • We will use MENTION_BREAKER to get the remaining part of the metion.

      App/src/CONST.ts

      Lines 3494 to 3498 in 3885a40

      // Define the regular expression pattern to find a potential end of a mention suggestion:
      // It might be a space, a newline character, an emoji, or a special character (excluding underscores & tildes, which might be used in usernames)
      get MENTION_BREAKER() {
      return new RegExp(`[\\n\\s]|${this.SPECIAL_CHAR.source}|${this.EMOJI.source}`, 'gu');
      },

    • This ensures we don’t re-append any part of the original partial mention.

    Code diff
    +  function getOriginalMentionText(valuee: string, atSignIndex: number) {
    +     const rest = valuee.slice(atSignIndex);
    +     const mentionMatch = rest.match(/^[@\w.\-+]+/); // capture till space or special characters not in emails
    +     return mentionMatch?.[0] ?? '';
    +  }
    
      const insertSelectedMention = useCallback(
          (highlightedMentionIndexInner: number) => {
              const commentBeforeAtSign = value.slice(0, suggestionValues.atSignIndex);
              const mentionObject = suggestionValues.suggestedMentions.at(highlightedMentionIndexInner);
              if (!mentionObject || highlightedMentionIndexInner === -1) {
                  return;
              }
              const mentionCode = getMentionCode(mentionObject, suggestionValues.prefixType);
    -         const commentAfterMention = value.slice(suggestionValues.atSignIndex + suggestionValues.mentionPrefix.length + 1);
    +         const originalMention = getOriginalMentionText(value, suggestionValues.atSignIndex);
    +         const commentAfterMention = value.slice(suggestionValues.atSignIndex + originalMention.length);
    
              updateComment(`${commentBeforeAtSign}${mentionCode} ${trimLeadingSpace(commentAfterMention)}`, true);
              const selectionPosition = suggestionValues.atSignIndex + mentionCode.length + CONST.SPACE_LENGTH;
              setSelection({
                  start: selectionPosition,
                  end: selectionPosition,
              });
              suggestionInsertionIndexRef.current = selectionPosition;
              setSuggestionValues((prevState) => ({
                  ...prevState,
                  suggestedMentions: [],
                  shouldShowSuggestionMenu: false,
              }));
          },
    -     [
    -         value,
    -         suggestionValues.atSignIndex,
    -         suggestionValues.suggestedMentions,
    -         suggestionValues.prefixType,
    -         suggestionValues.mentionPrefix.length,
    -         getMentionCode,
    -         updateComment,
    -         setSelection,
    -     ],
    +     [
    +         value,
    +         suggestionValues.atSignIndex,
    +         suggestionValues.suggestedMentions,
    +         suggestionValues.prefixType,
    +         getMentionCode,
    +         updateComment,
    +         setSelection,
    +     ],
      );

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

    • We can create test for insertSelectedMention to test different scenarios.

    What alternative solutions did you explore? (Optional)

    N/A

    Result

  4. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Apr 24, 2025
  5. changed the title [-]ComposeBox - When you click on the mention again, extra characters appear[/-] [+][$250] ComposeBox - When you click on the mention again, extra characters appear[/+] on Apr 24, 2025
  6. melvin-bot commented on Apr 24, 2025

    @melvin-bot
  7. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Apr 24, 2025
  8. melvin-bot commented on Apr 24, 2025

    @melvin-bot

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

  9. hoangzinh commented on Apr 27, 2025

    @hoangzinh
    Contributor

    @Krishna2323 can you check if we have any existing regrex for this const mentionMatch = rest.match(/^[@\w.\-+]+/);?

  10. Krishna2323 commented on Apr 28, 2025

    @Krishna2323
    Contributor

    @hoangzinh, I think we can use MENTION_BREAKER. It works well.

    App/src/CONST.ts

    Lines 3494 to 3498 in 3885a40

    // Define the regular expression pattern to find a potential end of a mention suggestion:
    // It might be a space, a newline character, an emoji, or a special character (excluding underscores & tildes, which might be used in usernames)
    get MENTION_BREAKER() {
    return new RegExp(`[\\n\\s]|${this.SPECIAL_CHAR.source}|${this.EMOJI.source}`, 'gu');
    },

    Monosnap.screencast.2025-04-28.15-15-20.mp4
  11. hoangzinh commented on Apr 28, 2025

    @hoangzinh
    Contributor

    Cool. Can you add it to your proposal? Also, you can put code diff into details expand block to help your proposal look cleaner/

  12. 70 remaining items

  13. lydiabarclay commented on Jul 2, 2025

    @lydiabarclay
    Contributor

    Hey @hoangzinh I'm going to be OOO starting Friday through Tuesday, so to make sure that payment happens on time, can you please fill out the BZ checklist asap? I'll tag another Concierge to have eyes on it on 7/7

  14. hoangzinh commented on Jul 3, 2025

    @hoangzinh
    Contributor

    BugZero Checklist:

    • [Contributor] Classify the bug:
    Bug classification

    Source of bug:

    • 1a. Result of the original design (eg. a case wasn't considered)
    • 1b. Mistake during implementation
    • 1c. Backend bug
    • 1z. Other:

    Where bug was reported:

    • 2a. Reported on production (eg. bug slipped through the normal regression and PR testing process on staging)
    • 2b. Reported on staging (eg. found during regression or PR testing)
    • 2d. Reported on a PR
    • 2z. Other:

    Who reported the bug:

    • 3a. Expensify user
    • 3b. Expensify employee
    • 3c. Contributor
    • 3d. QA
    • 3z. Other:

    Regression Test Proposal

    Test:

    1. Go to any conversation or create a new one.
    2. In the compose box, type “@”.
    3. Select any user from the list or manually enter a username.
    4. Click in the middle of the username within the mention.
    5. In the window that appears, click on the same user again.
    6. Verify that the cursor is placed after the mention and no extra characters are added.

    Do we agree 👍 or 👎

  15. lydiabarclay commented on Jul 3, 2025

    @lydiabarclay
    Contributor

    Thanks @hoangzinh - apparently I'm not able to round-robin-reassign BZ issues, so I will just be issuing the payment when I'm back on 7/9 - thanks for your understanding!

  16. hoangzinh commented on Jul 3, 2025

    @hoangzinh
    Contributor

    No worry, I'm fine with that plan. @lydiabarclay

  17. melvin-bot commented on Jul 7, 2025

    @melvin-bot

    This issue has not been updated in over 15 days. @dangrous, @hoangzinh, @Krishna2323, @lydiabarclay 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!

  18. dangrous commented on Jul 7, 2025

    @dangrous
    Contributor

    Keeping as weekly to handle payment when @lydiabarclay is back!

  19. lydiabarclay commented on Jul 9, 2025

    @lydiabarclay
    Contributor

    Payment Summary

    Contributor: @Krishna2323 paid $250 via Upwork
    Contributor+: @hoangzinh due $250 via NewDot

    ✅ Regression test filed

  20. hoangzinh commented on Jul 10, 2025

    @hoangzinh
    Contributor

    Thanks @lydiabarclay. I requested in ND

  21. garrettmknight commented on Jul 21, 2025

    @garrettmknight
    Contributor

    $250 approved for @hoangzinh

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.ExternalAdded to denote the issue can be worked on by a contributorReviewingHas a PR in reviewWeeklyKSv2

Type

No type

Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions