Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(agents): stop the Agents workspace remounting on conversation select (#8896)
Eric Hayes7cae95c80c87
diff --git a/apps/web/src/features/agents-view/route-views.tsx b/apps/web/src/features/agents-view/route-views.tsxindex 79c0f06002..ef31c278a1 100644--- a/apps/web/src/features/agents-view/route-views.tsx+++ b/apps/web/src/features/agents-view/route-views.tsx@@ -162,7 +162,7 @@ export const AgentsRouteView = withAuth(() => {><Showwhen={isTouchDevice() && route()}- fallback={<AgentsView initialRoute={route()} />}+ fallback={<AgentsView route={route()} />}>{(current) => (<RedirectSplitdiff --git a/apps/web/src/features/agents-view/views/AgentsView.tsx b/apps/web/src/features/agents-view/views/AgentsView.tsxindex 5df795927b..abdc7ab100 100644--- a/apps/web/src/features/agents-view/views/AgentsView.tsx+++ b/apps/web/src/features/agents-view/views/AgentsView.tsx@@ -33,6 +33,7 @@ import {Show,Suspense,Switch,+ useTransition,} from 'solid-js';import { routineContent } from '../../routines/routine-navigation';import { RoutinesPage } from '../../routines/routines-page';@@ -79,14 +80,14 @@ function LoadingComposer() {);}-function AgentsWorkspace(props: { initialRoute?: AgentsRoute }) {+function AgentsWorkspace(props: { route?: AgentsRoute }) {const panel = useSplitPanelOrThrow();const layout = useSplitLayout();const orchestrator = useGlobalBlockOrchestrator();const userId = useUserId();useWarmAgentSessionQuery(userId);const notifications = useGlobalNotificationSource();- const mode = (): AgentsMode => props.initialRoute?.mode ?? 'chat';+ const mode = (): AgentsMode => props.route?.mode ?? 'chat';// The composer's Chat/Code choice; an open conversation keeps its own mode.const workspace = createWorkspaceMode(userId());const listView = createConversationListView(userId());@@ -100,13 +101,46 @@ function AgentsWorkspace(props: { initialRoute?: AgentsRoute }) {const [selected, setSelected] = createSignal<SelectedConversation | undefined>(- props.initialRoute+ props.route? {- conversation: props.initialRoute.conversation,- activeConversationId: props.initialRoute.conversation.id,+ conversation: props.route.conversation,+ activeConversationId: props.route.conversation.id,}: undefined);+ // A conversation suspends until its first load resolves. Switching inside a+ // transition keeps the current one on screen until then, instead of blanking+ // the pane to a spinner; the sidebar highlights the target meanwhile.+ const [switching, startSwitch] = useTransition();+ const selectConversation = (conversation: AgentConversationTarget) =>+ fireAndForget(+ startSwitch(() => {+ setPage('new');+ setSelected({ conversation, activeConversationId: conversation.id });+ }),+ 'agents-view'+ );+ // The list and its conversations share one mount (`mountKey` in the routes),+ // so the selection follows navigation, including Back and Forward.+ createEffect(+ on(+ () => {+ const conversation = props.route?.conversation;+ return conversation && `${conversation.type}:${conversation.id}`;+ },+ () => {+ const conversation = props.route?.conversation;+ if (!conversation) {+ setSelected(undefined);+ return;+ }+ // An adopted session id is the conversation already on screen.+ if (selected()?.activeConversationId === conversation.id) return;+ selectConversation(conversation);+ },+ { defer: true }+ )+ );const dataMode = () => dataModeFor(selected() ? mode() : workspace.mode());const [mobileList, setMobileList] = createSignal(!isRoutinesPage());const [draft, setDraft] = createSignal('');@@ -240,7 +274,7 @@ function AgentsWorkspace(props: { initialRoute?: AgentsRoute }) {id: agentsRouteId({ mode: targetMode, conversation }),};if (!event?.shiftKey && panel.handle.content().id === next.id) {- setSelected({ conversation, activeConversationId: conversation.id });+ selectConversation(conversation);return;}const result = layout.openWithSplit(next, {@@ -301,7 +335,7 @@ function AgentsWorkspace(props: { initialRoute?: AgentsRoute }) {onFilterChange={listView.setSelected}onClearFilters={listView.clear}onGroupingChange={listView.setGrouping}- activePage={selected() ? undefined : page()}+ activePage={selected() || switching() ? undefined : page()}onCreateRoutine={() =>layout.popoverSplit({ type: 'component', id: 'routine-compose' })}@@ -317,7 +351,11 @@ function AgentsWorkspace(props: { initialRoute?: AgentsRoute }) {: openPage(next)}modeForConversation={modeForConversation}- activeConversationId={selected()?.activeConversationId}+ activeConversationId={+ switching()+ ? props.route?.conversation.id+ : selected()?.activeConversationId+ }search={search()}conversations={partitioned().conversations}archived={partitioned().archived}@@ -367,72 +405,74 @@ function AgentsWorkspace(props: { initialRoute?: AgentsRoute }) {class="main touch:pt-[calc(var(--mobile-content-inset-top,var(--safe-top,0px))+0.5rem)] touch:[&>*]:[--mobile-content-inset-top:0px]"classList={{ hidden: isTouchDevice() && mobileList() }}>- <Show- when={selected()?.conversation}- keyed- fallback={- <>- <Show when={page() !== 'routines'}>- <Topbar- title={pageTitle()}- onBack={- isTouchDevice()- ? () => setMobileList(true)- : undefined- }- />- </Show>- <div class="body">- <Suspense fallback={<LoadingComposer />}>- <Switch>- <Match when={page() === 'routines'}>- <RoutinesPage />- </Match>- <Match when={page() === 'connections'}>- <IntegrationsPage />- </Match>- <Match when={page() === 'agents'}>- <AgentSettings- createKind={creatingKind()}- onCloseCreate={() =>- setCreatingKind(undefined)+ {/* Outside the keyed Show, so a conversation switched to in a+ transition keeps the previous one shown while it loads. */}+ <Suspense fallback={<LoadingComposer />}>+ <Show+ when={selected()?.conversation}+ keyed+ fallback={+ <>+ <Show when={page() !== 'routines'}>+ <Topbar+ title={pageTitle()}+ onBack={+ isTouchDevice()+ ? () => setMobileList(true)+ : undefined+ }+ />+ </Show>+ <div class="body">+ <Suspense fallback={<LoadingComposer />}>+ <Switch>+ <Match when={page() === 'routines'}>+ <RoutinesPage />+ </Match>+ <Match when={page() === 'connections'}>+ <IntegrationsPage />+ </Match>+ <Match when={page() === 'agents'}>+ <AgentSettings+ createKind={creatingKind()}+ onCloseCreate={() =>+ setCreatingKind(undefined)+ }+ />+ </Match>+ </Switch>+ <div+ class="contents"+ classList={{ hidden: page() !== 'new' }}+ >+ <NewChatPage+ mode={workspace.mode()}+ onModeChange={workspace.setMode}+ active={+ !isTouchDevice() ||+ (!mobileList() && page() === 'new')}+ registerFocus={(focus) => {+ composerFocus = focus;+ }}+ workspaceId={panel.handle.id}+ draft={draft()}+ onDraftChange={setDraft}+ roster={rosterSource.roster()}+ rosterLoading={rosterSource.loading()}+ availabilityLoading={rosterSource.availabilityLoading()}+ onStart={startConversation}+ onOpenRoster={openRoster}/>- </Match>- </Switch>- <div- class="contents"- classList={{ hidden: page() !== 'new' }}- >- <NewChatPage- mode={workspace.mode()}- onModeChange={workspace.setMode}- active={- !isTouchDevice() ||- (!mobileList() && page() === 'new')- }- registerFocus={(focus) => {- composerFocus = focus;- }}- workspaceId={panel.handle.id}- draft={draft()}- onDraftChange={setDraft}- roster={rosterSource.roster()}- rosterLoading={rosterSource.loading()}- availabilityLoading={rosterSource.availabilityLoading()}- onStart={startConversation}- onOpenRoster={openRoster}- />- </div>- </Suspense>- </div>- </>- }- >- {(conversation) => (- <Switch>- <Match when={conversation.type === 'agent_session'}>- <Suspense fallback={<LoadingComposer />}>+ </div>+ </Suspense>+ </div>+ </>+ }+ >+ {(conversation) => (+ <Switch>+ <Match when={conversation.type === 'agent_session'}><AgentSessionPaneid={conversation.id}notificationSource={notifications}@@ -441,11 +481,9 @@ function AgentsWorkspace(props: { initialRoute?: AgentsRoute }) {}onDeleted={showComposer}/>- </Suspense>- </Match>- <Match when={true}>- <div class="body">- <Suspense fallback={<LoadingComposer />}>+ </Match>+ <Match when={true}>+ <div class="body"><ChatEmptyStateContext.Providervalue={() => (<div class="px-4 py-16 text-center">@@ -461,12 +499,12 @@ function AgentsWorkspace(props: { initialRoute?: AgentsRoute }) {splitPanelContext={panel}/></ChatEmptyStateContext.Provider>- </Suspense>- </div>- </Match>- </Switch>- )}- </Show>+ </div>+ </Match>+ </Switch>+ )}+ </Show>+ </Suspense></main><Show when={isTouchDevice() && mobileList()}><div@@ -488,12 +526,12 @@ function AgentsWorkspace(props: { initialRoute?: AgentsRoute }) {}/** Dedicated Agents workspace used by the new app views layout. */-export function AgentsView(props: { initialRoute?: AgentsRoute }) {+export function AgentsView(props: { route?: AgentsRoute }) {return (<ListEntityMetadataQueryProvider><StaticMarkdownContext><Suspense fallback={<LoadingComposer />}>- <AgentsWorkspace initialRoute={props.initialRoute} />+ <AgentsWorkspace route={props.route} /></Suspense></StaticMarkdownContext></ListEntityMetadataQueryProvider>diff --git a/apps/web/src/lib/split-router/README.md b/apps/web/src/lib/split-router/README.mdindex 5cc31bf9c2..0139e8288f 100644--- a/apps/web/src/lib/split-router/README.md+++ b/apps/web/src/lib/split-router/README.md@@ -2,7 +2,9 @@`useBeforeLeave` runs when a navigation leaves the registering route, closes itspane, or changes an explicitly watched search namespace. Returning `false` keeps-the current destination. Solid cleanup only unregisters the guard.+the current destination. Solid cleanup only unregisters the guard. Routes that+share a `mountKey` count as one route: moving between them keeps the view+mounted and does not leave it.Use `context.onCommit(callback)` to stage a synchronous side effect that must runonly after the navigation commits. Capture outgoing state while the guard runs;diff --git a/apps/web/src/lib/split-router/routes/define.ts b/apps/web/src/lib/split-router/routes/define.tsindex 18fdad07dc..b840b786a2 100644--- a/apps/web/src/lib/split-router/routes/define.ts+++ b/apps/web/src/lib/split-router/routes/define.ts@@ -30,6 +30,7 @@ type SplitRouteDefinitionConstraint = {| readonly string[]| '*'| ((entry: Readonly<Entry>) => readonly string[]);+ mountKey?: string;remountKey?: unknown;preload?: unknown;info?: SplitRouteInfo;diff --git a/apps/web/src/lib/split-router/routes/queries.ts b/apps/web/src/lib/split-router/routes/queries.tsindex 0e2b250786..6babb9e795 100644--- a/apps/web/src/lib/split-router/routes/queries.ts+++ b/apps/web/src/lib/split-router/routes/queries.ts@@ -184,7 +184,10 @@ function renderKeys(routes: SplitRoutesManifest, entry: Entry): string[] {const context = { entryId: entry.id };const remountKey = node.definition.remountKey?.(params, context);- return JSON.stringify([node.definition.id, remountKey ?? null]);+ return JSON.stringify([+ node.definition.mountKey ?? node.definition.id,+ remountKey ?? null,+ ]);});}diff --git a/apps/web/src/lib/split-router/routes/types.ts b/apps/web/src/lib/split-router/routes/types.tsindex bcafe68dd1..f24cd7765c 100644--- a/apps/web/src/lib/split-router/routes/types.ts+++ b/apps/web/src/lib/split-router/routes/types.ts@@ -150,6 +150,12 @@ export type SplitRouteDefinition<| readonly string[]| '*'| ((entry: Readonly<Entry>) => readonly string[]);+ /**+ * Routes sharing a `mountKey` keep one mounted view while the pane moves+ * between them, so a workspace that renders several routes is not rebuilt on+ * each step. Defaults to the route id.+ */+ mountKey?: string;remountKey?: {bivarianceHack(params: StandardSchemaV1.InferOutput<TParamsSchema>,diff --git a/apps/web/src/lib/split-router/solid/outlet.tsx b/apps/web/src/lib/split-router/solid/outlet.tsxindex 5529f23d99..b36b682981 100644--- a/apps/web/src/lib/split-router/solid/outlet.tsx+++ b/apps/web/src/lib/split-router/solid/outlet.tsx@@ -94,9 +94,9 @@ function RouteMounted(props: { route: string }) {/*** Renders the next route component in the enclosing pane's branch. Its view- * stays mounted while its route id and `remountKey` are unchanged; params- * update in place. Outside any pane it renders the first pane's top-level- * route, whose component decides how the other panes render.+ * stays mounted while its route id (or shared `mountKey`) and `remountKey` are+ * unchanged; params update in place. Outside any pane it renders the first+ * pane's top-level route, whose component decides how the other panes render.*/export function Outlet(props: OutletProps) {const router = useSplitRouter();diff --git a/apps/web/src/lib/split-router/tests/solid.test.tsx b/apps/web/src/lib/split-router/tests/solid.test.tsxindex 20f0a1dce3..406fa23cc6 100644--- a/apps/web/src/lib/split-router/tests/solid.test.tsx+++ b/apps/web/src/lib/split-router/tests/solid.test.tsx@@ -36,7 +36,7 @@ import { Router } from '../solid/router';import { useBeforeLeave } from '../solid/use-before-leave';import { createTestPolicy } from './fixtures';-const counts = { drive: 0, document: 0 };+const counts = { drive: 0, document: 0, workspace: 0 };const documentTypeReads = vi.fn();let allowLeave = true;@@ -62,6 +62,17 @@ function DocumentView() {);}+function WorkspaceView() {+ const pane = usePane();+ const router = useSplitRouter();+ onMount(() => {+ counts.workspace += 1;+ });+ const item = () =>+ router.entry(pane())?.location.route.matches.at(-1)?.params.itemId;+ return <p data-testid="workspace">{`item:${item() ?? 'none'}`}</p>;+}+function DriveView() {const navigate = useNavigate();onMount(() => {@@ -160,6 +171,19 @@ const paneRoutes = [search: ['probe', 'other'],component: ProbeView,}),+ defineRoute({+ id: 'workspace',+ path: 'workspace',+ mountKey: 'workspace',+ component: WorkspaceView,+ }),+ defineRoute({+ id: 'workspace-item',+ path: 'workspace/:itemId',+ params: z.object({ itemId: z.string().min(1) }),+ mountKey: 'workspace',+ component: WorkspaceView,+ }),defineRoute({ id: 'home', path: 'home', component: () => <p>home</p> }),defineRoute({ id: 'guarded', path: 'guarded', component: GuardedView }),defineRoute({@@ -253,6 +277,7 @@ function renderPanes(beforeEach(() => {counts.drive = 0;counts.document = 0;+ counts.workspace = 0;documentTypeReads.mockClear();allowLeave = true;@@ -283,11 +308,26 @@ describe('split router Solid bindings', () => {await router.navigatePane(pane, '/drive/md/d2');expect(screen.getByTestId('document').textContent).toBe('md:d2');- expect(counts).toEqual({ drive: 1, document: 1 });+ expect(counts).toMatchObject({ drive: 1, document: 1 });expect(documentTypeReads).toHaveBeenCalledTimes(1);await router.navigatePane(pane, '/drive/pdf/d2');- expect(counts).toEqual({ drive: 1, document: 2 });+ expect(counts).toMatchObject({ drive: 1, document: 2 });+ });++ it('keeps one view mounted across routes that share a mount key', async () => {+ const { router } = renderPanes('/workspace');+ const pane = router.panes()[0]!;++ await router.navigatePane(pane, '/workspace/a');+ await router.navigatePane(pane, '/workspace/b');+ expect(screen.getByTestId('workspace').textContent).toBe('item:b');+ await router.navigatePane(pane, '/workspace');+ expect(counts.workspace).toBe(1);++ await router.navigatePane(pane, '/home');+ await router.navigatePane(pane, '/workspace/a');+ expect(counts.workspace).toBe(2);});it('lets panel chrome around a prop-less outlet use the hooks', async () => {diff --git a/apps/web/src/routes/routes.ts b/apps/web/src/routes/routes.tsindex 6bc59c42cb..0225cfe243 100644--- a/apps/web/src/routes/routes.ts+++ b/apps/web/src/routes/routes.ts@@ -313,11 +313,15 @@ export const settingsRoute = defineRoute({externalSearch: ['pair', 'createAgent'],});+// The Agents list and its conversations share one workspace mount, so picking+// a conversation swaps the pane beside the sidebar instead of rebuilding both.+const AGENTS_WORKSPACE_MOUNT = 'agents-workspace';+export const agentsRoute = defineRoute({id: 'agents',path: 'agents/:id',params: z.object({ id: z.string() }),- remountKey: ({ id }) => id,+ mountKey: AGENTS_WORKSPACE_MOUNT,claim: ({ id }) => ({ namespace: 'agent', id }),search: [changesSearch.namespace, agentDetailSearch.namespace],toReference: ({ id }) => uuidRouteReference(id, 'agent'),@@ -327,7 +331,7 @@ export const codersRoute = defineRoute({id: 'coders',path: 'coders/:id',params: z.object({ id: z.string() }),- remountKey: ({ id }) => id,+ mountKey: AGENTS_WORKSPACE_MOUNT,claim: ({ id }) => ({ namespace: 'agent', id }),search: [changesSearch.namespace, agentDetailSearch.namespace],toReference: ({ id }) => uuidRouteReference(id, 'agent'),@@ -338,7 +342,7 @@ export const agentChatsRoute = defineRoute({path: 'agents/chat/:id',aliases: ['agent-chats/:id'],params: z.object({ id: z.string() }),- remountKey: ({ id }) => id,+ mountKey: AGENTS_WORKSPACE_MOUNT,claim: ({ id }) => ({ namespace: 'chat', id }),search: [changesSearch.namespace],toReference: ({ id }) => uuidRouteReference(id, 'chat'),@@ -485,6 +489,7 @@ export const routineDetailRoute = defineRoute({export const agentsViewRoute = defineRoute({id: 'view-agents',path: 'agents',+ mountKey: AGENTS_WORKSPACE_MOUNT,search: '*' as const,externalSearch: ['createAgent'],claim: () => ({ namespace: 'component', id: 'agents' }),diff --git a/docs/agent-guide/ai-chat.md b/docs/agent-guide/ai-chat.mdindex 4927c980c9..f11c90142e 100644--- a/docs/agent-guide/ai-chat.md+++ b/docs/agent-guide/ai-chat.md@@ -362,6 +362,9 @@ the shimmer.entity it opens GitHub in a new tab. Either click leaves the session unopened.Changing the composer mode does not filter the sidebar.Selecting a row opens its own mode; Shift-click opens it in a new split.+ Switching conversations keeps the sidebar mounted (no reload or scroll reset)+ and the open conversation on screen until the next one has loaded; verify by+ tagging the workspace and row nodes and checking they survive the click.Right-click (or long-press on mobile) opens the same entity menu as Home:Rename, Favorite, Copy link, Share, Archive, Delete, and the other sessionactions. Archived sessions are grouped at the bottom under **Archived**.