Skip to content

fix(mentions): suppress mention autocomplete on email and domain patt… - #1406

Open
swarnendusahu10-dotcom wants to merge 1 commit into
RocketChat:developfrom
swarnendusahu10-dotcom:fix/issue-1287-mention-email-trigger
Open

swarnendusahu10-dotcom wants to merge 1 commit into
RocketChat:developfrom
swarnendusahu10-dotcom:fix/issue-1287-mention-email-trigger

Conversation

@swarnendusahu10-dotcom

Copy link
Copy Markdown
Contributor

Description

Resolves #1287

Prevents the member mention autocomplete popup from firing and intercepting keystrokes when typing an email address or web domain (e.g. contact admin @example.com, @gmail.com, or @company.io).


Problem & Background

  1. Unwanted Popup on Email/Domain Typing:
    Whenever @ is typed after a space, EmbeddedChat enters mention-reading mode. If the user is typing an email address or domain, the popup appears and flickers against partial substring matches of room members.
  2. Enter Key Hijacking:
    Because the popup is active in the background, pressing Enter to send the message intercepts the keypress. Instead of sending the email text, it auto-completes whichever random member happened to be highlighted (e.g. replacing @example.com with @Alexandre ), corrupting the user's message.
  3. Flaw of Previous Attempt (PR fix: resolve email mention trigger and paginate member list retrieval #1304):
    A previous attempt in PR fix: resolve email mention trigger and paginate member list retrieval #1304 tried to unconditionally disable mentions whenever a dot (.) was present. This was rejected because Rocket.Chat usernames explicitly support dots (e.g. @john.doe), which broke legitimate user mentions.

Solution

  • Universal Domain Detection via Dot (.): Rather than maintaining a brittle, hardcoded list of 1,500+ top-level domains (.com, .org, .net, .io, .edu, etc.), any email or domain query universally contains a dot separator (.).
  • Instant Dismissal & Disarming: The instant a dot is typed in a domain pattern (e.g. @example.), the hook checks if any room member matches. If no member matches (!isValidUsername), it immediately closes the popup (setShowMembersList(false)), clears filteredMembers, and resets mentionIndex to -1.
  • Restores Enter Behavior: By disarming the mention index, pressing Enter cleanly sends the message with the email text intact instead of inserting an unwanted member.
  • Preserves Dot Usernames: If a teammate actually has a dot in their username (e.g. @john.doe), isValidUsername evaluates to true, so suggestions remain visible and selectable.
  • Typo Recovery: Supports backspacing out of typos without prematurely destroying mention state.

Changes Made

  • Modified packages/react/src/hooks/useSearchMentionUser.js:
    if (query.includes('.') && !isValidUsername) {
      setShowMembersList(false);
      setFilteredMembers([]);
      setMentionIndex(-1);
      return;
    }

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mention autocomplete triggers on email addresses

1 participant