Skip to content

fix: ComposeBox - When you click on the mention again, extra characters appear. #61362

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

Merged
merged 5 commits into from
May 12, 2025
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions src/pages/home/report/ReportActionCompose/SuggestionMention.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function SuggestionMention(
// eslint-disable-next-line react-compiler/react-compiler
suggestionValuesRef.current = suggestionValues;

const [reports] = useOnyx(ONYXKEYS.COLLECTION.REPORT);
const [reports] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {canBeMissing: false});

const currentUserPersonalDetails = useCurrentUserPersonalDetails();
const isMentionSuggestionsMenuVisible = !!suggestionValues.suggestedMentions.length && suggestionValues.shouldShowSuggestionMenu;
Expand Down Expand Up @@ -190,6 +190,12 @@ function SuggestionMention(
[formatLoginPrivateDomain],
);

function getOriginalMentionText(inputValue: string, atSignIndex: number) {
const rest = inputValue.slice(atSignIndex);
const mentionMatch = rest.match(/^[@\w.\-+]+/); // capture till space or special characters not in emails
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Krishna2323 won't we use MENTION_BREAKER as you mentioned in your proposal? If not can you put this new regrex into a const?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, my mistake — I've updated it to use MENTION_BREAKER.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Krishna2323. Can you elaborate on why we need to use both .search and .match for MENTION_BREAKER? It look like MENTION_BREAKER is not used anywhere

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hoangzinh, I got this solution from AI, and after prompting again, I received the following clarification and updated the code accordingly. I’ve tested the solution as well:

You don’t need both — .search() is sufficient to locate the first breaking character (space, emoji, etc.).
If .match() is also used, it's likely unnecessary unless you want to inspect the actual matched breakers.
In clean implementation, use only .search() with MENTION_BREAKER.

return mentionMatch?.[0] ?? '';
}

/**
* Replace the code of mention and update selection
*/
Expand All @@ -201,8 +207,8 @@ function SuggestionMention(
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({
Expand All @@ -216,16 +222,7 @@ function SuggestionMention(
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],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it have a lint issue if we use previous style? I prefer spread in multiple line as previously, it makes code cleaner

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so, because printWidth is set to 190 and this line only includes 157 characters.

printWidth: 190,

);

/**
Expand Down
Loading