From d86c3041c948f17a8a02d01d08925c893eaf1bdf Mon Sep 17 00:00:00 2001 From: Luke Parker <10430890+Hona@users.noreply.github.com> Date: Mon, 7 Sep 2026 15:56:23 +1000 Subject: [PATCH] fix(app): keep new session open while the worktree list loads (#47734) --- .../src/new-session/workspace/controller.ts | 43 ++++++++++++------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/packages/app/src/new-session/workspace/controller.ts b/packages/app/src/new-session/workspace/controller.ts index 5772b4a3a48..d4c45d16fce 100644 --- a/packages/app/src/new-session/workspace/controller.ts +++ b/packages/app/src/new-session/workspace/controller.ts @@ -75,9 +75,14 @@ export function createNewSessionWorkspaceController(input: { if (event.type === "worktree.updated") void worktreeActions.refetch() }), ) + // `latest` only skips Suspense once the resource has resolved at least once. Before that it + // behaves like a plain read, which holds the transition that opens the New Session tab until + // the worktree list returns. + const worktreesLoaded = () => worktrees.state === "ready" || worktrees.state === "refreshing" const worktreeItems = createMemo(() => { const project = currentProject() if (!project) return [] + if (!worktreesLoaded()) return project.worktrees const loaded = worktrees.latest return loaded?.projectID === project.id ? loaded.items : project.worktrees }) @@ -110,10 +115,11 @@ export function createNewSessionWorkspaceController(input: { const project = currentProject() const worktree = input.selectedWorktree() if (!project || !worktree) return - return isWorkspaceSelection(project, worktree) || - worktreeDirectories().some((item) => sameDirectory(item, worktree)) - ? worktree - : undefined + if (isWorkspaceSelection(project, worktree)) return worktree + // A saved choice may only exist in the server inventory. Keep it until the list can confirm it, + // otherwise the selector falls back to Local while loading and a submit would target the wrong directory. + if (!worktreesLoaded()) return worktree + return worktreeDirectories().some((item) => sameDirectory(item, worktree)) ? worktree : undefined }) const fallback = createMemo(() => { const project = currentProject() @@ -140,12 +146,19 @@ export function createNewSessionWorkspaceController(input: { .catch(() => ({ directory, search, data: [] })), ) createEffect(() => { - void Promise.all([data.location.syncInfo({ directory: sdk().directory }), data.project.sync()]).catch( - () => undefined, - ) - const project = currentProject() - const directories = project ? [project.worktree, ...worktreeDirectories()] : [sdk().directory] - directories.forEach((directory) => void data.location.vcs.sync({ directory }).catch(() => undefined)) + void Promise.all([ + data.location.syncInfo({ directory: sdk().directory }), + data.project.sync(), + data.location.vcs.sync({ directory: sdk().directory }), + ]).catch(() => undefined) + }) + // Only the selected worktree feeds the branch label. Syncing every worktree in the inventory boots + // each one on the server, which then emits `agent.updated` and makes the client run the full + // catalog fan-out for every directory. + createEffect(() => { + const selection = value() + if (selection === "main" || selection === "create") return + void data.location.vcs.sync({ directory: selection }).catch(() => undefined) }) const branch = createMemo(() => resolveNewSessionBranch({ @@ -169,12 +182,10 @@ export function createNewSessionWorkspaceController(input: { workspace: createMemo(() => { const project = currentProject() const current = value() - return ( - current === "create" || - (!!project && - (isWorkspaceDirectory(project, current) || - worktreeDirectories().some((item) => sameDirectory(item, current)))) - ) + if (current === "create") return true + if (current === "main" || !project) return false + if (isWorkspaceDirectory(project, current) || !worktreesLoaded()) return true + return worktreeDirectories().some((item) => sameDirectory(item, current)) }), reset: () => { input.setSelectedWorktree(undefined)