Skip to content

Commit 0538c3b

Browse files
committed
fix: make stop response instant with optimistic UI update and parallel requests
1 parent d0bf015 commit 0538c3b

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

src/lib/components/chat/Chat.svelte

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2207,17 +2207,11 @@
22072207
22082208
const stopResponse = async () => {
22092209
if (taskIds) {
2210-
for (const taskId of taskIds) {
2211-
const res = await stopTask(localStorage.token, taskId).catch((error) => {
2212-
toast.error(`${error}`);
2213-
return null;
2214-
});
2215-
}
2216-
2210+
const _taskIds = [...taskIds];
22172211
taskIds = null;
22182212
2213+
// Immediately mark all response messages as done for instant UI feedback
22192214
const responseMessage = history.messages[history.currentId];
2220-
// Set all response messages to done
22212215
if (responseMessage.parentId && history.messages[responseMessage.parentId]) {
22222216
for (const messageId of history.messages[responseMessage.parentId].childrenIds) {
22232217
history.messages[messageId].done = true;
@@ -2229,6 +2223,15 @@
22292223
if (autoScroll) {
22302224
scrollToBottom();
22312225
}
2226+
2227+
// Send stop requests to backend in parallel, non-blocking
2228+
Promise.all(
2229+
_taskIds.map((taskId) =>
2230+
stopTask(localStorage.token, taskId).catch((error) => {
2231+
console.error(`Failed to stop task ${taskId}:`, error);
2232+
})
2233+
)
2234+
);
22322235
}
22332236
22342237
if (generating) {

0 commit comments

Comments
 (0)