Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(agent-changes): let the split router keep the changes viewer state (#6994)

Wolf Mermelsteindd5fce036017
diff --git a/apps/web/src/components/app/split-layout/split-router/app-routes.ts b/apps/web/src/components/app/split-layout/split-router/app-routes.ts
index 9d2ada2f9d..747994e9fd 100644
--- a/apps/web/src/components/app/split-layout/split-router/app-routes.ts
+++ b/apps/web/src/components/app/split-layout/split-router/app-routes.ts
@@ -1,4 +1,5 @@
import { activityRoute } from '@app/features/activity/route';
+import { DIFF_SEARCH_PARAM } from '@app/features/agent-changes/core/url-state';
import {
agentChatsRoute,
agentsRoute,
@@ -57,7 +58,9 @@ export const appSplitRoutes = defineRoutes({
...debugRoutes,
legacySplitRoute,
],
- globalSearch: ['referral_code'],
+ // The changes viewer keys its entries by host, not by pane, so its key is
+ // owned globally; a route-local one would be dropped on the next commit.
+ globalSearch: ['referral_code', DIFF_SEARCH_PARAM],
unmatchedPathHandlers: [handleLegacySplitPath],
defaultEntry: () => ({
location: { route: { matches: [{ id: 'view-inbox', params: {} }] } },
diff --git a/apps/web/src/components/app/split-layout/tests/app-route-search.test.ts b/apps/web/src/components/app/split-layout/tests/app-route-search.test.ts
new file mode 100644
index 0000000000..f740ea2ed9
--- /dev/null
+++ b/apps/web/src/components/app/split-layout/tests/app-route-search.test.ts
@@ -0,0 +1,59 @@
+import { DIFF_SEARCH_PARAM } from '@app/features/agent-changes/core/url-state';
+import { createRoutesManifest } from '@app/lib/split-router/routes';
+import {
+ decodeSplitRouterLocation,
+ serializeSplitRouterLocation,
+} from '@app/lib/split-router/url';
+import { describe, expect, it, vi } from 'vitest';
+import { appSplitRoutes } from '../split-router/app-routes';
+
+vi.mock('@service-storage/websocket', () => ({
+ storageWS: { reconnectIfDisconnected: vi.fn() },
+ createWebSocketJob: vi.fn(),
+}));
+vi.mock('@service-connection/websocket', () => ({
+ ws: { addEventListener: vi.fn(), send: vi.fn() },
+ state: () => 'closed',
+ createConnectionBlockWebsocketEffect: vi.fn(),
+ createConnectionWebsocketEffect: vi.fn(),
+}));
+
+const routes = createRoutesManifest(appSplitRoutes);
+const viewerState = `${DIFF_SEARCH_PARAM}=session-1%3Asplit%3Aunified`;
+
+function roundTrip(pathname: string, search: string, committed: boolean) {
+ const location = { pathname, search: `?${search}`, hash: '' };
+ const { entries } = decodeSplitRouterLocation({ routes, location });
+ return serializeSplitRouterLocation({
+ routes,
+ entries,
+ previous: location,
+ // A layout change commits without the inbound query; only globally owned
+ // keys survive it.
+ preserveExternalSearch: !committed,
+ });
+}
+
+describe('application route search ownership', () => {
+ it.each([
+ ['/agents/session-1', 'the agents workspace'],
+ ['/coders/session-1', 'a coding session'],
+ ['/agent/session-1', 'the agent block'],
+ ])('keeps the changes viewer state on %s (%s)', (pathname) => {
+ expect(roundTrip(pathname, viewerState, false)).toContain(viewerState);
+ expect(roundTrip(pathname, viewerState, true)).toContain(viewerState);
+ });
+
+ it('keeps a neighbouring pane’s viewer state when one pane navigates', () => {
+ const search = `${DIFF_SEARCH_PARAM}=session-1%3Asplit%3Aunified%2Csession-2%3Achanges-only%3Asplit`;
+ expect(roundTrip('/agents/session-1/~/mail', search, true)).toContain(
+ search
+ );
+ });
+
+ it('drops search keys no route owns', () => {
+ expect(roundTrip('/agents/session-1', 'unowned=1', true)).not.toContain(
+ 'unowned'
+ );
+ });
+});
diff --git a/apps/web/src/features/agent-changes/core/url-state.ts b/apps/web/src/features/agent-changes/core/url-state.ts
index 7c05181ab3..8017d78647 100644
--- a/apps/web/src/features/agent-changes/core/url-state.ts
+++ b/apps/web/src/features/agent-changes/core/url-state.ts
@@ -1,5 +1,13 @@
import type { DiffStyle, PaneLayout } from './layout';
+/**
+ * The query key the viewer stores its state under. One key holds every host's
+ * entry, so the split router owns it globally rather than per route: the
+ * viewer mounts wherever an agent session does, and a pane that navigates
+ * elsewhere must not drop a neighbouring pane's entry.
+ */
+export const DIFF_SEARCH_PARAM = 'diff';
+
export type DiffUrlState = { layout: PaneLayout; diffStyle: DiffStyle };
export const DEFAULT_DIFF_URL_STATE: DiffUrlState = {
diff --git a/apps/web/src/features/agent-changes/url-diff-state.ts b/apps/web/src/features/agent-changes/url-diff-state.ts
index dbafe3d6ef..ee812684af 100644
--- a/apps/web/src/features/agent-changes/url-diff-state.ts
+++ b/apps/web/src/features/agent-changes/url-diff-state.ts
@@ -2,6 +2,7 @@ import { useSearchParams } from '@solidjs/router';
import type { Accessor } from 'solid-js';
import type { DiffStyle, PaneLayout } from './core/layout';
import {
+ DIFF_SEARCH_PARAM,
type DiffUrlState,
readDiffUrlState,
writeDiffUrlState,
@@ -10,12 +11,17 @@ import {
/** Read directly from the router so reloads and Back/Forward restore the view. */
export function createUrlDiffState(scopeKey: Accessor<string | undefined>) {
const [params, setParams] = useSearchParams();
- const state = () => readDiffUrlState(params.diff, scopeKey());
+ const state = () => readDiffUrlState(params[DIFF_SEARCH_PARAM], scopeKey());
const update = (patch: Partial<DiffUrlState>) => {
const id = scopeKey();
if (!id) return;
setParams(
- { diff: writeDiffUrlState(params.diff, id, { ...state(), ...patch }) },
+ {
+ [DIFF_SEARCH_PARAM]: writeDiffUrlState(params[DIFF_SEARCH_PARAM], id, {
+ ...state(),
+ ...patch,
+ }),
+ },
{ replace: false, scroll: false }
);
};