diff --git a/src/components/Markdown.tsx b/src/components/Markdown.tsx index abc78778..c5574ab8 100644 --- a/src/components/Markdown.tsx +++ b/src/components/Markdown.tsx @@ -52,14 +52,21 @@ type MarkdownProps = { isLoading: boolean; onPrompt?: (prompt: string) => void; children: string; + className?: string; }; -function Markdown({ previewCode, isLoading, onPrompt, children }: MarkdownProps) { +function Markdown({ + previewCode, + isLoading, + onPrompt, + children, + className = "message-text", +}: MarkdownProps) { const style = useColorModeValue(oneLight, oneDark); return ( (null); const meta = useMemo(getMetaKey, []); + const { isOpen, onToggle: originalOnToggle } = useDisclosure(); + const isLongMessage = text.length > 5000; + const displaySummaryText = !isOpen && (summaryText || isLongMessage); + + // Wrap the onToggle function with startTransition, state update should be deferred due to long message + // https://reactjs.org/docs/error-decoder.html?invariant=426 + const onToggle = () => { + startTransition(() => { + originalOnToggle(); + }); + }; useEffect(() => { if (settings.countTokens) { @@ -334,6 +347,14 @@ function MessageBase({ + { + // only display the button before message if the message is too long and toggled + !editing && isLongMessage && isOpen ? ( + + ) : undefined + } {editing ? ( // eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
@@ -381,9 +402,21 @@ function MessageBase({
) : ( - - {summaryText || text} - + <> + + {displaySummaryText ? summaryText || text.slice(0, 500).trim() : text} + + {isLongMessage ? ( + + ) : undefined} + )}