From af9050a3fb46346ed5d0ba387b42d5a85d937e93 Mon Sep 17 00:00:00 2001 From: Vishal Narkhede Date: Fri, 20 Oct 2023 10:39:03 +0200 Subject: [PATCH] fix: issue with String.replaceAll being undefined function (#2271) --- .../ChannelPreview/hooks/useLatestMessagePreview.ts | 4 +++- .../components/Message/MessageSimple/utils/renderText.tsx | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/package/src/components/ChannelPreview/hooks/useLatestMessagePreview.ts b/package/src/components/ChannelPreview/hooks/useLatestMessagePreview.ts index eebf1fe1ab..b728a0e9c5 100644 --- a/package/src/components/ChannelPreview/hooks/useLatestMessagePreview.ts +++ b/package/src/components/ChannelPreview/hooks/useLatestMessagePreview.ts @@ -63,7 +63,9 @@ const getMentionUsers = < }, ''); // escape special characters - return mentionUserString.replaceAll(/[.*+?^${}()|[\]\\]/g, '\\$&'); + return mentionUserString.replace(/[.*+?^${}()|[\]\\]/g, function (match) { + return '\\' + match; + }); } return ''; diff --git a/package/src/components/Message/MessageSimple/utils/renderText.tsx b/package/src/components/Message/MessageSimple/utils/renderText.tsx index e533655b62..93b7808ed7 100644 --- a/package/src/components/Message/MessageSimple/utils/renderText.tsx +++ b/package/src/components/Message/MessageSimple/utils/renderText.tsx @@ -226,7 +226,10 @@ export const renderText = < if (userName) { acc += `${acc.length ? '|' : ''}@${userName}`; } - return acc.replaceAll(/[.*+?^${}()|[\]\\]/g, '\\$&'); + + return acc.replace(/[.*+?^${}()|[\]\\]/g, function (match) { + return '\\' + match; + }); }, '') : '';