Skip to content

Commit cf3ff3a

Browse files
committed
refactor(ui): 优化主界面抖动的问题
1 parent a5da21f commit cf3ff3a

1 file changed

Lines changed: 5 additions & 15 deletions

File tree

src/ui/views/App.tsx

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -584,29 +584,19 @@ function App({ projectRoot, initialPrompt, onRestart }: AppProps): React.ReactEl
584584

585585
if (mode === RawMode.Raw) {
586586
// In raw mode, re-render all messages directly to stdout at the new width.
587-
// Use process.stdout.write instead of writeRef to avoid Ink interference.
588587
process.stdout.write(ANSI_CLEAR_SCREEN);
589588
const activeSessionId = sessionManager.getActiveSessionId();
590589
const allMessages = activeSessionId ? loadVisibleMessages(sessionManager, activeSessionId) : [];
591590
renderRawModeMessages(allMessages, mode);
592591
return;
593592
}
594593

595-
// Force full redraw on terminal resize to avoid stale wrapped rows.
596-
writeRef.current("\u001B[2J\u001B[H");
597-
598-
setMessages([]);
599-
setShowWelcome(false);
594+
// Don't clear the screen on resize — Ink handles re-layout naturally.
595+
// Clearing causes scroll-to-top and flash, especially on tab switch in iTerm2.
596+
// Just force ThemeableStatic to remount so Ink recalculates row heights.
600597
setWelcomeNonce((n) => n + 1);
601-
602-
const activeSessionId = sessionManager.getActiveSessionId();
603-
const nextMessages =
604-
activeSessionId && !busy ? loadVisibleMessages(sessionManager, activeSessionId) : messagesRef.current;
605-
setTimeout(() => {
606-
setMessages(nextMessages);
607-
setShowWelcome(true);
608-
}, 0);
609-
}, [busy, mode, sessionManager, columns, stdout]);
598+
// eslint-disable-next-line react-hooks/exhaustive-deps
599+
}, [busy, mode, sessionManager, columns]);
610600

611601
const screenWidth = useMemo(() => columns ?? stdout?.columns ?? 80, [columns, stdout]);
612602
const screenHeight = useMemo(() => rows ?? stdout?.rows ?? 24, [rows, stdout]);

0 commit comments

Comments
 (0)