cleanup memory in chat (#4073)

This commit is contained in:
Zane
2025-08-13 13:56:07 -07:00
committed by GitHub
parent c42da79479
commit 84d0ca111d
2 changed files with 26 additions and 6 deletions
+17 -2
View File
@@ -1,4 +1,4 @@
import React, { useState, useEffect } from 'react';
import React, { useState, useEffect, useRef } from 'react';
import ReactMarkdown from 'react-markdown';
import remarkGfm from 'remark-gfm';
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
@@ -17,16 +17,31 @@ interface MarkdownContentProps {
const CodeBlock = ({ language, children }: { language: string; children: string }) => {
const [copied, setCopied] = useState(false);
const timeoutRef = useRef<number | null>(null);
const handleCopy = async () => {
try {
await navigator.clipboard.writeText(children);
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) {
console.error('Failed to copy text: ', err);
}
};
useEffect(() => {
return () => {
if (timeoutRef.current) {
window.clearTimeout(timeoutRef.current);
}
};
}, []);
return (
<div className="relative group w-full">
<button
@@ -141,11 +141,16 @@ export default function ProgressiveMessageList({
// Force complete rendering when search is active
useEffect(() => {
// Only add listener if we're actually loading
if (!isLoading) {
return;
}
const handleKeyDown = (e: KeyboardEvent) => {
const isMac = window.electron.platform === 'darwin';
const isSearchShortcut = (isMac ? e.metaKey : e.ctrlKey) && e.key === 'f';
if (isSearchShortcut && isLoading) {
if (isSearchShortcut) {
// Immediately render all messages when search is triggered
setRenderedCount(messages.length);
setIsLoading(false);
@@ -248,14 +253,14 @@ export default function ProgressiveMessageList({
renderedCount,
renderMessage,
isUserMessage,
hasContextHandlerContent,
getContextHandlerType,
chat,
append,
appendMessage,
toolCallNotifications,
onScrollToBottom,
isStreamingMessage,
hasContextHandlerContent,
getContextHandlerType,
onScrollToBottom,
]);
return (