Skip to content

Commit 867ef87

Browse files
authored
fix(desktop): sync v1 terminal dimensions to backend on connect (#3545)
When panes mount during new-workspace / preset flows, attachToContainer's fit() can run before flex layout resolves, leaving the backend PTY spawned at stale defaults (shell prompt wraps wrong until a manual resize). Mirror v2's sendResize-on-open pattern: once createOrAttach succeeds, re-fit against the now-settled container and push the real dims.
1 parent 1979f4c commit 867ef87

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/hooks

apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/hooks/useTerminalLifecycle.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,17 @@ export function useTerminalLifecycle({
260260

261261
const { xterm, fitAddon, searchAddon } = cached;
262262

263+
// Called after createOrAttach resolves: re-fit against the now-settled
264+
// container and push dims to the backend. Guards against stale sizes
265+
// from attachToContainer's fit running before flex layout resolved
266+
// (e.g. preset tabs, new workspace bulk creation). Mirrors v2's
267+
// terminal-ws-transport sendResize-on-open.
268+
const syncBackendDimensions = () => {
269+
if (container.clientWidth === 0 || container.clientHeight === 0) return;
270+
fitAddon.fit();
271+
resizeRef.current({ paneId, cols: xterm.cols, rows: xterm.rows });
272+
};
273+
263274
// Attach the wrapper div to the live container.
264275
// The cache creates a ResizeObserver that calls fitAddon.fit() and
265276
// forwards resize events to the backend — no separate resize handler needed.
@@ -383,6 +394,7 @@ export function useTerminalLifecycle({
383394
return;
384395
}
385396
setConnectionError(null);
397+
syncBackendDimensions();
386398
pendingInitialStateRef.current = result;
387399
maybeApplyInitialState();
388400
if (!command) {
@@ -595,6 +607,7 @@ export function useTerminalLifecycle({
595607
v1TerminalCache.startStream(paneId);
596608
v1TerminalCache.setStreamReady(paneId);
597609
markTerminalSessionReady(paneId);
610+
syncBackendDimensions();
598611

599612
const storedColdRestore = coldRestoreState.get(paneId);
600613
if (storedColdRestore?.isRestored) {

0 commit comments

Comments
 (0)