Skip to content

Commit 98c2743

Browse files
authored
🤖 fix: prevent stale redirect after workspace deletion (#1001)
When deleting a workspace, the redirect logic was using a stale closure value of `selectedWorkspace`. If the user navigated to another workspace while the delete was in progress, they'd still get redirected to the project page because the callback captured the old selection. **Fix:** Use functional update form of `setSelectedWorkspace` to check the *current* selection at the time the delete completes, not the value captured when the callback was created. _Generated with `mux`_
1 parent 1cecc36 commit 98c2743

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/browser/contexts/WorkspaceContext.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,10 @@ export function WorkspaceProvider(props: WorkspaceProviderProps) {
353353
await loadWorkspaceMetadata();
354354

355355
// Clear selected workspace if it was removed
356-
if (selectedWorkspace?.workspaceId === workspaceId) {
357-
setSelectedWorkspace(null);
358-
}
356+
// Use functional update to check *current* selection, not stale closure value
357+
setSelectedWorkspace((current) =>
358+
current?.workspaceId === workspaceId ? null : current
359+
);
359360
return { success: true };
360361
} else {
361362
console.error("Failed to remove workspace:", result.error);
@@ -367,7 +368,7 @@ export function WorkspaceProvider(props: WorkspaceProviderProps) {
367368
return { success: false, error: errorMessage };
368369
}
369370
},
370-
[loadWorkspaceMetadata, refreshProjects, selectedWorkspace, setSelectedWorkspace, api]
371+
[loadWorkspaceMetadata, refreshProjects, setSelectedWorkspace, api]
371372
);
372373

373374
const renameWorkspace = useCallback(

0 commit comments

Comments
 (0)