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(web): release unmounted editor and list state (#8549)
teo7a85d5adc8ff
diff --git a/apps/web/AGENTS.md b/apps/web/AGENTS.mdindex 8c689b35ae..0add1d41bf 100644--- a/apps/web/AGENTS.md+++ b/apps/web/AGENTS.md@@ -76,6 +76,9 @@ Then trigger the interaction and read `window.__inst.log`. `'1,2,3' → '' → '## Development Patterns+Keep persistent list hotkeys free of mounted-view closures, and clear+virtualizer accessors when their view unmounts.+- Reuse `src/components/WorkspaceTexture.tsx` for the onboarding and Createdetail panel grain; pass the surface accent and a unique SVG filter ID.diff --git a/apps/web/src/features/next-soup/soup-view/use-soup-navigation-hotkeys.test.ts b/apps/web/src/features/next-soup/soup-view/use-soup-navigation-hotkeys.test.tsindex dcb8bbd2bc..a9cdc0186e 100644--- a/apps/web/src/features/next-soup/soup-view/use-soup-navigation-hotkeys.test.ts+++ b/apps/web/src/features/next-soup/soup-view/use-soup-navigation-hotkeys.test.ts@@ -337,6 +337,39 @@ describe('useSoupNavigationHotkeys', () => {dispose();});+ it('keeps detail navigation without reading the unmounted list virtualizer', () => {+ const virtualizer = vi.fn(() => undefined);+ const { soup, dispose, disposeView } = createRoot((dispose) => {+ const slots = createOwnedSlots();+ vi.mocked(withSplitPanelOwner).mockImplementation(slots.replace);+ const soup = createSoupState();+ setGroupedRows(soup);+ const disposeView = createRoot((disposeView) => {+ useSoupNavigationHotkeys({+ scopeId: 'test-scope',+ soup,+ splitHandle: createSplitHandleStub(),+ virtualizerHandle: virtualizer,+ });+ return disposeView;+ });+ return { soup, dispose, disposeView };+ });+ try {+ handlerFor('j')();+ expect(virtualizer).toHaveBeenCalled();+ disposeView();+ virtualizer.mockClear();+ handlerFor('j')();+ expect(soup.focus.id()).toBe('a2');+ handlerFor('k')();+ expect(soup.focus.id()).toBe('a1');+ expect(virtualizer).not.toHaveBeenCalled();+ } finally {+ dispose();+ }+ });+it('arrow keys share the header-skipping navigation', () => {const { soup, dispose } = setupHotkeys();soup.focus.set('a2');diff --git a/apps/web/src/features/next-soup/soup-view/use-soup-navigation-hotkeys.ts b/apps/web/src/features/next-soup/soup-view/use-soup-navigation-hotkeys.tsindex ef48b29938..8ea0916736 100644--- a/apps/web/src/features/next-soup/soup-view/use-soup-navigation-hotkeys.ts+++ b/apps/web/src/features/next-soup/soup-view/use-soup-navigation-hotkeys.ts@@ -10,7 +10,7 @@ import { createHotkeyGroup, registerHotkey } from '@core/hotkey/hotkeys';import { TOKENS } from '@core/hotkey/tokens';import { type EntityData, isTaskEntity } from '@entity/types/entity';import { Telemetry } from '@macro-inc/observability';-import { type Accessor, createMemo, onCleanup } from 'solid-js';+import { type Accessor, onCleanup } from 'solid-js';import type { VirtualizerHandle } from 'virtua/solid';import type { SoupState } from '../create-soup-state';@@ -29,23 +29,26 @@ type UseSoupNavigationHotkeysOptions = {error?: Accessor<Error | null>;};-export const useSoupNavigationHotkeys = (- options: UseSoupNavigationHotkeysOptions-) => {- const { scopeId, soup, splitHandle, virtualizerHandle } = options;+// These callbacks outlive SoupViewList. Keep their closure separate from the+// mounted view, and release the only route back to its virtualizer on cleanup.+function createPersistentNavigation(+ options: Omit<UseSoupNavigationHotkeysOptions, 'virtualizerHandle'>,+ viewport: { current?: Accessor<VirtualizerHandle | undefined> }+) {+ const { scopeId, soup, splitHandle } = options;const notificationSource = useGlobalNotificationSource();const scrollTo = (index: number) => {- const handle = virtualizerHandle();+ const handle = viewport.current?.();if (!handle) return;- virtualizerHandle()?.scrollToIndex(index, {+ handle.scrollToIndex(index, {align: 'nearest',});};- const navigationReferredFrom = createMemo(() => {+ const navigationReferredFrom = () => {const content = splitHandle.content();if (content.type === 'component' && isListViewID(content.id)) {@@ -54,7 +57,7 @@ export const useSoupNavigationHotkeys = (const referredFrom = splitHandle.referredFrom();return isListViewID(referredFrom) ? referredFrom : undefined;- });+ };const viewId = navigationReferredFrom();if (viewId) {@@ -94,60 +97,6 @@ export const useSoupNavigationHotkeys = (const navigateToOpenableEntity = (offset: -1 | 1) =>soup.navigate.by(offset, { skipGroupHeaders: true });- const navigateAndSelectEntity = (offset: number) => {- const nextRow = soup.navigate.by(offset, { skipGroupHeaders: true });- if (!nextRow) return true;- soup.selection.select(nextRow.row.original);- scrollTo(nextRow.index);- return true;- };-- const handleNavigationSelection = (offset: number) => {- const focusedEntity = soup.focus.item();- const next = soup.navigate.peekOffset(offset, { skipGroupHeaders: true });-- const selection = soup.selection;-- const nextEntity = next?.row.original;- if (!nextEntity) return true;-- // At the boundary (top/bottom), peekOffset clamps and returns the- // same item we're already focused on. No-op to avoid toggling.- if (focusedEntity && nextEntity.id === focusedEntity.id) return true;-- if (!focusedEntity) {- navigateAndSelectEntity(offset);- return true;- }-- if (selection.count() === 0) {- selection.toggle(focusedEntity);- return true;- }-- if (- !selection.isSelected(focusedEntity.id) &&- !selection.isSelected(nextEntity.id)- ) {- selection.toggle(focusedEntity);- navigateAndSelectEntity(offset);- return true;- }-- if (selection.isSelected(nextEntity.id)) {- selection.toggle(focusedEntity);- soup.navigate.by(offset, { skipGroupHeaders: true });- scrollTo(next.index);- return true;- }-- navigateAndSelectEntity(offset);-- return true;- };-- const group = createHotkeyGroup();-const { fetchNextPage, isFetching, isFetchingNextPage, hasNextPage } =options;@@ -213,14 +162,6 @@ export const useSoupNavigationHotkeys = (disposeWithOwner: false,});- registerHotkey({- hotkey: ['arrowdown'],- scopeId,- description: 'Down',- keyDownHandler: navigateDown,- hide: true,- }).withGroup(group);-// Keep j/k registered on the split scope after the list unmounts. When an// entity is opened from a list into the same split, this lets j/k continue// navigating the originating soup list and update the split content.@@ -235,6 +176,95 @@ export const useSoupNavigationHotkeys = (disposeWithOwner: false,});+ return { scrollTo, navigateDown, navigateUp };+}++export const useSoupNavigationHotkeys = (+ options: UseSoupNavigationHotkeysOptions+) => {+ const { scopeId, soup, splitHandle } = options;+ const viewport: { current?: Accessor<VirtualizerHandle | undefined> } = {+ current: options.virtualizerHandle,+ };+ onCleanup(() => {+ viewport.current = undefined;+ });+ const { scrollTo, navigateDown, navigateUp } = createPersistentNavigation(+ {+ scopeId,+ soup,+ splitHandle,+ hasNextPage: options.hasNextPage,+ isFetching: options.isFetching,+ isFetchingNextPage: options.isFetchingNextPage,+ fetchNextPage: options.fetchNextPage,+ error: options.error,+ },+ viewport+ );++ const navigateAndSelectEntity = (offset: number) => {+ const nextRow = soup.navigate.by(offset, { skipGroupHeaders: true });+ if (!nextRow) return true;+ soup.selection.select(nextRow.row.original);+ scrollTo(nextRow.index);+ return true;+ };++ const handleNavigationSelection = (offset: number) => {+ const focusedEntity = soup.focus.item();+ const next = soup.navigate.peekOffset(offset, { skipGroupHeaders: true });++ const selection = soup.selection;++ const nextEntity = next?.row.original;+ if (!nextEntity) return true;++ // At the boundary (top/bottom), peekOffset clamps and returns the+ // same item we're already focused on. No-op to avoid toggling.+ if (focusedEntity && nextEntity.id === focusedEntity.id) return true;++ if (!focusedEntity) {+ navigateAndSelectEntity(offset);+ return true;+ }++ if (selection.count() === 0) {+ selection.toggle(focusedEntity);+ return true;+ }++ if (+ !selection.isSelected(focusedEntity.id) &&+ !selection.isSelected(nextEntity.id)+ ) {+ selection.toggle(focusedEntity);+ navigateAndSelectEntity(offset);+ return true;+ }++ if (selection.isSelected(nextEntity.id)) {+ selection.toggle(focusedEntity);+ soup.navigate.by(offset, { skipGroupHeaders: true });+ scrollTo(next.index);+ return true;+ }++ navigateAndSelectEntity(offset);++ return true;+ };++ const group = createHotkeyGroup();++ registerHotkey({+ hotkey: ['arrowdown'],+ scopeId,+ description: 'Down',+ keyDownHandler: navigateDown,+ hide: true,+ }).withGroup(group);+registerHotkey({hotkey: ['arrowup'],scopeId,diff --git a/apps/web/src/features/next-soup/soup-view/use-soup-view-hotkeys.ts b/apps/web/src/features/next-soup/soup-view/use-soup-view-hotkeys.tsindex d91ca8d689..5f7a5aac2b 100644--- a/apps/web/src/features/next-soup/soup-view/use-soup-view-hotkeys.ts+++ b/apps/web/src/features/next-soup/soup-view/use-soup-view-hotkeys.ts@@ -50,26 +50,18 @@ type UseSoupViewHotkeysOptions = {fetchNextGroupPage: (groupKey: string) => Promise<void>;};-export const useSoupViewHotkeys = (options: UseSoupViewHotkeysOptions) => {- const {- scopeId,- soup,- splitHandle,- virtualizerHandle,- currentView,- activeTab,- applyTabPreset,- fetchNextGroupPage,- } = options;-- const analytics = useAnalytics();- const notificationSource = useGlobalNotificationSource();-+// Escape belongs to the split, not the mounted list. Do not capture view+// props, virtualizers, or the other view hotkeys in its persistent callbacks.+function registerSplitEscapeHotkey(+ scopeId: string,+ selection: SoupState['selection'],+ splitHandle: SplitHandle+) {const splitIsUnifiedList = () => isListViewID(splitHandle.content().id);// escape - Multi-purpose: Clear selection / Close spotlightconst clearMultiCondition = () =>- soup.selection.count() > 0 && splitIsUnifiedList();+ selection.count() > 0 && splitIsUnifiedList();const closeSpotlightCondition = () => splitHandle.isSpotLight();const escapeDescription = () => {@@ -82,6 +74,50 @@ export const useSoupViewHotkeys = (options: UseSoupViewHotkeysOptions) => {return '';};+ // escape - Multi-purpose: Clear selection / Close spotlight+ // Deliberately outside the group and kept past this view's unmount: the+ // soup selection and split spotlight it acts on live at the split-panel+ // level, so escape keeps working after a list entity is opened in place.+ // The token is required for a persistent registration: same-token override+ // replacement is what dedupes it when this view remounts on the same split.+ registerHotkey({+ hotkey: ['escape'],+ scopeId,+ hotkeyToken: TOKENS.soup.dismiss,+ description: escapeDescription,+ condition: () => clearMultiCondition() || closeSpotlightCondition(),+ keyDownHandler: () => {+ if (clearMultiCondition()) {+ const length = selection.count();+ selection.clear();+ return length > 1;+ }+ if (closeSpotlightCondition()) {+ splitHandle.toggleSpotlight();+ return true;+ }+ return false;+ },+ disposeWithOwner: false,+ });+}++export const useSoupViewHotkeys = (options: UseSoupViewHotkeysOptions) => {+ const {+ scopeId,+ soup,+ splitHandle,+ virtualizerHandle,+ currentView,+ activeTab,+ applyTabPreset,+ fetchNextGroupPage,+ } = options;++ const analytics = useAnalytics();+ const notificationSource = useGlobalNotificationSource();+ registerSplitEscapeHotkey(scopeId, soup.selection, splitHandle);+const group = createHotkeyGroup();// home, cmd+arrowup - Jump to top of list@@ -299,33 +335,6 @@ export const useSoupViewHotkeys = (options: UseSoupViewHotkeysOptions) => {runWithInputFocused: true,}).withGroup(group);- // escape - Multi-purpose: Clear selection / Close spotlight- // Deliberately outside the group and kept past this view's unmount: the- // soup selection and split spotlight it acts on live at the split-panel- // level, so escape keeps working after a list entity is opened in place.- // The token is required for a persistent registration: same-token override- // replacement is what dedupes it when this view remounts on the same split.- registerHotkey({- hotkey: ['escape'],- scopeId,- hotkeyToken: TOKENS.soup.dismiss,- description: escapeDescription,- condition: () => clearMultiCondition() || closeSpotlightCondition(),- keyDownHandler: () => {- if (clearMultiCondition()) {- const length = soup.selection.count();- soup.selection.clear();- return length > 1;- }- if (closeSpotlightCondition()) {- splitHandle.toggleSpotlight();- return true;- }- return false;- },- disposeWithOwner: false,- });-// shift+enter - Open in new splitregisterHotkey({hotkey: ['shift+enter'],diff --git a/apps/web/src/features/scheduling/queries/source.test.ts b/apps/web/src/features/scheduling/queries/source.test.tsnew file mode 100644index 0000000000..abc9166261--- /dev/null+++ b/apps/web/src/features/scheduling/queries/source.test.ts@@ -0,0 +1,137 @@+import { schedulingClient } from '@service-email/scheduling';+import { ok } from 'neverthrow';+import { createRoot, createSignal } from 'solid-js';+import { expect, it, vi } from 'vitest';+import type { SchedulingScope } from '../core/types';+import {+ createSchedulingSource,+ useSchedulingProfileWithAutoSetupQuery,+} from './source';++type Options = {+ queryKey: readonly unknown[];+ queryFn: () => Promise<unknown>;+};+const captured = vi.hoisted(() => ({+ read: undefined as (() => Options) | undefined,+}));++vi.mock('@queries/client', () => ({ queryClient: {} }));+vi.mock('@tanstack/solid-query', async (importOriginal) => ({+ ...(await importOriginal<typeof import('@tanstack/solid-query')>()),+ useQuery: (read: () => Options) => {+ captured.read = read;+ return {};+ },+ useMutation: () => ({}),+}));+vi.mock('@service-email/scheduling', () => ({+ schedulingClient: {+ bookings: vi.fn(async () => ok({ bookings: [] })),+ settings: vi.fn(async () =>+ ok({+ profile: {+ id: 'profile',+ name: '',+ description: '',+ revision: 1,+ schedules: [],+ eventTypes: [],+ },+ })+ ),+ },+}));++it('keeps cached scheduling requests independent of retired scope accessors', async () => {+ const [scope, setScope] = createSignal<SchedulingScope>({+ id: 'first',+ name: 'First',+ teamId: 'team-first',+ canEdit: true,+ canManageBookings: true,+ });+ let retired = false;+ const dispose = createRoot((dispose) => {+ useSchedulingProfileWithAutoSetupQuery(+ () => {+ if (retired) throw new Error('retired component read');+ return scope();+ },+ () => {+ if (retired) throw new Error('retired user read');+ return 'owner';+ }+ );+ return dispose;+ });+ const first = captured.read!();+ setScope({+ id: 'second',+ name: 'Second',+ teamId: 'team-second',+ canEdit: true,+ canManageBookings: true,+ });+ const second = captured.read!();+ dispose();+ retired = true;++ await first.queryFn();+ await second.queryFn();+ expect(first.queryKey).not.toEqual(second.queryKey);+ expect(schedulingClient.settings).toHaveBeenNthCalledWith(1, 'team-first');+ expect(schedulingClient.settings).toHaveBeenNthCalledWith(2, 'team-second');+});++it('keeps cached bookings tied to their original owner and date range', async () => {+ const [scope, setScope] = createSignal<SchedulingScope>({+ id: 'first',+ name: 'First',+ teamId: 'team-first',+ canEdit: true,+ canManageBookings: true,+ });+ const [range, setRange] = createSignal({+ from: '2026-10-01',+ to: '2026-10-08',+ });+ let retired = false;+ const dispose = createRoot((dispose) => {+ createSchedulingSource(+ () => {+ if (retired) throw new Error('retired scope read');+ return scope();+ },+ () => {+ if (retired) throw new Error('retired range read');+ return range();+ }+ );+ return dispose;+ });+ const first = captured.read!();+ setScope({+ id: 'second',+ name: 'Second',+ teamId: 'team-second',+ canEdit: true,+ canManageBookings: true,+ });+ setRange({ from: '2026-10-08', to: '2026-10-15' });+ const second = captured.read!();+ dispose();+ retired = true;++ await first.queryFn();+ await second.queryFn();+ expect(first.queryKey).not.toEqual(second.queryKey);+ expect(schedulingClient.bookings).toHaveBeenNthCalledWith(1, 'team-first', {+ from: '2026-10-01',+ to: '2026-10-08',+ });+ expect(schedulingClient.bookings).toHaveBeenNthCalledWith(2, 'team-second', {+ from: '2026-10-08',+ to: '2026-10-15',+ });+});diff --git a/apps/web/src/features/scheduling/queries/source.ts b/apps/web/src/features/scheduling/queries/source.tsindex f1644e418f..35b3e50033 100644--- a/apps/web/src/features/scheduling/queries/source.ts+++ b/apps/web/src/features/scheduling/queries/source.ts@@ -3,7 +3,7 @@ import { fireAndForget } from '@core/util/fireAndForget';import { throwOnErr } from '@core/util/result';import { queryClient } from '@queries/client';import { schedulingClient } from '@service-email/scheduling';-import { useMutation, useQuery } from '@tanstack/solid-query';+import { queryOptions, useMutation, useQuery } from '@tanstack/solid-query';import type { Accessor } from 'solid-js';import type { SchedulingSource } from '../context/scheduling-context';import {@@ -14,14 +14,83 @@ import {} from '../core/types';import { schedulingKeys } from './keys';-export function useSchedulingProfileQuery(scope: Accessor<SchedulingScope>) {- return useQuery(() => ({- queryKey: schedulingKeys.settings(scope().id).queryKey,+function schedulingProfileQueryOptions(+ scopeId: string,+ teamId: string | undefined,+ userId?: string+) {+ return queryOptions({+ queryKey: schedulingKeys.settings(scopeId).queryKey,+ queryFn: async () => {+ const { profile } = await throwOnErr(() =>+ schedulingClient.settings(teamId)+ );+ if (!teamId && userId) {+ const updated = await createDefaultBookingLinkIfNeeded(profile, userId);+ if (updated) return updated;+ }+ return profile;+ },+ retry: false,+ });+}++function schedulingBookingsQueryOptions(+ scopeId: string,+ teamId: string | undefined,+ from: string,+ to: string+) {+ return queryOptions({+ queryKey: schedulingKeys.bookings(scopeId, from, to).queryKey,queryFn: async () =>- (await throwOnErr(() => schedulingClient.settings(scope().teamId)))- .profile,+ (await throwOnErr(() => schedulingClient.bookings(teamId, { from, to })))+ .bookings,retry: false,- }));+ });+}++function schedulingInsightsQueryOptions(+ scopeId: string,+ teamId: string | undefined,+ from: string,+ to: string+) {+ return queryOptions({+ queryKey: schedulingKeys.insights(scopeId, from, to).queryKey,+ queryFn: async () =>+ (await throwOnErr(() => schedulingClient.bookings(teamId, { from, to })))+ .bookings,+ retry: false,+ staleTime: 0,+ });+}++const saveSchedulingProfileOptions = {+ mutationFn: async ({+ next,+ owner,+ }: {+ next: SchedulingProfile;+ owner: SchedulingScope;+ }) =>+ (await throwOnErr(() => schedulingClient.save(next, owner.teamId))).profile,+ onSuccess: (+ data: SchedulingProfile,+ { owner }: { owner: SchedulingScope }+ ) => {+ queryClient.setQueryData(schedulingKeys.settings(owner.id).queryKey, data);+ },+};++const manageBookingOptions = {+ mutationFn: (id: string) => throwOnErr(() => schedulingClient.manage(id)),+};++export function useSchedulingProfileQuery(scope: Accessor<SchedulingScope>) {+ return useQuery(() =>+ schedulingProfileQueryOptions(scope().id, scope().teamId)+ );}export function createSchedulingSource(@@ -31,34 +100,15 @@ export function createSchedulingSource(): SchedulingSource {const profile = useSchedulingProfileQuery(scope);const bookings = useQuery(() => ({- queryKey: schedulingKeys.bookings(scope().id, range().from, range().to)- .queryKey,- queryFn: async () =>- (- await throwOnErr(() =>- schedulingClient.bookings(scope().teamId, range())- )- ).bookings,+ ...schedulingBookingsQueryOptions(+ scope().id,+ scope().teamId,+ range().from,+ range().to+ ),enabled: loadBookings(),- retry: false,- }));- const save = useMutation(() => ({- mutationFn: async ({- next,- owner,- }: {- next: SchedulingProfile;- owner: SchedulingScope;- }) =>- (await throwOnErr(() => schedulingClient.save(next, owner.teamId)))- .profile,- onSuccess: (data, { owner }) => {- queryClient.setQueryData(- schedulingKeys.settings(owner.id).queryKey,- data- );- },}));+ const save = useMutation(() => saveSchedulingProfileOptions);const reload = () => {fireAndForget(profile.refetch(), 'scheduling');if (loadBookings()) fireAndForget(bookings.refetch(), 'scheduling');@@ -87,17 +137,9 @@ export function createSchedulingSource(},loadInsights: (from, to) => {const owner = scope();- return queryClient.fetchQuery({- queryKey: schedulingKeys.insights(owner.id, from, to).queryKey,- queryFn: async () =>- (- await throwOnErr(() =>- schedulingClient.bookings(owner.teamId, { from, to })- )- ).bookings,- staleTime: 0,- retry: false,- });+ return queryClient.fetchQuery(+ schedulingInsightsQueryOptions(owner.id, owner.teamId, from, to)+ );},setAttendance: async (id, attendance) => {await throwOnErr(() => schedulingClient.setAttendance(id, attendance));@@ -111,9 +153,7 @@ export function createSchedulingSource(}export function useManageBookingMutation() {- return useMutation(() => ({- mutationFn: (id: string) => throwOnErr(() => schedulingClient.manage(id)),- }));+ return useMutation(() => manageBookingOptions);}async function createDefaultBookingLinkIfNeeded(@@ -150,26 +190,7 @@ export function useSchedulingProfileWithAutoSetupQuery(scope: Accessor<SchedulingScope>,userId: Accessor<string>) {- return useQuery(() => ({- queryKey: schedulingKeys.settings(scope().id).queryKey,- queryFn: async () => {- const result = await throwOnErr(() =>- schedulingClient.settings(scope().teamId)- );- const profile = result.profile;-- if (!scope().teamId && userId()) {- const updated = await createDefaultBookingLinkIfNeeded(- profile,- userId()- );- if (updated) {- return updated;- }- }-- return profile;- },- retry: false,- }));+ return useQuery(() =>+ schedulingProfileQueryOptions(scope().id, scope().teamId, userId())+ );}diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/builder/MarkdownShell.test.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/builder/MarkdownShell.test.tsxnew file mode 100644index 0000000000..e39b7021c4--- /dev/null+++ b/apps/web/src/lib/core/component/LexicalMarkdown/builder/MarkdownShell.test.tsx@@ -0,0 +1,39 @@+import { render } from '@solidjs/testing-library';+import { createSignal } from 'solid-js';+import { expect, it, vi } from 'vitest';+import { buildConfig } from './MarkdownConfigBuilder';+import { MarkdownShell } from './MarkdownShell';++const connection = vi.hoisted(() => ({+ callback: undefined as (() => void) | undefined,+}));++vi.mock('@solid-primitives/lifecycle', async (importOriginal) => ({+ ...(await importOriginal<typeof import('@solid-primitives/lifecycle')>()),+ onElementConnect: (_element: Element, callback: () => void) => {+ connection.callback = callback;+ },+}));++it('disposes reactive autofocus reads made during deferred editor connection', () => {+ const [touch, setTouch] = createSignal(false);+ const [autofocus] = createSignal(false);+ let reads = 0;+ const isTouch = () => {+ reads += 1;+ return touch();+ };+ const { unmount } = render(() => (+ <MarkdownShell+ config={buildConfig('plain-text')}+ autofocus={!isTouch() && autofocus()}+ />+ ));+ expect(connection.callback).toBeTypeOf('function');+ connection.callback!();+ expect(reads).toBeGreaterThan(0);+ unmount();+ const readsAtUnmount = reads;+ setTouch(true);+ expect(reads).toBe(readsAtUnmount);+});diff --git a/apps/web/src/lib/queries/agent-session/preview.test.ts b/apps/web/src/lib/queries/agent-session/preview.test.tsnew file mode 100644index 0000000000..870b58bf25--- /dev/null+++ b/apps/web/src/lib/queries/agent-session/preview.test.ts@@ -0,0 +1,54 @@+import { ok } from 'neverthrow';+import { createRoot, createSignal } from 'solid-js';+import { expect, it, vi } from 'vitest';+import { previewServiceClient } from '../../service-clients/service-preview/client';+import { useAgentPreview } from './preview';++type Options = {+ queryKey: readonly unknown[];+ queryFn: () => Promise<unknown>;+ enabled: boolean;+};+const captured = vi.hoisted(() => ({+ read: undefined as (() => Options) | undefined,+}));++vi.mock('@tanstack/solid-query', async (importOriginal) => ({+ ...(await importOriginal<typeof import('@tanstack/solid-query')>()),+ useQuery: (read: () => Options) => {+ captured.read = read;+ return {};+ },+ useQueryClient: () => ({ invalidateQueries: vi.fn() }),+}));+vi.mock('../../service-clients/service-preview/client', () => ({+ previewServiceClient: { get: vi.fn(async () => ok({ preview: null })) },+}));+vi.mock('./queue-sync', () => ({+ subscribeSocketSessionStarted: () => () => {},+}));++it('keeps cached preview requests tied to their key without reading a retired component', async () => {+ const [sessionId, setSessionId] = createSignal<string | undefined>('first');+ let retired = false;+ const dispose = createRoot((dispose) => {+ useAgentPreview(() => {+ if (retired) throw new Error('retired component read');+ return sessionId();+ });+ return dispose;+ });+ const first = captured.read!();+ setSessionId('second');+ const second = captured.read!();+ setSessionId(undefined);+ expect(captured.read!().enabled).toBe(false);+ dispose();+ retired = true;++ await first.queryFn();+ await second.queryFn();+ expect(first.queryKey).not.toEqual(second.queryKey);+ expect(previewServiceClient.get).toHaveBeenNthCalledWith(1, 'first');+ expect(previewServiceClient.get).toHaveBeenNthCalledWith(2, 'second');+});diff --git a/apps/web/src/lib/queries/agent-session/preview.ts b/apps/web/src/lib/queries/agent-session/preview.tsindex 2f3abbd2ed..bff8eea261 100644--- a/apps/web/src/lib/queries/agent-session/preview.ts+++ b/apps/web/src/lib/queries/agent-session/preview.ts@@ -1,6 +1,6 @@import { fireAndForget } from '@core/util/fireAndForget';import { throwOnErr } from '@core/util/result';-import { useQuery, useQueryClient } from '@tanstack/solid-query';+import { queryOptions, useQuery, useQueryClient } from '@tanstack/solid-query';import { type Accessor, onCleanup } from 'solid-js';import { previewServiceClient } from '../../service-clients/service-preview/client';import { subscribeSocketSessionStarted } from './queue-sync';@@ -13,6 +13,18 @@ export function handleAgentSessionPreview(event: { agentSessionId: string }) {const key = (sessionId: string | undefined) =>['agentSession', 'preview', sessionId ?? ''] as const;+function agentPreviewQueryOptions(sessionId: string | undefined) {+ return queryOptions({+ queryKey: key(sessionId),+ queryFn: () => throwOnErr(() => previewServiceClient.get(sessionId!)),+ enabled: Boolean(sessionId),+ staleTime: 0,+ // Repairs missed events and renews the viewer's event subscription.+ refetchInterval: 30_000,+ retry: false,+ });+}+export function useAgentPreview(sessionId: Accessor<string | undefined>) {const client = useQueryClient();const invalidate = () =>@@ -27,15 +39,7 @@ export function useAgentPreview(sessionId: Accessor<string | undefined>) {fireAndForget(invalidate(), 'agent-preview')));- const query = useQuery(() => ({- queryKey: key(sessionId()),- queryFn: () => throwOnErr(() => previewServiceClient.get(sessionId()!)),- enabled: Boolean(sessionId()),- staleTime: 0,- // Repairs missed events and gateway restarts; also renews the viewer's event subscription.- refetchInterval: 30_000,- retry: false,- }));+ const query = useQuery(() => agentPreviewQueryOptions(sessionId()));return {query,open: () => throwOnErr(() => previewServiceClient.open(sessionId()!)),diff --git a/docs/agent-guide/channels.md b/docs/agent-guide/channels.mdindex 3c22c8b6a0..93b8d38c5c 100644--- a/docs/agent-guide/channels.md+++ b/docs/agent-guide/channels.md@@ -1310,6 +1310,11 @@ the caret after send does not pan the page while the keyboard resizes. Repeat wiand check that sent text does not return. Scroll into history before an incomingmessage or acknowledgement and verify that it does not pull you to latest.+For composer cleanup, repeatedly open and leave channels and threads, then+switch between touch and keyboard/mouse input. Retired composers must not keep+reacting to input-modality changes. Memory-pressure crashes still require an+iPhone run with the app's native memory diagnostics.+## Channel picturesdiff --git a/docs/agent-guide/navigation.md b/docs/agent-guide/navigation.mdindex 5d3238f469..5e7a8507bb 100644--- a/docs/agent-guide/navigation.md+++ b/docs/agent-guide/navigation.md@@ -973,6 +973,11 @@ restart rules still apply.Single-letter shortcuts only work when no editor has focus; press `Escape` first.- `/` — search everything (in Email it focuses email search). `j`/`k` — move inlists. `e` — mark done.+ After opening a list item in the same split, `j`/`k` continue through the+ originating list; native detail paging can still load its next page. Check+ repeated list/detail transitions as well as group-header skipping. Returning+ to the list restores scrolling to the focused row; the unmounted list's+ virtualizer must not run while viewing details.- `#` — move email to Trash, with an Undo toast. Works on the selected or focusedrows in a mail list and on the thread open in an email detail or block. Emailonly; other entity types keep Delete/Backspace and do not answer `#`.