stream-chat-react
stream-chat-react copied to clipboard
bug: empty new line is ignored by markdown parser in Message text
Describe the bug
Empty lines are ignored in the message text.
To Reproduce
Steps to reproduce the behavior:
- In message input type text, then add 1+ empty lines with Shift + Enter, type more text
- Send message
- Observe the message text ignoring the empty lines

Expected behavior
Empty lines are kept:

Package version
- stream-chat-react: 10.0.2
~Blocked by https://github.com/GetStream/stream-chat-react/issues/1560.~
@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.
fixed by #2170