diff --git a/src/frontend/src/modals/formModal/chatMessage/codeBlock/index.tsx b/src/frontend/src/modals/formModal/chatMessage/codeBlock/index.tsx index c78974a3c..884215ebb 100644 --- a/src/frontend/src/modals/formModal/chatMessage/codeBlock/index.tsx +++ b/src/frontend/src/modals/formModal/chatMessage/codeBlock/index.tsx @@ -1,5 +1,5 @@ import { IconCheck, IconClipboard, IconDownload } from "@tabler/icons-react"; -import { FC, memo, useState } from "react"; +import { useState } from "react"; import { Prism as SyntaxHighlighter } from "react-syntax-highlighter"; import { oneDark } from "react-syntax-highlighter/dist/cjs/styles/prism"; import { programmingLanguages } from "../../../../utils"; @@ -9,7 +9,7 @@ interface Props { value: string; } -export const CodeBlock: FC = memo(({ language, value }) => { +export function CodeBlock({ language, value }) { const [isCopied, setIsCopied] = useState(false); const copyToClipboard = () => { @@ -63,7 +63,7 @@ export const CodeBlock: FC = memo(({ language, value }) => { = memo(({ language, value }) => { ); -}); +} CodeBlock.displayName = "CodeBlock"; diff --git a/src/frontend/src/modals/formModal/chatMessage/index.tsx b/src/frontend/src/modals/formModal/chatMessage/index.tsx index 93ef22bc2..4e941e278 100644 --- a/src/frontend/src/modals/formModal/chatMessage/index.tsx +++ b/src/frontend/src/modals/formModal/chatMessage/index.tsx @@ -1,6 +1,6 @@ import Convert from "ansi-to-html"; import { ChevronDown } from "lucide-react"; -import { useState } from "react"; +import { useMemo, useState } from "react"; import ReactMarkdown from "react-markdown"; import rehypeMathjax from "rehype-mathjax"; import remarkGfm from "remark-gfm"; @@ -75,47 +75,60 @@ export default function ChatMessage({
- - ▍ - + components={{ + code: ({ + node, + inline, + className, + children, + ...props + }) => { + if (children.length) { + if (children[0] === "▍") { + return ( + + ▍ + + ); + } + + children[0] = (children[0] as string).replace( + "`▍`", + "▍" + ); + } + + const match = /language-(\w+)/.exec( + className || "" ); - } - children[0] = (children[0] as string).replace( - "`▍`", - "▍" - ); - } - - const match = /language-(\w+)/.exec(className || ""); - - return !inline ? ( - - ) : ( - - {children} - - ); - }, - }} - > - {chat.message.toString()} - + return !inline ? ( + + ) : ( + + {children} + + ); + }, + }} + > + {chat.message.toString()} + + ), + [chat.message.toString()] + )}
{chat.files && (