From 451b6e652f5d884c0b8b5115dd9a4c3d2feb6fd4 Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Fri, 17 Apr 2026 16:48:54 -0700 Subject: [PATCH] fix(terminal): stop re-running composer prompt on user-initiated splits (#778) --- .../src/components/terminal-pane/pty-connection.ts | 13 ++++++------- .../terminal-pane/use-terminal-pane-lifecycle.ts | 12 ++++++++++++ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/renderer/src/components/terminal-pane/pty-connection.ts b/src/renderer/src/components/terminal-pane/pty-connection.ts index e1f439d90..8f99dce16 100644 --- a/src/renderer/src/components/terminal-pane/pty-connection.ts +++ b/src/renderer/src/components/terminal-pane/pty-connection.ts @@ -19,13 +19,12 @@ export function connectPanePty( let disposed = false let connectFrame: number | null = null let startupInjectTimer: ReturnType | null = null - // Why: setup commands must only run once — in the initial pane of the tab. - // Capture and clear the startup reference synchronously so that panes - // created later by splits or layout restoration cannot re-execute the - // setup script, which would be confusing and potentially destructive. - // Note: this intentionally mutates `deps` so the caller's object no - // longer carries the startup payload — preventing any later consumer - // from accidentally replaying it. + // Why: startup commands must only run once — in the pane they were + // targeted at. Capture `deps.startup` into a local and clear the field on + // the (already spread-copied) `deps` so nothing else inside this function + // can accidentally re-read it. The caller is responsible for clearing its + // own outer reference, since `deps` here is a shallow copy and our + // mutation does not propagate back. const paneStartup = deps.startup ?? null deps.startup = undefined diff --git a/src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts b/src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts index b3fbdab56..ee06241d7 100644 --- a/src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts +++ b/src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts @@ -293,6 +293,18 @@ export function useTerminalPaneLifecycle({ ...ptyDeps, restoredLeafId }) + // Why: connectPanePty receives a spread copy of ptyDeps, so the + // `deps.startup = undefined` it performs internally only clears its + // local copy. If we don't also clear the outer ptyDeps.startup here, + // a later user-initiated splitPane (e.g. Cmd+D, context-menu "Split + // Right") fires onPaneCreated again with the original startup still + // attached — which re-runs the initial composer prompt in the newly + // created pane. Clearing here ensures the initial-startup payload is + // consumed exactly once, by the first pane. Setup/issue splits + // inject their own payload via splitPaneWithOneShotStartup, which + // sets deps.startup immediately before splitPane() and is therefore + // unaffected by this clear. + ptyDeps.startup = null panePtyBindings.set(pane.id, panePtyBinding) scheduleRuntimeGraphSync() queueResizeAll(true)