From 005e13089a4a8f44cb25452cb4b8d9b18184a1b7 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 1 Mar 2026 19:16:26 -0800 Subject: [PATCH] Preserve draft branch/worktree when update options are undefined - Keep existing `branch` and `worktreePath` values when `setProjectDraftThreadId` receives `undefined` - Add a regression test covering the undefined-update case --- apps/web/src/composerDraftStore.test.ts | 18 ++++++++++++++++++ apps/web/src/composerDraftStore.ts | 12 ++++++------ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/apps/web/src/composerDraftStore.test.ts b/apps/web/src/composerDraftStore.test.ts index ce88deb494d11b0d9054ce92b747cb3d0d21fd24..c2dd5c1240b706f0634df523c6c2d6e02aaae061 100644 --- a/apps/web/src/composerDraftStore.test.ts +++ b/apps/web/src/composerDraftStore.test.ts @@ -275,6 +275,24 @@ describe("composerDraftStore project draft thread mapping", () => { worktreePath: "/tmp/feature-next", }); }); + + it("preserves existing branch and worktree when setProjectDraftThreadId receives undefined", () => { + const store = useComposerDraftStore.getState(); + store.setProjectDraftThreadId(projectId, threadId, { + branch: "main", + worktreePath: "/tmp/main-worktree", + }); + store.setProjectDraftThreadId(projectId, threadId, { + branch: undefined, + worktreePath: undefined, + }); + + expect(useComposerDraftStore.getState().getDraftThread(threadId)).toMatchObject({ + projectId, + branch: "main", + worktreePath: "/tmp/main-worktree", + }); + }); }); describe("composerDraftStore setModel", () => { diff --git a/apps/web/src/composerDraftStore.ts b/apps/web/src/composerDraftStore.ts index a5002f200c07398255d19e4d7c8609e6724257c5..1606f2aeb1af30d84d44c8f0897686afa0a5b836 100644 --- a/apps/web/src/composerDraftStore.ts +++ b/apps/web/src/composerDraftStore.ts @@ -460,13 +460,13 @@ export const useComposerDraftStore = create()( projectId, createdAt: options?.createdAt ?? existingThread?.createdAt ?? new Date().toISOString(), branch: - options && "branch" in options - ? (options.branch ?? null) - : (existingThread?.branch ?? null), + options?.branch === undefined + ? (existingThread?.branch ?? null) + : (options.branch ?? null), worktreePath: - options && "worktreePath" in options - ? (options.worktreePath ?? null) - : (existingThread?.worktreePath ?? null), + options?.worktreePath === undefined + ? (existingThread?.worktreePath ?? null) + : (options.worktreePath ?? null), }; const hasSameProjectMapping = previousThreadIdForProject === threadId; const hasSameDraftThread = -- 2.54.0