From e17e7cd32e12639a5e9a97c75f4bc83da5e48e6f Mon Sep 17 00:00:00 2001 From: Gemini AI Date: Wed, 24 Dec 2025 22:08:04 +0400 Subject: [PATCH] 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. --- packages/ui/src/stores/session-actions.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/ui/src/stores/session-actions.ts b/packages/ui/src/stores/session-actions.ts index c95359a..24be1fc 100644 --- a/packages/ui/src/stores/session-actions.ts +++ b/packages/ui/src/stores/session-actions.ts @@ -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(resolve => setTimeout(resolve, 0)) } if (timedOut) { throw new Error("Stream timed out")