From a07b2d5b935c9f2063a57e515b4efa54986684c2 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Sun, 19 Apr 2026 16:17:30 +0000 Subject: [PATCH] fix(frontend): auto-select new project on create (race with fallback effect) Co-Authored-By: thesyperdev@gmail.com --- frontend/src/components/CreateProjectModal.tsx | 5 ++++- frontend/src/hooks/useProjects.ts | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/frontend/src/components/CreateProjectModal.tsx b/frontend/src/components/CreateProjectModal.tsx index 49eae1c..9a09db2 100644 --- a/frontend/src/components/CreateProjectModal.tsx +++ b/frontend/src/components/CreateProjectModal.tsx @@ -20,8 +20,11 @@ export default function CreateProjectModal({ onClose }: Props): JSX.Element { mutationFn: (body: { name: string; path: string; repo_url: string | null }) => api.post('/api/projects', body), onSuccess: (project) => { - qc.invalidateQueries({ queryKey: ['projects'] }); + qc.setQueryData(['projects'], (prev) => + prev ? [...prev, project] : [project], + ); setCurrent(project.id); + qc.invalidateQueries({ queryKey: ['projects'] }); onClose(); }, }); diff --git a/frontend/src/hooks/useProjects.ts b/frontend/src/hooks/useProjects.ts index 5585b4b..a841719 100644 --- a/frontend/src/hooks/useProjects.ts +++ b/frontend/src/hooks/useProjects.ts @@ -16,7 +16,7 @@ export function useProjects() { useEffect(() => { const list = query.data; if (!list || list.length === 0) return; - if (!currentId || !list.some((p) => p.id === currentId)) { + if (currentId == null) { setCurrent(list[0].id); } }, [query.data, currentId, setCurrent]);