Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion frontend/src/components/CreateProjectModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ export default function CreateProjectModal({ onClose }: Props): JSX.Element {
mutationFn: (body: { name: string; path: string; repo_url: string | null }) =>
api.post<Project>('/api/projects', body),
onSuccess: (project) => {
qc.invalidateQueries({ queryKey: ['projects'] });
qc.setQueryData<Project[]>(['projects'], (prev) =>
prev ? [...prev, project] : [project],
);
setCurrent(project.id);
qc.invalidateQueries({ queryKey: ['projects'] });
onClose();
},
});
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/hooks/useProjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Comment on lines +19 to 21
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Removed guard allows stale project ID to persist after project deletion

The old code reset the current project when the stored ID was not found in the fetched project list: if (!currentId || !list.some((p) => p.id === currentId)). The new code only checks if (currentId == null), removing the !list.some(...) guard. If a project is deleted (via API, CLI tool, or database reset) while its ID is stored in localStorage, the currentProjectId remains a non-null stale string, so currentId == null is false and the auto-selection never fires. This causes the ProjectSelector to show "Select project" (frontend/src/components/ProjectSelector.tsx:15 finds no match), all page queries (Dashboard, Tasks, Sessions, etc.) to filter by a non-existent project ID returning empty results, and SSE events to be silently dropped at frontend/src/events/EventBus.ts:153-158 because the event's project_id won't match the stale ID.

Suggested change
if (currentId == null) {
setCurrent(list[0].id);
}
if (currentId == null || !list.some((p) => p.id === currentId)) {
setCurrent(list[0].id);
}
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

}, [query.data, currentId, setCurrent]);
Expand Down