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:
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user