From da8f3e92a7bbc3b288f89f6b535b72b94c1d1c19 Mon Sep 17 00:00:00 2001 From: adamelmore <2363879+adamdottv@users.noreply.github.com> Date: Fri, 23 Jan 2026 23:18:54 -0600 Subject: perf(app): better session stream rendering --- packages/ui/src/components/session-turn.tsx | 16 ++++++++++++++-- packages/ui/src/hooks/create-auto-scroll.tsx | 11 ++++------- 2 files changed, 18 insertions(+), 9 deletions(-) (limited to 'packages/ui/src') diff --git a/packages/ui/src/components/session-turn.tsx b/packages/ui/src/components/session-turn.tsx index ca63d17ab..fe53c0939 100644 --- a/packages/ui/src/components/session-turn.tsx +++ b/packages/ui/src/components/session-turn.tsx @@ -457,9 +457,16 @@ export function SessionTurn( }) createEffect(() => { - const timer = setInterval(() => { + const update = () => { setStore("duration", duration()) - }, 1000) + } + + update() + + // Only keep ticking while the active (in-progress) turn is running. + if (!working()) return + + const timer = setInterval(update, 1000) onCleanup(() => clearInterval(timer)) }) @@ -495,6 +502,11 @@ export function SessionTurn( } }) + onCleanup(() => { + if (!statusTimeout) return + clearTimeout(statusTimeout) + }) + return (
| undefined let autoTimer: ReturnType | undefined let cleanup: (() => void) | undefined - let resizeFrame: number | undefined let auto: { top: number; time: number } | undefined const threshold = () => options.bottomThreshold ?? 10 @@ -152,11 +151,10 @@ export function createAutoScroll(options: AutoScrollOptions) { () => { if (!active()) return if (store.userScrolled) return - if (resizeFrame !== undefined) return - resizeFrame = requestAnimationFrame(() => { - resizeFrame = undefined - scrollToBottom(false) - }) + // ResizeObserver fires after layout, before paint. + // Keep the bottom locked in the same frame to avoid visible + // "jump up then catch up" artifacts while streaming content. + scrollToBottom(false) }, ) @@ -190,7 +188,6 @@ export function createAutoScroll(options: AutoScrollOptions) { onCleanup(() => { if (settleTimer) clearTimeout(settleTimer) if (autoTimer) clearTimeout(autoTimer) - if (resizeFrame !== undefined) cancelAnimationFrame(resizeFrame) if (cleanup) cleanup() }) -- cgit v1.2.3