Fix UI freeze by adding yield to SSE streaming loop

Added microtask yield (setTimeout 0) after processing each batch of SSE
lines. This allows the main thread event loop to process UI updates and
user interaction between streaming updates, preventing the UI from
becoming completely unresponsive during rapid streaming.
This commit is contained in:
Gemini AI
2025-12-24 22:08:04 +04:00
Unverified
parent 2cb9fea514
commit e17e7cd32e

View File

@@ -449,7 +449,7 @@ async function readSseStream(
if (idleTimer) clearTimeout(idleTimer)
idleTimer = setTimeout(() => {
timedOut = true
reader.cancel().catch(() => {})
reader.cancel().catch(() => { })
}, idleTimeoutMs)
}
resetIdleTimer()
@@ -474,6 +474,8 @@ async function readSseStream(
}
onData(data)
}
// Yield to main thread periodically to prevent UI freeze during rapid streaming
await new Promise<void>(resolve => setTimeout(resolve, 0))
}
if (timedOut) {
throw new Error("Stream timed out")