Fix terminal stability bugs: remove autoFocus from effect deps, stabilize memo, remove dead export

- Remove autoFocus from the main terminal setup effect dependency array to
  prevent full terminal teardown/recreation when switching tabs in split view.
  Focus is already handled by a dedicated effect.
- Change threadTerminalRuntimeEnv memo dependency from activeProject to
  activeProject?.cwd so unrelated project state changes (e.g. saving scripts)
  don't trigger terminal re-initialization.
- Unexport injectEnvIntoShellCommand which is never imported by production
  code (env injection is handled server-side), and remove its tests.
This commit is contained in:
Cursor Agent committed 2026-02-18 07:29:34 +00:00
1 parent b033c60d41
commit 74cb1b6f84
4 files changed
+3 -23

No files matched your search

+1 -1
View File
@@ -552,7 +552,7 @@ export default function ChatView() {
},
worktreePath: activeThread?.worktreePath ?? null,
});
}, [activeProject, activeThread?.worktreePath]);
}, [activeProject?.cwd, activeThread?.worktreePath]);
// Default true while loading to avoid toolbar flicker.
const isGitRepo = branchesQuery.data?.isRepo ?? true;
const splitTerminalShortcutLabel = useMemo(
@@ -372,7 +372,7 @@ function TerminalViewport({
fitAddonRef.current = null;
terminal.dispose();
};
}, [api, autoFocus, cwd, runtimeEnv, terminalId, threadId]);
}, [api, cwd, runtimeEnv, terminalId, threadId]);
useEffect(() => {
if (!autoFocus) return;
-20
View File
@@ -2,7 +2,6 @@ import { describe, expect, it } from "vitest";
import {
commandForProjectScript,
injectEnvIntoShellCommand,
nextProjectScriptId,
primaryProjectScript,
projectScriptRuntimeEnv,
@@ -24,25 +23,6 @@ describe("projectScripts helpers", () => {
expect(nextProjectScriptId("!!!", [])).toBe("script");
});
it("injects environment variables for posix shells", () => {
const command = injectEnvIntoShellCommand("bun install", { T3CODE_PROJECT_ROOT: "/tmp/project" }, "MacIntel");
expect(command).toBe("env T3CODE_PROJECT_ROOT='/tmp/project' bun install");
});
it("injects environment variables for windows shells", () => {
const command = injectEnvIntoShellCommand("bun install", { T3CODE_PROJECT_ROOT: "C:\\\\repo path" }, "Win32");
expect(command).toBe('set "T3CODE_PROJECT_ROOT=C:\\\\repo path" && bun install');
});
it("escapes windows env values that trigger interpolation", () => {
const command = injectEnvIntoShellCommand(
"bun install",
{ T3CODE_PROJECT_ROOT: '%USERPROFILE%^"repo"' },
"Win32",
);
expect(command).toBe('set "T3CODE_PROJECT_ROOT=^%USERPROFILE^%^^""repo""" && bun install');
});
it("resolves primary and setup scripts", () => {
const scripts = [
{
+1 -1
View File
@@ -60,7 +60,7 @@ function shellEscapeWindowsSetValue(value: string): string {
return value.replace(/\^/g, "^^").replace(/%/g, "^%").replace(/"/g, '""');
}
export function injectEnvIntoShellCommand(
function injectEnvIntoShellCommand(
command: string,
env: Record<string, string>,
platform = typeof navigator === "undefined" ? "" : navigator.platform,