From 84d0ca111d507128db954943a5e792bc6d09c6af Mon Sep 17 00:00:00 2001 From: Zane <75694352+zanesq@users.noreply.github.com> Date: Wed, 13 Aug 2025 13:56:07 -0700 Subject: [PATCH] cleanup memory in chat (#4073) --- ui/desktop/src/components/MarkdownContent.tsx | 19 +++++++++++++++++-- .../src/components/ProgressiveMessageList.tsx | 13 +++++++++---- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/ui/desktop/src/components/MarkdownContent.tsx b/ui/desktop/src/components/MarkdownContent.tsx index 3566c6bccc..15c9b293a9 100644 --- a/ui/desktop/src/components/MarkdownContent.tsx +++ b/ui/desktop/src/components/MarkdownContent.tsx @@ -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(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 (