Skip to content

Commit 97996b2

Browse files
committed
fix: add workspace to store synchronously before switching
When creating a workspace with async background operations, the frontend can try to access the workspace before React processes the state update. This causes a race condition where WorkspaceStore throws 'must call addWorkspace() first'. Fix by calling workspaceStore.addWorkspace() synchronously BEFORE setting the selected workspace. This ensures the store knows about the workspace immediately, regardless of when React batches the state updates.
1 parent 2272df4 commit 97996b2

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/browser/App.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,13 @@ function AppInner() {
610610
onProviderConfig={handleProviderConfig}
611611
onReady={handleCreationChatReady}
612612
onWorkspaceCreated={(metadata) => {
613-
// Add to workspace metadata map
613+
// IMPORTANT: Add workspace to store FIRST (synchronous) to ensure
614+
// the store knows about it before React processes the state updates.
615+
// This prevents race conditions where the UI tries to access the
616+
// workspace before the store has created its aggregator.
617+
workspaceStore.addWorkspace(metadata);
618+
619+
// Add to workspace metadata map (triggers React state update)
614620
setWorkspaceMetadata((prev) =>
615621
new Map(prev).set(metadata.id, metadata)
616622
);

0 commit comments

Comments
 (0)