TypeScript
fix(web): keep composer toolbar visible after worktree failure (#14753)
Theo Browne77ed46a8aac2
diff --git a/apps/web/src/components/BranchToolbar.panel.browser.test.tsx b/apps/web/src/components/BranchToolbar.panel.browser.test.tsxindex 82c26e01175..0c0a2059330 100644--- a/apps/web/src/components/BranchToolbar.panel.browser.test.tsx+++ b/apps/web/src/components/BranchToolbar.panel.browser.test.tsx@@ -30,11 +30,6 @@ vi.mock(import("./BranchToolbarBranchSelector"), async (original) => ({}));vi.mock(import("../state/entities"), async (original) => ({...(await original()),- useQuietThreadShell: (() => ({- environmentId: "local",- projectId: "project",- worktreePath: state.worktreePath,- })) as never,useProject: (() => ({ workspaceRoot: "/tmp/project" })) as never,useThreadShellsForProjectRefs: () => [],}));@@ -71,6 +66,9 @@ function render(props: Partial<ComponentProps<typeof BranchToolbar>>) {panelSection="workspace"environmentId={EnvironmentId.make("local")}threadId={ThreadId.make("thread")}+ projectId={ProjectId.make("project")}+ worktreePath={state.worktreePath}+ isServerThreadshowGitControlsenvMode="local"envLocked={false}diff --git a/apps/web/src/components/BranchToolbar.tsx b/apps/web/src/components/BranchToolbar.tsxindex eca987fe57f..4d6fbef50a6 100644--- a/apps/web/src/components/BranchToolbar.tsx+++ b/apps/web/src/components/BranchToolbar.tsx@@ -3,7 +3,7 @@ import { readLocalApi } from "../localApi";import { stackedThreadToast, toastManager } from "./ui/toast";import { ComposerContextLabel } from "./ComposerContextLabel";import { scopeProjectRef, scopeThreadRef } from "@t3tools/client-runtime/environment";-import type { EnvironmentId, ThreadId } from "@t3tools/contracts";+import type { EnvironmentId, ProjectId, ThreadId } from "@t3tools/contracts";import {ChevronDownIcon,FolderGit2Icon,@@ -25,7 +25,7 @@ import {import { useComposerDraftStore, type DraftId } from "../composerDraftStore";import { EnvironmentMachineIcon } from "./EnvironmentMachineIcon";-import { useProject, useQuietThreadShell, useThreadShellsForProjectRefs } from "../state/entities";+import { useProject, useThreadShellsForProjectRefs } from "../state/entities";import {type EnvMode,type EnvironmentOption,@@ -83,6 +83,9 @@ interface BranchToolbarProps {ref?: Ref<BranchToolbarHandle>;environmentId: EnvironmentId;threadId: ThreadId;+ projectId: ProjectId;+ worktreePath: string | null;+ isServerThread: boolean;showGitControls: boolean;draftId?: DraftId;onEnvModeChange: (mode: EnvMode) => void;@@ -571,6 +574,9 @@ export const BranchToolbar = memo(function BranchToolbar({ref,environmentId,threadId,+ projectId,+ worktreePath,+ isServerThread,showGitControls,draftId,onEnvModeChange,@@ -592,28 +598,16 @@ export const BranchToolbar = memo(function BranchToolbar({}: BranchToolbarProps) {const branchSelectorRef = useRef<BranchToolbarBranchSelectorHandle>(null);const threadRef = scopeThreadRef(environmentId, threadId);- const draftThread = useComposerDraftStore((store) =>- draftId ? store.getDraftSession(draftId) : store.getDraftThreadByRef(threadRef),- );- const serverThread = useQuietThreadShell(threadRef);const setDraftThreadContext = useComposerDraftStore((store) => store.setDraftThreadContext);- const activeProjectRef = serverThread- ? scopeProjectRef(serverThread.environmentId, serverThread.projectId)- : draftThread- ? scopeProjectRef(draftThread.environmentId, draftThread.projectId)- : null;+ // The composer retains resolved thread details while bootstrap cleanup can remove its shell.+ const activeProjectRef = scopeProjectRef(environmentId, projectId);const activeProject = useProject(activeProjectRef);- const hasActiveThread = serverThread !== null || draftThread !== null;- const activeWorktreePath = forceNewWorktree- ? null- : (serverThread?.worktreePath ?? draftThread?.worktreePath ?? null);+ const activeWorktreePath = forceNewWorktree ? null : worktreePath;const effectiveEnvMode = forceNewWorktree ? "worktree" : envMode;- const envModeLocked = envLocked || (serverThread !== null && activeWorktreePath !== null);+ const envModeLocked = envLocked || (isServerThread && activeWorktreePath !== null);- const canUsePreviousWorktree =- draftThread !== null && serverThread === null && !envModeLocked && !forceNewWorktree;- const projectRefsForWorktreeLookup =- canUsePreviousWorktree && activeProjectRef ? [activeProjectRef] : [];+ const canUsePreviousWorktree = !isServerThread && !envModeLocked && !forceNewWorktree;+ const projectRefsForWorktreeLookup = canUsePreviousWorktree ? [activeProjectRef] : [];const projectThreads = useThreadShellsForProjectRefs(projectRefsForWorktreeLookup);const previousWorktreeSeed = canUsePreviousWorktree? resolvePreviousWorktreeSeed({@@ -625,7 +619,7 @@ export const BranchToolbar = memo(function BranchToolbar({? resolvePreviousWorktreeLabel(previousWorktreeSeed): null;const onUsePreviousWorktree = () => {- if (!previousWorktreeSeed || !activeProjectRef) return;+ if (!previousWorktreeSeed) return;setDraftThreadContext(draftId ?? threadRef, {branch: previousWorktreeSeed.branch,worktreePath: previousWorktreeSeed.worktreePath,@@ -667,7 +661,7 @@ export const BranchToolbar = memo(function BranchToolbar({const [stripElement, setStripElement] = useState<HTMLDivElement | null>(null);const labelsOverflow = useLabelsOverflow(stripElement);- if (!hasActiveThread || !activeProject) return null;+ if (!activeProject) return null;if (layout === "panel") {return (diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsxindex e615ae91e14..3c811d2cb51 100644--- a/apps/web/src/components/ChatView.tsx+++ b/apps/web/src/components/ChatView.tsx@@ -8434,6 +8434,9 @@ export default function ChatView(props: ChatViewProps) {ref={branchToolbarRef}environmentId={activeThread.environmentId}threadId={activeThread.id}+ projectId={activeThread.projectId}+ worktreePath={activeThread.worktreePath}+ isServerThread={isServerThread}showGitControls={isGitRepo}{...(routeKind === "draft" && draftId ? { draftId } : {})}onEnvModeChange={onEnvModeChangeStable}@@ -8511,6 +8514,9 @@ export default function ChatView(props: ChatViewProps) {forceNewWorktree={multipleModelSelections !== null}environmentId={activeThread.environmentId}threadId={activeThread.id}+ projectId={activeThread.projectId}+ worktreePath={activeThread.worktreePath}+ isServerThread={isServerThread}{...(draftId ? { draftId } : {})}activeProjectName={activeProject?.title}activeProjectScripts={activeProject ? activeProjectScripts : undefined}diff --git a/apps/web/src/components/chat/ThreadDetailsPanel.tsx b/apps/web/src/components/chat/ThreadDetailsPanel.tsxindex bc54f4f8a94..cea257e4641 100644--- a/apps/web/src/components/chat/ThreadDetailsPanel.tsx+++ b/apps/web/src/components/chat/ThreadDetailsPanel.tsx@@ -1,6 +1,7 @@import type {EditorId,EnvironmentId,+ ProjectId,ProjectScript,ResolvedKeybindingsConfig,ThreadId,@@ -31,6 +32,9 @@ export interface ThreadDetailsPanelProps extends Pick<forceNewWorktree?: boolean;environmentId: EnvironmentId;threadId: ThreadId;+ projectId: ProjectId;+ worktreePath: string | null;+ isServerThread: boolean;draftId?: DraftId;activeProjectName: string | undefined;activeProjectScripts: ReadonlyArray<ProjectScript> | undefined;@@ -74,6 +78,9 @@ export function ThreadDetailsPanel(props: ThreadDetailsPanelProps) {showGitControls: props.isGitRepo,environmentId: props.environmentId,threadId: props.threadId,+ projectId: props.projectId,+ worktreePath: props.worktreePath,+ isServerThread: props.isServerThread,...(props.draftId ? { draftId: props.draftId } : {}),onEnvModeChange: props.onEnvModeChange,startFromOrigin: props.startFromOrigin,diff --git a/apps/web/src/components/chat/ThreadDetailsPrRows.browser.test.tsx b/apps/web/src/components/chat/ThreadDetailsPrRows.browser.test.tsxindex b36dc779935..82dda731869 100644--- a/apps/web/src/components/chat/ThreadDetailsPrRows.browser.test.tsx+++ b/apps/web/src/components/chat/ThreadDetailsPrRows.browser.test.tsx@@ -1,4 +1,4 @@-import { EnvironmentId, ThreadId, type ThreadPullRequestLink } from "@t3tools/contracts";+import { EnvironmentId, ProjectId, ThreadId, type ThreadPullRequestLink } from "@t3tools/contracts";import { act, type ComponentProps } from "react";import { createRoot, type Root } from "react-dom/client";import { afterEach, beforeEach, expect, it, vi } from "vite-plus/test";@@ -235,6 +235,9 @@ it("keeps workspace controls after expanding and collapsing 70 linked pull requeroot.render(<ThreadDetailsPanel{...threadRef}+ projectId={ProjectId.make("project")}+ worktreePath={null}+ isServerThreadanchor={{ current: null }}handle={PopoverCreateHandle()}onPresentationChange={vi.fn()}