From 6951f9d5f0908117e8d883add7196651a7e0e47b Mon Sep 17 00:00:00 2001 From: Vishal Narkhede Date: Thu, 19 Oct 2023 16:53:41 +0200 Subject: [PATCH] fix: issue with String.replaceAll being undefined function --- .../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; + }); }, '') : '';