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 =