Skip to content

Commit 3045338

Browse files
committed
fix: cancel active streams and clear messages on background job start
1 parent 8aef23e commit 3045338

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/components/Chat.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,13 @@ export function Chat() {
227227
}
228228

229229
try {
230+
// Cancel any active stream and clear existing messages
231+
cancelStream()
232+
stop()
233+
clearBuffer()
234+
setMessages([])
235+
setHasStartedChat(true)
236+
230237
const url = new URL('/api/background-jobs', window.location.origin)
231238
url.searchParams.set('id', job.id)
232239
const streamResponse = await fetch(url.toString(), {
@@ -241,7 +248,7 @@ export function Chat() {
241248
handleError(new Error('Failed to load background job'))
242249
}
243250
},
244-
[backgroundJobs],
251+
[backgroundJobs, cancelStream, stop, clearBuffer, setMessages, handleResponse, handleError],
245252
)
246253

247254
const handleCancelJob = useCallback((jobId: string) => {

0 commit comments

Comments
 (0)