🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
✨ feat: add use switch workspace hook (#15979)
Rdmclin2cdcd57970bdb
diff --git a/src/business/client/hooks/useSwitchWorkspace.ts b/src/business/client/hooks/useSwitchWorkspace.tsindex 2389fce7b03..ad5b79c98b4 100644--- a/src/business/client/hooks/useSwitchWorkspace.ts+++ b/src/business/client/hooks/useSwitchWorkspace.ts@@ -5,7 +5,24 @@ export interface SwitchWorkspaceActions {const noop = async (): Promise<void> => {};+/**+ * Workspace switch invoked from imperative call sites that represent an+ * explicit user choice (e.g. switcher click, wizard landing, accept-invite,+ * post-leave redirect). Implementations may attach side effects appropriate+ * to the user-intent semantics.+ */export const useSwitchWorkspace = (): SwitchWorkspaceActions => ({switchToPersonal: noop,switchWorkspace: noop,});++/**+ * Workspace switch invoked from passive reconciliation sources (e.g. URL+ * sync) where the active workspace is being aligned with external state+ * rather than chosen by the user. Implementations must not attach+ * user-intent side effects.+ */+export const useSilentSwitchWorkspace = (): SwitchWorkspaceActions => ({+ switchToPersonal: noop,+ switchWorkspace: noop,+});diff --git a/src/features/Workspace/__tests__/workspaceSlugHooks.test.tsx b/src/features/Workspace/__tests__/workspaceSlugHooks.test.tsxindex 92fdef2b45f..4ca43508608 100644--- a/src/features/Workspace/__tests__/workspaceSlugHooks.test.tsx+++ b/src/features/Workspace/__tests__/workspaceSlugHooks.test.tsx@@ -36,7 +36,7 @@ const mockWorkspaceStore = (state: WorkspaceStateMock) => {vi.spyOn(useActiveWorkspaceIdModule, 'useActiveWorkspaceId').mockReturnValue(state.activeWorkspaceId,);- vi.spyOn(useSwitchWorkspaceModule, 'useSwitchWorkspace').mockReturnValue({+ vi.spyOn(useSwitchWorkspaceModule, 'useSilentSwitchWorkspace').mockReturnValue({switchToPersonal: state.switchToPersonal as any,switchWorkspace: state.switchWorkspace as any,});diff --git a/src/features/Workspace/useWorkspaceUrlSync.ts b/src/features/Workspace/useWorkspaceUrlSync.tsindex a8bd5836b3d..8cd3a351e02 100644--- a/src/features/Workspace/useWorkspaceUrlSync.ts+++ b/src/features/Workspace/useWorkspaceUrlSync.ts@@ -5,7 +5,7 @@ import { useLocation } from 'react-router-dom';import { useActiveWorkspaceId } from '@/business/client/hooks/useActiveWorkspaceId';import { useIsWorkspaceLoading } from '@/business/client/hooks/useIsWorkspaceLoading';-import { useSwitchWorkspace } from '@/business/client/hooks/useSwitchWorkspace';+import { useSilentSwitchWorkspace } from '@/business/client/hooks/useSwitchWorkspace';import { useWorkspaces } from '@/business/client/hooks/useWorkspaces';/**@@ -73,7 +73,10 @@ export const useWorkspaceUrlSync = (): void => {const workspaces = useWorkspaces();const activeId = useActiveWorkspaceId();const isLoading = useIsWorkspaceLoading();- const { switchWorkspace, switchToPersonal } = useSwitchWorkspace();+ // URL is a passive source, not an explicit user intent — use the silent+ // variant so refreshing or following a `/{slug}` link is not treated as+ // a user-driven switch.+ const { switchWorkspace, switchToPersonal } = useSilentSwitchWorkspace();// `useLayoutEffect` (not `useEffect`) so the workspace switch is scheduled// before the browser paints. With `useEffect` there is one paintable frame