fix(tui): clamp bogus terminal dimensions (WSL 131072x1) (#35657)

Some hosts (notably WSL) report a junk window size such as 131072 columns
by 1 row. Both the Ink fork and our components only guard against
0/null/undefined/NaN (stdout.columns || 80), so a positive-but-absurd
width sails through into createScreen(width*height), allocating tens to
hundreds of MB per frame and tripping the TUI memory monitor's hard exit.

Add clampStdoutDimensions(), installed in entry.tsx before ink.render: it
patches process.stdout.columns/rows with clamping getters (cols 1-2000,
rows 1-1000; out-of-range -> 80x24). One install point fixes the renderer,
its resize handler, and every component read. Live resizes still propagate
through the original descriptor, just clamped.
This commit is contained in:
Teknium
2026-05-30 20:42:30 -07:00
committed by GitHub
parent cd067ab91e
commit b1d34cf6e2
3 changed files with 258 additions and 0 deletions
+7
View File
@@ -11,6 +11,7 @@ import { setupGracefulExit } from './lib/gracefulExit.js'
import { formatBytes, type HeapDumpResult, performHeapDump } from './lib/memory.js'
import { type MemorySnapshot, startMemoryMonitor } from './lib/memoryMonitor.js'
import { openExternalUrl } from './lib/openExternalUrl.js'
import { clampStdoutDimensions } from './lib/terminalDimensions.js'
import { resetTerminalModes } from './lib/terminalModes.js'
if (!process.stdin.isTTY) {
@@ -18,6 +19,12 @@ if (!process.stdin.isTTY) {
process.exit(0)
}
// Some hosts (notably WSL) report bogus window sizes such as 131072x1. Clamp
// `process.stdout.columns`/`rows` at the source so the Ink renderer, its
// resize handler, and every component read see sane values. Must run before
// `ink.render` constructs the renderer.
clampStdoutDimensions()
// Start from a clean slate. If a previous TUI crashed or was kill -9'd, the
// terminal tab can still have mouse/focus/paste modes enabled.
resetTerminalModes()