Skip to content

fix(chat): don't apply hard-break newlines to AI-streamed messages#385

Open
FelipeRamos-neuro wants to merge 1 commit into
plmbr:mainfrom
FelipeRamos-neuro:fix/chat-code-block-trailing-whitespace
Open

fix(chat): don't apply hard-break newlines to AI-streamed messages#385
FelipeRamos-neuro wants to merge 1 commit into
plmbr:mainfrom
FelipeRamos-neuro:fix/chat-code-block-trailing-whitespace

Conversation

@FelipeRamos-neuro

Copy link
Copy Markdown

Summary

Fixes #384

  • The chat message renderer (src/chat-sidebar.tsx:891) applied a blanket .replace(/\n/gi, ' \n') hard-break transform to every rendered message, not just user input as the adjacent comment intended.
  • Since this is a raw string transform applied before markdown parsing, it injected trailing double-spaces into every line of AI-streamed fenced code blocks — invisible on screen, but present in the DOM text, corrupting copied code with trailing whitespace (breaking whitespace-sensitive languages like Python, or tripping lint/format diffs after paste).
  • Fix: scope the hard-break transform to msg.from === 'user' only, matching the comment's stated intent. AI-streamed messages already contain well-formed markdown and don't need the hack.

See #384 for the full root-cause writeup and reproduction.

Test plan

  • Full Jest suite passes (29 suites / 371 tests, no regressions)
  • Verified via isolated repro against the pinned react-markdown@9.0.1 + remark-gfm@4.0.0: AI-message code blocks no longer carry trailing whitespace on any line, while user-message hard breaks are preserved
  • Manual verification in a running JupyterLab chat panel (not done — no way to launch the dev UI in this environment)

🤖 Generated with Claude Code

The blanket `.replace(/\n/gi, '  \n')` in the chat message renderer ran
over every message, not just user input as the comment intended. Since
it's a raw string transform applied before markdown parsing, it injected
trailing double-spaces into every line of AI-streamed fenced code
blocks, corrupting copy-pasted code with invisible trailing whitespace.

Scope the hard-break transform to user messages only.
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.

Chat markdown hard-break transform injects trailing whitespace into every line of code blocks

1 participant