Merge pull request #6412 from menloresearch/fix/render-new-line

fix: render new line for user message
This commit is contained in:
Faisal Amir 2025-09-11 13:29:18 +07:00 committed by GitHub
commit 198955285e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 2 deletions

View File

@ -75,6 +75,7 @@
"react-textarea-autosize": "^8.5.9",
"rehype-katex": "^7.0.1",
"rehype-raw": "^7.0.0",
"remark-breaks": "^4.0.0",
"remark-emoji": "^5.0.1",
"remark-gfm": "^4.0.1",
"remark-math": "^6.0.0",

View File

@ -3,6 +3,7 @@ import ReactMarkdown, { Components } from 'react-markdown'
import remarkGfm from 'remark-gfm'
import remarkEmoji from 'remark-emoji'
import remarkMath from 'remark-math'
import remarkBreaks from 'remark-breaks'
import rehypeKatex from 'rehype-katex'
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter'
import * as prismStyles from 'react-syntax-highlighter/dist/cjs/styles/prism'
@ -162,8 +163,13 @@ function RenderMarkdownComponent({
// Memoize the remarkPlugins to prevent unnecessary re-renders
const remarkPlugins = useMemo(() => {
// Using a simpler configuration to avoid TypeScript errors
return [remarkGfm, remarkMath, remarkEmoji]
}, [])
const basePlugins = [remarkGfm, remarkMath, remarkEmoji]
// Add remark-breaks for user messages to handle single newlines as line breaks
if (isUser) {
basePlugins.push(remarkBreaks)
}
return basePlugins
}, [isUser])
// Memoize the rehypePlugins to prevent unnecessary re-renders
const rehypePlugins = useMemo(() => {