Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions webview-ui/src/components/chat/ChatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
{ isHidden, showAnnouncement, hideAnnouncement },
ref,
) => {
const isMountedRef = useRef(true)
const [audioBaseUri] = useState(() => {
const w = window as any
return w.AUDIO_BASE_URI || ""
Expand Down Expand Up @@ -158,6 +159,13 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
clineAskRef.current = clineAsk
}, [clineAsk])

useEffect(() => {
isMountedRef.current = true
return () => {
isMountedRef.current = false
}
}, [])

const isProfileDisabled = useMemo(
() => !!apiConfiguration && !ProfileValidator.isProfileAllowed(apiConfiguration, organizationAllowList),
[apiConfiguration, organizationAllowList],
Expand Down Expand Up @@ -1109,10 +1117,14 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
)

useEffect(() => {
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])

Expand Down Expand Up @@ -1234,16 +1246,21 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
// Add delay for write operations.
if (lastMessage.ask === "tool" && isWriteToolAction(lastMessage)) {
await new Promise((resolve) => setTimeout(resolve, writeDelayMs))
if (!isMountedRef.current) {
return
}
}

vscode.postMessage({ type: "askResponse", askResponse: "yesButtonClicked" })

// This is copied from `handlePrimaryButtonClick`, which we used
// to call from `autoApprove`. I'm not sure how many of these
// things are actually needed.
setSendingDisabled(true)
setClineAsk(undefined)
setEnableButtons(false)
if (isMountedRef.current) {
setSendingDisabled(true)
setClineAsk(undefined)
setEnableButtons(false)
}
}
}
autoApprove()
Expand Down
Loading