cleanup memory in chat (#4073)
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect, useRef } from 'react';
|
||||||
import ReactMarkdown from 'react-markdown';
|
import ReactMarkdown from 'react-markdown';
|
||||||
import remarkGfm from 'remark-gfm';
|
import remarkGfm from 'remark-gfm';
|
||||||
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
|
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
|
||||||
@@ -17,16 +17,31 @@ interface MarkdownContentProps {
|
|||||||
|
|
||||||
const CodeBlock = ({ language, children }: { language: string; children: string }) => {
|
const CodeBlock = ({ language, children }: { language: string; children: string }) => {
|
||||||
const [copied, setCopied] = useState(false);
|
const [copied, setCopied] = useState(false);
|
||||||
|
const timeoutRef = useRef<number | null>(null);
|
||||||
|
|
||||||
const handleCopy = async () => {
|
const handleCopy = async () => {
|
||||||
try {
|
try {
|
||||||
await navigator.clipboard.writeText(children);
|
await navigator.clipboard.writeText(children);
|
||||||
setCopied(true);
|
setCopied(true);
|
||||||
setTimeout(() => setCopied(false), 2000); // Reset after 2 seconds
|
|
||||||
|
if (timeoutRef.current) {
|
||||||
|
window.clearTimeout(timeoutRef.current);
|
||||||
|
}
|
||||||
|
|
||||||
|
timeoutRef.current = window.setTimeout(() => setCopied(false), 2000);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Failed to copy text: ', err);
|
console.error('Failed to copy text: ', err);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
return () => {
|
||||||
|
if (timeoutRef.current) {
|
||||||
|
window.clearTimeout(timeoutRef.current);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="relative group w-full">
|
<div className="relative group w-full">
|
||||||
<button
|
<button
|
||||||
|
|||||||
@@ -141,11 +141,16 @@ export default function ProgressiveMessageList({
|
|||||||
|
|
||||||
// Force complete rendering when search is active
|
// Force complete rendering when search is active
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
// Only add listener if we're actually loading
|
||||||
|
if (!isLoading) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const handleKeyDown = (e: KeyboardEvent) => {
|
const handleKeyDown = (e: KeyboardEvent) => {
|
||||||
const isMac = window.electron.platform === 'darwin';
|
const isMac = window.electron.platform === 'darwin';
|
||||||
const isSearchShortcut = (isMac ? e.metaKey : e.ctrlKey) && e.key === 'f';
|
const isSearchShortcut = (isMac ? e.metaKey : e.ctrlKey) && e.key === 'f';
|
||||||
|
|
||||||
if (isSearchShortcut && isLoading) {
|
if (isSearchShortcut) {
|
||||||
// Immediately render all messages when search is triggered
|
// Immediately render all messages when search is triggered
|
||||||
setRenderedCount(messages.length);
|
setRenderedCount(messages.length);
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
@@ -248,14 +253,14 @@ export default function ProgressiveMessageList({
|
|||||||
renderedCount,
|
renderedCount,
|
||||||
renderMessage,
|
renderMessage,
|
||||||
isUserMessage,
|
isUserMessage,
|
||||||
hasContextHandlerContent,
|
|
||||||
getContextHandlerType,
|
|
||||||
chat,
|
chat,
|
||||||
append,
|
append,
|
||||||
appendMessage,
|
appendMessage,
|
||||||
toolCallNotifications,
|
toolCallNotifications,
|
||||||
onScrollToBottom,
|
|
||||||
isStreamingMessage,
|
isStreamingMessage,
|
||||||
|
hasContextHandlerContent,
|
||||||
|
getContextHandlerType,
|
||||||
|
onScrollToBottom,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in New Issue
Block a user