Skip to content

fix(react): preserve newlines when editing multi-line messages - #1440

Open
swarnendusahu10-dotcom wants to merge 1 commit into
RocketChat:developfrom
swarnendusahu10-dotcom:fix/issue-1430-multiline-message-edit
Open

swarnendusahu10-dotcom wants to merge 1 commit into
RocketChat:developfrom
swarnendusahu10-dotcom:fix/issue-1430-multiline-message-edit

Conversation

@swarnendusahu10-dotcom

Copy link
Copy Markdown
Contributor

Summary of Changes

Closes #1430.

In packages/react/src/views/ChatInput/ChatInput.js, handleEditMessage previously sanitized messages before dispatching the update:

const res = await RCInstance.updateMessage(
  editMessageId,
  message.replace(/\n/g, '\\n')
);

The Problem

Escaping \n into \\n sends the literal two-character string "\n" over Rocket.Chat's REST API instead of a newline control character. When the server persists and broadcasts the edited message, EmbeddedChat displays literal backslash-n (\n) characters instead of true line breaks, corrupting formatted multi-line messages, bulleted lists, and paragraphs.

Fix

  • Passed the unescaped message string directly to RCInstance.updateMessage(editMessageId, message), identical to how handleSendNewMessage transmits new messages.
  • Verified that Rocket.Chat's REST API natively handles real newline characters without requiring artificial backslash escaping.

Testing & Verification

  • Verified editing single-line messages.
  • Verified editing multi-line paragraphs and bullet lists retains true line breaks.
  • Verified code blocks containing intentional \n characters are preserved.
  • Formatted with prettier@2.8.1 matching .prettierrc (All matched files use Prettier code style!).
  • Monorepo production build passes cleanly (yarn workspace @embeddedchat/react build).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: editing a multi-line message saves literal \n instead of line breaks

1 participant