Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

Preserve draft branch/worktree when update options are undefined

Julius Marminge005e13089a4a
diff --git a/apps/web/src/composerDraftStore.test.ts b/apps/web/src/composerDraftStore.test.ts
index ce88deb49..c2dd5c124 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 a5002f200..1606f2aeb 100644
--- a/apps/web/src/composerDraftStore.ts
+++ b/apps/web/src/composerDraftStore.ts
@@ -460,13 +460,13 @@ export const useComposerDraftStore = create<ComposerDraftStoreState>()(
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 =