diff --git a/webview-ui/src/components/chat/ChatView.tsx b/webview-ui/src/components/chat/ChatView.tsx index d114701e18..52a3026e8a 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 || "" @@ -158,6 +159,13 @@ const ChatViewComponent: React.ForwardRefRenderFunction { + isMountedRef.current = true + return () => { + isMountedRef.current = false + } + }, []) + const isProfileDisabled = useMemo( () => !!apiConfiguration && !ProfileValidator.isProfileAllowed(apiConfiguration, organizationAllowList), [apiConfiguration, organizationAllowList], @@ -1109,10 +1117,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 +1246,9 @@ const ChatViewComponent: React.ForwardRefRenderFunction setTimeout(resolve, writeDelayMs)) + if (!isMountedRef.current) { + return + } } vscode.postMessage({ type: "askResponse", askResponse: "yesButtonClicked" }) @@ -1241,9 +1256,11 @@ const ChatViewComponent: React.ForwardRefRenderFunction