Skip to content

Commit 465db02

Browse files
author
Tom Hutman
committed
don't try to replace mentions with spans if array is empty
1 parent ec0f638 commit 465db02

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/utils.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,6 @@ const mentionsMarkdownPlugin = <
117117
.filter(Boolean)
118118
.map(escapeRegExp);
119119

120-
const mentionedUsersRegex = new RegExp(
121-
mentioned_usernames.map((username) => `@${username}`).join('|'),
122-
'g',
123-
);
124-
125120
function replace(match: string) {
126121
const usernameOrId = match.replace('@', '');
127122
const user = mentioned_users.find(
@@ -135,6 +130,13 @@ const mentionsMarkdownPlugin = <
135130
}
136131

137132
const transform = <T extends unknown>(markdownAST: T) => {
133+
if (!mentioned_usernames.length) {
134+
return markdownAST;
135+
}
136+
const mentionedUsersRegex = new RegExp(
137+
mentioned_usernames.map((username) => `@${username}`).join('|'),
138+
'g',
139+
);
138140
findAndReplace(markdownAST, mentionedUsersRegex, replace);
139141
return markdownAST;
140142
};

0 commit comments

Comments
 (0)