Skip to content

Commit 6524402

Browse files
authored
fix(terminal): send initial size when WebSocket opens (#9505)
The mount-time fitAddon.fit() can fire before the terminal WS reaches OPEN state (common in iframe + tunneled deployments), in which case the resize message is silently dropped and the PTY stays at its default 0x0 winsize. bash then falls back to COLUMNS=80, producing horizontal-scroll input lines and incorrect wrapping. Send the current dimensions from the open handler so the PTY is always sized before the user starts typing.
1 parent 59ba840 commit 6524402

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

frontend/src/components/terminal/terminal.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,22 @@ const TerminalComponent: React.FC<TerminalComponentProps> = ({
270270

271271
const handleOpen = () => {
272272
updateReadyState();
273+
// Send initial dimensions: the mount-time fit() may have fired
274+
// before the WS was OPEN, dropping the resize message and leaving
275+
// the PTY at its default 0x0 winsize.
276+
fitAddon.fit();
277+
if (terminal.cols > 0 && terminal.rows > 0) {
278+
socket.send(
279+
JSON.stringify({
280+
type: "resize",
281+
cols: terminal.cols,
282+
rows: terminal.rows,
283+
}),
284+
);
285+
// The fit() above may have triggered onResize → scheduled a
286+
// debounced send. Cancel it; we just sent the same dims.
287+
handleBackendResizeDebounced.cancel();
288+
}
273289
};
274290

275291
const handleDisconnect = () => {

frontend/src/core/static/static-state.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ function isMarimoStaticState(
4343
}
4444

4545
function getMarimoStaticState(): Readonly<MarimoStaticState> | undefined {
46-
const state = window?.__MARIMO_STATIC__;
46+
// `typeof window` guard handles the identifier-undeclared case (e.g.
47+
// leaked async work firing after jsdom teardown in tests); `?.` only
48+
// short-circuits on null/undefined.
49+
const state =
50+
typeof window === "undefined" ? undefined : window.__MARIMO_STATIC__;
4751
return isMarimoStaticState(state) ? state : undefined;
4852
}
4953

0 commit comments

Comments
 (0)