From 8a2ac99aa0cf2e57b94cd63dcb1bef00ce70f07d Mon Sep 17 00:00:00 2001 From: Ammar Date: Mon, 8 Dec 2025 20:27:35 -0600 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20fix:=20prevent=20stale=20redirec?= =?UTF-8?q?t=20after=20workspace=20deletion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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_ --- src/browser/contexts/WorkspaceContext.tsx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/browser/contexts/WorkspaceContext.tsx b/src/browser/contexts/WorkspaceContext.tsx index b62990427d..37fd1e345e 100644 --- a/src/browser/contexts/WorkspaceContext.tsx +++ b/src/browser/contexts/WorkspaceContext.tsx @@ -353,9 +353,10 @@ export function WorkspaceProvider(props: WorkspaceProviderProps) { await loadWorkspaceMetadata(); // Clear selected workspace if it was removed - if (selectedWorkspace?.workspaceId === workspaceId) { - setSelectedWorkspace(null); - } + // Use functional update to check *current* selection, not stale closure value + setSelectedWorkspace((current) => + current?.workspaceId === workspaceId ? null : current + ); return { success: true }; } else { console.error("Failed to remove workspace:", result.error); @@ -367,7 +368,7 @@ export function WorkspaceProvider(props: WorkspaceProviderProps) { return { success: false, error: errorMessage }; } }, - [loadWorkspaceMetadata, refreshProjects, selectedWorkspace, setSelectedWorkspace, api] + [loadWorkspaceMetadata, refreshProjects, setSelectedWorkspace, api] ); const renameWorkspace = useCallback(