Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

fix(terminal): send initial size when WebSocket opens (#9505)

Myles Scolnick6524402860c6
diff --git a/frontend/src/components/terminal/terminal.tsx b/frontend/src/components/terminal/terminal.tsx
index 6df070193b..5dc811b6d5 100644
--- a/frontend/src/components/terminal/terminal.tsx
+++ b/frontend/src/components/terminal/terminal.tsx
@@ -270,6 +270,22 @@ const TerminalComponent: React.FC<TerminalComponentProps> = ({
const handleOpen = () => {
updateReadyState();
+ // Send initial dimensions: the mount-time fit() may have fired
+ // before the WS was OPEN, dropping the resize message and leaving
+ // the PTY at its default 0x0 winsize.
+ fitAddon.fit();
+ if (terminal.cols > 0 && terminal.rows > 0) {
+ socket.send(
+ JSON.stringify({
+ type: "resize",
+ cols: terminal.cols,
+ rows: terminal.rows,
+ }),
+ );
+ // The fit() above may have triggered onResize → scheduled a
+ // debounced send. Cancel it; we just sent the same dims.
+ handleBackendResizeDebounced.cancel();
+ }
};
const handleDisconnect = () => {
diff --git a/frontend/src/core/static/static-state.ts b/frontend/src/core/static/static-state.ts
index 73db93123b..137495cb3b 100644
--- a/frontend/src/core/static/static-state.ts
+++ b/frontend/src/core/static/static-state.ts
@@ -43,7 +43,11 @@ function isMarimoStaticState(
}
function getMarimoStaticState(): Readonly<MarimoStaticState> | undefined {
- const state = window?.__MARIMO_STATIC__;
+ // `typeof window` guard handles the identifier-undeclared case (e.g.
+ // leaked async work firing after jsdom teardown in tests); `?.` only
+ // short-circuits on null/undefined.
+ const state =
+ typeof window === "undefined" ? undefined : window.__MARIMO_STATIC__;
return isMarimoStaticState(state) ? state : undefined;
}