From f63ee379a41ab8d1b6b3fce9c42cc40a0680cb62 Mon Sep 17 00:00:00 2001 From: Bill Date: Mon, 14 Sep 2026 01:17:04 +0800 Subject: [PATCH] fix: send the first pty size immediately, debounce only subsequent resizes --- src/renderer/src/terminal/TerminalView.tsx | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/renderer/src/terminal/TerminalView.tsx b/src/renderer/src/terminal/TerminalView.tsx index a7abdb8..b62f3d6 100644 --- a/src/renderer/src/terminal/TerminalView.tsx +++ b/src/renderer/src/terminal/TerminalView.tsx @@ -348,17 +348,25 @@ export const TerminalView: ForwardRefExoticComponent { + const send = (): void => { const live = termRef.current if (!live || deadRef.current) return if (live.cols === ptySizeRef.current?.cols && live.rows === ptySizeRef.current?.rows) return ptySizeRef.current = { cols: live.cols, rows: live.rows } window.api.resizePty(sessionId, live.cols, live.rows) - // 100ms mirrors what other Electron terminals use: long enough to swallow - // a maximize/restore animation tick storm, short enough that a plain - // window drag does not visibly wrap against a stale width. - }, 100) + } + window.clearTimeout(ptyTimerRef.current) + // First size for a session goes out immediately (the pty spawns at a + // placeholder 80x24 and a shell may already be drawing); later changes — + // window drags, maximize/restore — wait for the layout to settle. + if (!last) { + send() + return + } + // 100ms mirrors what other Electron terminals use: long enough to swallow + // a maximize/restore animation tick storm, short enough that a plain + // window drag does not visibly wrap against a stale width. + ptyTimerRef.current = window.setTimeout(send, 100) }) }, [sessionId])