From 0fb2f7c44ef8113ae43f6668f30d2ddc48b2ffc6 Mon Sep 17 00:00:00 2001 From: Vikhyath Mondreti Date: Thu, 26 Jun 2025 18:44:06 -0700 Subject: [PATCH] fix switch workspace bug (#560) Co-authored-by: Vikhyath Mondreti --- .../workspace-header/workspace-header.tsx | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/workspace-header/workspace-header.tsx b/apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/workspace-header/workspace-header.tsx index 4ffc0ba6de..152306206f 100644 --- a/apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/workspace-header/workspace-header.tsx +++ b/apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/workspace-header/workspace-header.tsx @@ -343,11 +343,11 @@ export const WorkspaceHeader = React.memo( setActiveWorkspace(workspace) setWorkspaceDropdownOpen(false) - // Use full workspace switch which now handles localStorage automatically - switchToWorkspace(workspace.id) - - // Update URL to include workspace ID + // Update URL first so sidebar filters use the new workspace ID router.push(`/workspace/${workspace.id}/w`) + + // Then switch workspace which will clear workflows and fetch new ones + switchToWorkspace(workspace.id) }, [activeWorkspace?.id, switchToWorkspace, router, setWorkspaceDropdownOpen] ) @@ -372,12 +372,11 @@ export const WorkspaceHeader = React.memo( setWorkspaces((prev) => [...prev, newWorkspace]) setActiveWorkspace(newWorkspace) - // Use switchToWorkspace to properly load workflows for the new workspace - // This will clear existing workflows, set loading state, and fetch workflows from DB - switchToWorkspace(newWorkspace.id) - - // Update URL to include new workspace ID + // Update URL first so sidebar filters use the new workspace ID router.push(`/workspace/${newWorkspace.id}/w`) + + // Then switch workspace which will clear workflows and fetch new ones + switchToWorkspace(newWorkspace.id) } } catch (err) { logger.error('Error creating workspace:', err)