diff --git a/packages/cli/src/ui/components/MainContent.tsx b/packages/cli/src/ui/components/MainContent.tsx index 914eb2a8a3..c9378ab2f0 100644 --- a/packages/cli/src/ui/components/MainContent.tsx +++ b/packages/cli/src/ui/components/MainContent.tsx @@ -436,6 +436,9 @@ export const MainContent = () => { {(item) => item} {pendingItems} + {/* In alternate buffer mode, the btwDisplayNode is rendered within the ScrollableList + (via virtualizedData) to ensure proper scrolling. In standard mode, it is rendered + here at the bottom of the layout. */} {btwDisplayNode} ); diff --git a/packages/cli/src/ui/hooks/useBtw.ts b/packages/cli/src/ui/hooks/useBtw.ts index 896fbaa106..003ac26a52 100644 --- a/packages/cli/src/ui/hooks/useBtw.ts +++ b/packages/cli/src/ui/hooks/useBtw.ts @@ -148,7 +148,10 @@ export const useBtw = ( break; } case GeminiEventType.Error: { - if (flushTimerRef.current) clearTimeout(flushTimerRef.current); + if (flushTimerRef.current) { + clearTimeout(flushTimerRef.current); + flushTimerRef.current = null; + } flushResponse(); const value = event.value; @@ -177,7 +180,10 @@ export const useBtw = ( } case GeminiEventType.Finished: case GeminiEventType.UserCancelled: - if (flushTimerRef.current) clearTimeout(flushTimerRef.current); + if (flushTimerRef.current) { + clearTimeout(flushTimerRef.current); + flushTimerRef.current = null; + } flushResponse(); dispatch({ type: 'FINISHED' }); break; @@ -186,7 +192,10 @@ export const useBtw = ( } } } catch (err) { - if (flushTimerRef.current) clearTimeout(flushTimerRef.current); + if (flushTimerRef.current) { + clearTimeout(flushTimerRef.current); + flushTimerRef.current = null; + } flushResponse(); if (err instanceof Error && err.name === 'AbortError') { @@ -198,7 +207,10 @@ export const useBtw = ( }); } } finally { - if (flushTimerRef.current) clearTimeout(flushTimerRef.current); + if (flushTimerRef.current) { + clearTimeout(flushTimerRef.current); + flushTimerRef.current = null; + } flushResponse(); if (requestIdRef.current === requestId) { @@ -217,6 +229,7 @@ export const useBtw = ( } if (flushTimerRef.current) { clearTimeout(flushTimerRef.current); + flushTimerRef.current = null; } }, [],