diff --git a/app/api/terminal/[id]/route.ts b/app/api/terminal/[id]/route.ts index 785861c68e..0ef9f2ca6b 100644 --- a/app/api/terminal/[id]/route.ts +++ b/app/api/terminal/[id]/route.ts @@ -26,8 +26,8 @@ export async function POST( } if (body.type === "resize" && Number.isInteger(body.cols) && Number.isInteger(body.rows) && (body.cols as number) >= 2 && (body.cols as number) <= 1000 - && (body.rows as number) >= 2 && (body.rows as number) <= 1000) { - return resizeTerminal(id, body.cols as number, body.rows as number) + && (body.rows as number) >= 1 && (body.rows as number) <= 1000) { + return resizeTerminal(id, body.cols as number, Math.max(2, body.rows as number)) ? NextResponse.json({ success: true }) : NextResponse.json({ error: "Terminal not found" }, { status: 404 }); } diff --git a/components/TerminalPanel.tsx b/components/TerminalPanel.tsx index f3a2abd078..0fa2aa59cf 100644 --- a/components/TerminalPanel.tsx +++ b/components/TerminalPanel.tsx @@ -99,7 +99,8 @@ export function TerminalPanel({ tab, active, onRestart, onClosed, onCloseError } fit.fit(); }; const onResize = terminal.onResize(({ cols, rows }) => { - if (connected && !exited && !inputFailed) writer.resize(cols, rows); + if (!connected || exited || inputFailed) return; + writer.resize(Math.max(2, cols), Math.max(2, rows)); }); const resizeObserver = new ResizeObserver(fitAndResize); resizeObserver.observe(container); @@ -138,7 +139,7 @@ export function TerminalPanel({ tab, active, onRestart, onClosed, onCloseError } terminal.options.disableStdin = false; setStatus("ready"); fitAndResize(); - writer.resize(terminal.cols, terminal.rows); + writer.resize(Math.max(2, terminal.cols), Math.max(2, terminal.rows)); if (container.offsetWidth && container.offsetHeight) terminal.focus(); }; events.onerror = () => {