From 7582db6df6883dd8b82a6242ba57c9957c1d25ef Mon Sep 17 00:00:00 2001 From: Jovines <1246634075@qq.com> Date: Mon, 18 May 2026 22:54:54 +0800 Subject: [PATCH] fix(mobile): sync project switch with draft target state (#1307) When a new session draft is open on mobile and the user switches projects via the ProjectBar, the draft target was not updated, causing a mismatch with the desktop project/branch selectors. handleProjectSwitch now mirrors the desktop handleDraftProjectChange: when a draft is open, it uses setActiveProjectIdOnly + setNewSessionDraftTarget instead of setActiveProject. The draft is also guarded against preserveDirectoryOverride to prevent overwriting a worktree-locked directory. When no draft is open, the original setActiveProject behavior is preserved. Co-authored-by: Jovines --- .../chat/MobileSessionStatusBar.tsx | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/packages/ui/src/components/chat/MobileSessionStatusBar.tsx b/packages/ui/src/components/chat/MobileSessionStatusBar.tsx index 801e82ea..a5dea54b 100644 --- a/packages/ui/src/components/chat/MobileSessionStatusBar.tsx +++ b/packages/ui/src/components/chat/MobileSessionStatusBar.tsx @@ -1436,6 +1436,7 @@ export const MobileSessionStatusBar: React.FC = ({ const projects = useProjectsStore((state) => state.projects); const activeProjectId = useProjectsStore((state) => state.activeProjectId); const setActiveProject = useProjectsStore((state) => state.setActiveProject); + const setActiveProjectIdOnly = useProjectsStore((state) => state.setActiveProjectIdOnly); const removeProject = useProjectsStore((state) => state.removeProject); const getActiveProject = useProjectsStore((state) => state.getActiveProject); @@ -1498,9 +1499,29 @@ export const MobileSessionStatusBar: React.FC = ({ }; const handleProjectSwitch = (projectId: string) => { - if (projectId !== activeProjectId) { - setActiveProject(projectId); + if (projectId === activeProjectId) { + return; } + const draft = useSessionUIStore.getState().newSessionDraft; + if (draft?.open) { + if ( + draft.pendingWorktreeRequestId || + draft.bootstrapPendingDirectory || + draft.preserveDirectoryOverride + ) { + return; + } + const project = projects.find((p) => p.id === projectId); + if (project) { + setActiveProjectIdOnly(projectId); + useSessionUIStore.getState().setNewSessionDraftTarget({ + projectId, + directoryOverride: project.path, + }); + } + return; + } + setActiveProject(projectId); }; const handleAddProject = () => {