stream-chat-react icon indicating copy to clipboard operation
stream-chat-react copied to clipboard

bug: empty new line is ignored by markdown parser in Message text

Open MartinCupela opened this issue 3 years ago • 2 comments

Describe the bug

Empty lines are ignored in the message text.

To Reproduce

Steps to reproduce the behavior:

  1. In message input type text, then add 1+ empty lines with Shift + Enter, type more text
  2. Send message
  3. Observe the message text ignoring the empty lines

image

Expected behavior

Empty lines are kept:

image

Package version

  • stream-chat-react: 10.0.2

MartinCupela avatar Sep 16 '22 11:09 MartinCupela

~Blocked by https://github.com/GetStream/stream-chat-react/issues/1560.~

arnautov-anton avatar Sep 19 '22 14:09 arnautov-anton

@MartinCupela Found a "solution"...don't think you're going to like it but it worked for me :) In the MessageText component you can add a step after the messageTextToRender to doubly replace all new lines to this:

messageTextToRender = messageTextToRender?.replaceAll("\n\n", "\n  ‎  \n").replaceAll("\n", "\n  \n")

Where the first replaceAll("\n\n", "\n ‎ \n") has a unicode empty character "U+200E" between the two \n. If you copy that exactly it will unfortunately work. For some reason, this is the only solution I've found to work.

Here is the MessageText component with a little more context:

const { t, userLanguage } = useTranslationContext("MessageText")
const message = propMessage || contextMessage
const hasAttachment = messageHasAttachments(message)

let messageTextToRender =
  message.i18n?.[`${userLanguage}_text` as `${TranslationLanguages}_text`] || message.text

messageTextToRender = messageTextToRender
  ?.replaceAll("\n\n", "\n  ‎  \n")
  .replaceAll("\n", "\n  \n")

const messageText = useMemo(
  () => renderText(messageTextToRender, message.mentioned_users),
  [message.mentioned_users, messageTextToRender]
)

const wrapperClass = customWrapperClass || "str-chat__message-text"
const innerClass =
  customInnerClass || `str-chat__message-text-inner str-chat__message-${theme}-text-inner`

if (!messageTextToRender && !message.quoted_message) return null

Don't ask me how or why this works, but if you're in a pinch it'll do the job.

barrelmaker avatar Sep 27 '22 21:09 barrelmaker

fixed by #2170

MartinCupela avatar Nov 28 '23 09:11 MartinCupela