From 5a4c93d251024a654cc6c0d26143cdb7fda2b356 Mon Sep 17 00:00:00 2001 From: kiwina Date: Mon, 2 Jun 2025 16:14:38 +0800 Subject: [PATCH 1/2] chore: Staging ChatView.tsx after reset to main --- webview-ui/src/components/chat/ChatView.tsx | 22 +++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/webview-ui/src/components/chat/ChatView.tsx b/webview-ui/src/components/chat/ChatView.tsx index d114701e18..7b311816c7 100644 --- a/webview-ui/src/components/chat/ChatView.tsx +++ b/webview-ui/src/components/chat/ChatView.tsx @@ -60,6 +60,7 @@ const ChatViewComponent: React.ForwardRefRenderFunction { + const isMountedRef = useRef(true) const [audioBaseUri] = useState(() => { const w = window as any return w.AUDIO_BASE_URI || "" @@ -1109,10 +1110,14 @@ const ChatViewComponent: React.ForwardRefRenderFunction { + let timerId: NodeJS.Timeout | undefined if (!disableAutoScrollRef.current) { - setTimeout(() => scrollToBottomSmooth(), 50) - // Don't cleanup since if visibleMessages.length changes it cancels. - // return () => clearTimeout(timer) + timerId = setTimeout(() => scrollToBottomSmooth(), 50) + } + return () => { + if (timerId) { + clearTimeout(timerId) + } } }, [groupedMessages.length, scrollToBottomSmooth]) @@ -1234,6 +1239,9 @@ const ChatViewComponent: React.ForwardRefRenderFunction setTimeout(resolve, writeDelayMs)) + if (!isMountedRef.current) { + return + } } vscode.postMessage({ type: "askResponse", askResponse: "yesButtonClicked" }) @@ -1241,9 +1249,11 @@ const ChatViewComponent: React.ForwardRefRenderFunction Date: Mon, 2 Jun 2025 16:17:29 +0800 Subject: [PATCH 2/2] fix: Address memory leaks in ChatView (ChatView_1113, ChatView_1236) --- webview-ui/src/components/chat/ChatView.tsx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/webview-ui/src/components/chat/ChatView.tsx b/webview-ui/src/components/chat/ChatView.tsx index 7b311816c7..52a3026e8a 100644 --- a/webview-ui/src/components/chat/ChatView.tsx +++ b/webview-ui/src/components/chat/ChatView.tsx @@ -159,6 +159,13 @@ const ChatViewComponent: React.ForwardRefRenderFunction { + isMountedRef.current = true + return () => { + isMountedRef.current = false + } + }, []) + const isProfileDisabled = useMemo( () => !!apiConfiguration && !ProfileValidator.isProfileAllowed(apiConfiguration, organizationAllowList), [apiConfiguration, organizationAllowList],