Skip to content

Commit 998ca8f

Browse files
committed
🤖 fix: buffer Start New Agent until projects load
1 parent f2a6ef9 commit 998ca8f

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

src/browser/App.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ function AppInner() {
102102

103103
const {
104104
projects,
105+
loading: projectsLoading,
105106
removeProject,
106107
openProjectCreateModal,
107108
isProjectCreateModalOpen,
@@ -136,6 +137,13 @@ function AppInner() {
136137
const projectsRef = useRef(projects);
137138
projectsRef.current = projects;
138139

140+
const projectsLoadingRef = useRef(projectsLoading);
141+
projectsLoadingRef.current = projectsLoading;
142+
143+
// When "Start New Agent" is triggered during cold start, projects may still be loading.
144+
// Buffer the action and flush it once projects are available.
145+
const pendingStartNewAgentRef = useRef(false);
146+
139147
const pendingNewWorkspaceProjectRef = useRef(pendingNewWorkspaceProject);
140148
pendingNewWorkspaceProjectRef.current = pendingNewWorkspaceProject;
141149

@@ -661,6 +669,11 @@ function AppInner() {
661669
for await (const _ of iterator) {
662670
if (signal.aborted) break;
663671

672+
if (projectsLoadingRef.current) {
673+
pendingStartNewAgentRef.current = true;
674+
continue;
675+
}
676+
664677
const projectPath =
665678
selectedWorkspaceRef.current?.projectPath ??
666679
pendingNewWorkspaceProjectRef.current ??
@@ -681,6 +694,25 @@ function AppInner() {
681694
return () => abortController.abort();
682695
}, [api]);
683696

697+
// Flush any pending menu-triggered "Start New Agent" once projects finish loading.
698+
useEffect(() => {
699+
if (projectsLoading) return;
700+
if (!pendingStartNewAgentRef.current) return;
701+
702+
const projectPath =
703+
selectedWorkspaceRef.current?.projectPath ??
704+
pendingNewWorkspaceProjectRef.current ??
705+
getFirstProjectPath(projects);
706+
707+
pendingStartNewAgentRef.current = false;
708+
709+
if (!projectPath) {
710+
console.warn("No projects available for workspace creation");
711+
return;
712+
}
713+
714+
startWorkspaceCreationRef.current(projectPath);
715+
}, [projectsLoading, projects]);
684716
// Handle workspace fork switch event
685717
useEffect(() => {
686718
const handleForkSwitch = (e: Event) => {

0 commit comments

Comments
 (0)