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): stop long-lived holders from keeping left views alive (#9903)
teocf36c57c6b80
diff --git a/apps/web/src/components/app/split-layout/components/SplitLabel.tsx b/apps/web/src/components/app/split-layout/components/SplitLabel.tsxindex c50484afb6..9958c3918b 100644--- a/apps/web/src/components/app/split-layout/components/SplitLabel.tsx+++ b/apps/web/src/components/app/split-layout/components/SplitLabel.tsx@@ -32,6 +32,7 @@ import {createSignal,For,type JSX,+ onCleanup,type ParentProps,Show,} from 'solid-js';@@ -39,6 +40,7 @@ import { Portal } from 'solid-js/web';import {getSplitFileMenuActionSections,type SplitFileMenuAction,+ type SplitPanelContextType,} from '../context';import { useSplitDisplayName, useSplitPanelOrThrow } from '../layoutUtils';import { HeaderIsland } from './HeaderIsland';@@ -143,9 +145,7 @@ export function StaticSplitLabel(props: {</span><divclass="shrink-0 flex items-center h-full"- ref={(ref) => {- panel.setTitleFileMenuRef(ref);- }}+ ref={titleFileMenuMount(panel)}/></div></HeaderIsland>@@ -316,9 +316,7 @@ export function BlockItemSplitLabel(props: {{props.trailingBadges}<divclass="shrink-0 flex items-center h-full"- ref={(ref) => {- panel.setTitleFileMenuRef(ref);- }}+ ref={titleFileMenuMount(panel)}/></div></HeaderIsland>@@ -405,6 +403,24 @@ function SplitLabelContextMenu(props: ParentProps) {);}+/**+ * A ref that makes its element the split title's file menu mount until the+ * element's owner is disposed. The split outlives the views in it, so a mount+ * left behind would keep a view that has gone alive.+ */+export function titleFileMenuMount(+ panel: Pick<SplitPanelContextType, 'setTitleFileMenuRef'>+) {+ return (element: HTMLDivElement) => {+ panel.setTitleFileMenuRef(element);+ onCleanup(() =>+ panel.setTitleFileMenuRef((current) =>+ current === element ? undefined : current+ )+ );+ };+}+export function SplitTitleFileMenu(props: ParentProps) {const panel = useSplitPanelOrThrow();diff --git a/apps/web/src/components/app/split-layout/components/SplitPanel.tsx b/apps/web/src/components/app/split-layout/components/SplitPanel.tsxindex aa7aade102..3e4a79ebbf 100644--- a/apps/web/src/components/app/split-layout/components/SplitPanel.tsx+++ b/apps/web/src/components/app/split-layout/components/SplitPanel.tsx@@ -63,7 +63,9 @@ export function SplitPanel(props: SplitPanelProps) {const [bottomPanel, setBottomPanel] =createSignal<SplitBottomPanelRegistration>();const panelSize = createElementSize(panelRef);- let pointerTarget: Element | undefined;+ // Weak, so the last element pressed doesn't keep a view this split has+ // left alive.+ let pointerTarget: WeakRef<Element> | undefined;const layoutRefs = createMutable<SplitPanelContextType['layoutRefs']>({});const headerCollapseController = createPriorityCollapseController();@@ -240,7 +242,10 @@ export function SplitPanel(props: SplitPanelProps) {replaceOwnedSlot: ownedSlots.replace,panelSize,panelRef,- pointerTarget: () => pointerTarget,+ pointerTarget: () => {+ const target = pointerTarget?.deref();+ return target?.isConnected ? target : undefined;+ },}}><SplitDrawerGroup panelSize={panelSize}>@@ -276,7 +281,9 @@ export function SplitPanel(props: SplitPanelProps) {capture: true,handleEvent: (e) => {pointerTarget =- e.target instanceof Element ? e.target : undefined;+ e.target instanceof Element+ ? new WeakRef(e.target)+ : undefined;},}}// A split opened from the keyboard has no pressed element to keepdiff --git a/apps/web/src/components/app/split-layout/splitFocusTracker.ts b/apps/web/src/components/app/split-layout/splitFocusTracker.tsindex d2b5fd56ed..582473c5e7 100644--- a/apps/web/src/components/app/split-layout/splitFocusTracker.ts+++ b/apps/web/src/components/app/split-layout/splitFocusTracker.ts@@ -39,7 +39,12 @@ export function createSplitFocusTracker(props: {const activeSplitId = () => props.splitManager.activeSplitId();const currentSplitsIds = () => new Set(props.splits().map((s) => s.id));- const lastFocusedChildBySplitId: Map<SplitId, HTMLElement | null> = new Map();+ // Weak, so the element last focused in a split doesn't keep a view the+ // split has left alive.+ const lastFocusedChildBySplitId: Map<+ SplitId,+ WeakRef<HTMLElement>+ > = new Map();createEffect(on(currentSplitsIds, (ids) => {for (const key of lastFocusedChildBySplitId.keys()) {@@ -74,7 +79,7 @@ export function createSplitFocusTracker(props: {return;// look for a child to return focus to.- const child = lastFocusedChildBySplitId.get(id);+ const child = lastFocusedChildBySplitId.get(id)?.deref();if (child && child.isConnected && splitPanelRef.contains(child)) {child.focus();return;@@ -222,7 +227,7 @@ export function createSplitFocusTracker(props: {element instanceof HTMLElement &&!element.closest('[data-no-focus-restore]')) {- lastFocusedChildBySplitId.set(parentId, element);+ lastFocusedChildBySplitId.set(parentId, new WeakRef(element));}activateTimeout = setTimeout(() => {diff --git a/apps/web/src/features/block-channel/component/Top.tsx b/apps/web/src/features/block-channel/component/Top.tsxindex 8aeedb4b21..b433e2490a 100644--- a/apps/web/src/features/block-channel/component/Top.tsx+++ b/apps/web/src/features/block-channel/component/Top.tsx@@ -4,7 +4,10 @@ import { ChannelTopIcon } from '@channel/components/ChannelTopIcon';import { CollapsibleHeaderItem } from '@components/app/split-layout/components/CollapsibleItem';import { HeaderIsland } from '@components/app/split-layout/components/HeaderIsland';import { SplitHeaderLeft } from '@components/app/split-layout/components/SplitHeader';-import { SplitLabel } from '@components/app/split-layout/components/SplitLabel';+import {+ SplitLabel,+ titleFileMenuMount,+} from '@components/app/split-layout/components/SplitLabel';import { useSplitPanelOrThrow } from '@components/app/split-layout/layoutUtils';import { useBlockId } from '@core/block';import { useChannelName } from '@core/context/channels';@@ -55,7 +58,7 @@ export function ChannelTopLeft(props: ChannelTopLeftProps) {/><divclass="shrink-0 flex items-center h-full"- ref={(ref) => panel.setTitleFileMenuRef(ref)}+ ref={titleFileMenuMount(panel)}/></div></HeaderIsland>diff --git a/apps/web/src/features/notifications-inbox/context/notifications-inbox-context.ts b/apps/web/src/features/notifications-inbox/context/notifications-inbox-context.tsindex 0cece951b3..d30f298edb 100644--- a/apps/web/src/features/notifications-inbox/context/notifications-inbox-context.ts+++ b/apps/web/src/features/notifications-inbox/context/notifications-inbox-context.ts@@ -1,20 +1,18 @@-import type { EntityWithRawNotifications } from '@app/features/soup/entity-notifications';import type { EntityData } from '@entity';import type { UnifiedNotification } from '@notifications/types';import { type Accessor, createContext, useContext } from 'solid-js';import type { InboxClear } from '../core/inbox-filters';import type { InboxRow, InboxRowType } from '../core/inbox-row';-/** What one inbox row presents. */+/**+ * What one inbox row presents, as plain data the feed's store reconciles by+ * row id. `rowEntity` gives the entity a row opens, with its notifications.+ */export type InboxRowContent = {- /** The row's entity, carrying only the row's notifications. */- entity: EntityWithRawNotifications<EntityData>;+ /** The entity the row is filed under. */+ entity: EntityData;/** The row's notifications, newest first; the first names the row. */notifications: UnifiedNotification[];- /** The row's entity, opening at one of its notifications. */- entityAt: (- notification: UnifiedNotification- ) => EntityWithRawNotifications<EntityData>;};export type NotificationInboxRow = InboxRow<InboxRowContent>;diff --git a/apps/web/src/features/notifications-inbox/open-notification-in-split.ts b/apps/web/src/features/notifications-inbox/open-notification-in-split.tsindex 0452faf971..4fdcb14ceb 100644--- a/apps/web/src/features/notifications-inbox/open-notification-in-split.ts+++ b/apps/web/src/features/notifications-inbox/open-notification-in-split.ts@@ -6,6 +6,7 @@ import { openNotification } from '@notifications';import type { UnifiedNotification } from '@notifications/types';import type { NotificationInboxRow } from './context/notifications-inbox-context';import { agentTurnParams } from './primitives/notification-location';+import { rowEntity } from './primitives/row-entity';type OpenOptions = { newSplit: boolean; splitHandle: SplitHandle };@@ -34,7 +35,7 @@ async function openStackNotification(options.splitHandle));if (!opened || opened.isErr()) {- await openEntityInSplitFromUnifiedList(row.content.entityAt(notification), {+ await openEntityInSplitFromUnifiedList(rowEntity(row, notification), {openInNewSplit: options.newSplit,splitHandle: options.splitHandle,});@@ -60,7 +61,7 @@ export function openNotificationInSplit(fireAndForget(options.notification? openStackNotification(row, options.notification, options)- : openEntityInSplitFromUnifiedList(row.content.entity, {+ : openEntityInSplitFromUnifiedList(rowEntity(row), {openInNewSplit: options.newSplit,splitHandle: options.splitHandle,}),diff --git a/apps/web/src/features/notifications-inbox/primitives/describe-row.test.ts b/apps/web/src/features/notifications-inbox/primitives/describe-row.test.tsindex 5960046998..0ada5091c4 100644--- a/apps/web/src/features/notifications-inbox/primitives/describe-row.test.ts+++ b/apps/web/src/features/notifications-inbox/primitives/describe-row.test.ts@@ -46,7 +46,6 @@ const row = (content: {entity: { type: 'task', id: 'task-a', name: 'Task' } as never,notifications: [notification],- entityAt: () => ({}) as never,},});@@ -122,7 +121,6 @@ const stack = (content: {entity: { type: 'channel', id: 'entity', name: 'The entity' } as never,notifications,- entityAt: () => ({}) as never,},});diff --git a/apps/web/src/features/notifications-inbox/primitives/inbox-date-headers.test.ts b/apps/web/src/features/notifications-inbox/primitives/inbox-date-headers.test.tsindex 5dd03c3dbf..7dc8ef74ec 100644--- a/apps/web/src/features/notifications-inbox/primitives/inbox-date-headers.test.ts+++ b/apps/web/src/features/notifications-inbox/primitives/inbox-date-headers.test.ts@@ -21,7 +21,6 @@ const row = (id: string, latestAt: Date): NotificationInboxRow => ({content: {entity: { type: 'document', id, name: 'Plan' } as never,notifications: [],- entityAt: () => ({}) as never,},});diff --git a/apps/web/src/features/notifications-inbox/primitives/inbox-list.test.ts b/apps/web/src/features/notifications-inbox/primitives/inbox-list.test.tsindex 2ddcdf408d..11bc2752a5 100644--- a/apps/web/src/features/notifications-inbox/primitives/inbox-list.test.ts+++ b/apps/web/src/features/notifications-inbox/primitives/inbox-list.test.ts@@ -6,8 +6,6 @@ import type {} from '../context/notifications-inbox-context';import { createInboxList, type InboxDoneNotices } from './inbox-list';-const entityAt = () => ({}) as never;-const row = (id: string): NotificationInboxRow => ({id,type: 'task',@@ -19,7 +17,6 @@ const row = (id: string): NotificationInboxRow => ({content: {entity: { type: 'document', id, name: 'Plan' } as never,notifications: [],- entityAt,},});diff --git a/apps/web/src/features/notifications-inbox/primitives/inbox-selection.test.ts b/apps/web/src/features/notifications-inbox/primitives/inbox-selection.test.tsindex 9e26d5799d..ee0e88005d 100644--- a/apps/web/src/features/notifications-inbox/primitives/inbox-selection.test.ts+++ b/apps/web/src/features/notifications-inbox/primitives/inbox-selection.test.ts@@ -18,7 +18,6 @@ const row = (id: string, revision = 'r1'): NotificationInboxRow => ({content: {entity: { type: 'document', id, name: id } as never,notifications: [],- entityAt: () => ({}) as never,},});diff --git a/apps/web/src/features/notifications-inbox/primitives/inbox-telemetry.test.ts b/apps/web/src/features/notifications-inbox/primitives/inbox-telemetry.test.tsindex 83278574bd..baf820aa8c 100644--- a/apps/web/src/features/notifications-inbox/primitives/inbox-telemetry.test.ts+++ b/apps/web/src/features/notifications-inbox/primitives/inbox-telemetry.test.ts@@ -39,7 +39,6 @@ const row = (id: string): NotificationInboxRow => ({content: {entity: {} as never,notifications: [],- entityAt: () => ({}) as never,},});diff --git a/apps/web/src/features/notifications-inbox/primitives/row-actions.test.ts b/apps/web/src/features/notifications-inbox/primitives/row-actions.test.tsindex 7b6d9070a3..056c28bf08 100644--- a/apps/web/src/features/notifications-inbox/primitives/row-actions.test.ts+++ b/apps/web/src/features/notifications-inbox/primitives/row-actions.test.ts@@ -64,7 +64,6 @@ const row = (content: {entity: { type: 'document', id: 'doc-a', name: 'Plan' } as never,notifications,- entityAt: () => ({}) as never,},});diff --git a/apps/web/src/features/notifications-inbox/primitives/row-entity.ts b/apps/web/src/features/notifications-inbox/primitives/row-entity.tsnew file mode 100644index 0000000000..7e49d60fef--- /dev/null+++ b/apps/web/src/features/notifications-inbox/primitives/row-entity.ts@@ -0,0 +1,30 @@+import type { EntityWithRawNotifications } from '@app/features/soup/entity-notifications';+import type { EntityData } from '@entity';+import { getChannelNotificationParams } from '@notifications/notification-navigation';+import type { UnifiedNotification } from '@notifications/types';+import type { NotificationInboxRow } from '../context/notifications-inbox-context';++/**+ * The entity a row opens, or one of its notifications opens: it carries only+ * those notifications, so entity-based helpers (icons, preview targets) see+ * what the row shows, and a channel names the message the newest one is+ * about, since a thread row's channel would otherwise open at its latest.+ */+export function rowEntity(+ row: NotificationInboxRow,+ notification?: UnifiedNotification+): EntityWithRawNotifications<EntityData> {+ const entity = row.content.entity;+ const notifications = notification+ ? [notification]+ : row.content.notifications;+ const read = () => notifications;+ const [newest] = notifications;+ if (!newest || entity.type !== 'channel') {+ return { ...entity, notifications: read };+ }+ const { messageId, threadId } = getChannelNotificationParams(newest);+ return messageId+ ? { ...entity, notifications: read, target: { messageId, threadId } }+ : { ...entity, notifications: read };+}diff --git a/apps/web/src/features/notifications-inbox/queries/decode.test.ts b/apps/web/src/features/notifications-inbox/queries/decode.test.tsindex 6f00a811b6..f06df9a0f1 100644--- a/apps/web/src/features/notifications-inbox/queries/decode.test.ts+++ b/apps/web/src/features/notifications-inbox/queries/decode.test.ts@@ -7,6 +7,7 @@ import type {} from '@service-storage/graphql/generated/graphql';import { describe, expect, it, vi } from 'vitest';import { ALL_INBOX_ROW_TYPES } from '../core/inbox-filters';+import { rowEntity } from '../primitives/row-entity';import { commentNotification, inboxEntry } from '../tests/wire';import { encodeInboxScope, toInboxGroup } from './decode';@@ -86,13 +87,13 @@ describe('toInboxGroup', () => {}))?.rows ?? [];- expect(row && isWithNotification(row.content.entity)).toBe(true);+ expect(row && isWithNotification(rowEntity(row))).toBe(true);});it('points a channel row at the message its newest notification names', () => {const [row] = toInboxGroup(threadRowEntry())?.rows ?? [];- expect(row?.content.entity).toMatchObject({+ expect(row && rowEntity(row)).toMatchObject({type: 'channel',target: { messageId: 'reply', threadId: 'root' },});@@ -117,11 +118,11 @@ describe('toInboxGroup', () => {} as unknown as NotificationInboxEntryFieldsFragment);const decoded = group?.rows[0];if (!decoded) throw new Error('row missing');- expect(decoded.content.entity).toMatchObject({+ expect(rowEntity(decoded)).toMatchObject({target: { messageId: 'reply', threadId: 'root' },});- const aimed = decoded.content.entityAt(decoded.content.notifications[1]);+ const aimed = rowEntity(decoded, decoded.content.notifications[1]);expect(aimed).toMatchObject({target: { messageId: 'older-reply', threadId: 'root' },@@ -163,7 +164,7 @@ describe('toInboxGroup', () => {count: row.count,notifications: row.content.notifications.map((n) => n.id),entityNotifications: (- row.content.entity.notifications as () => { id: string }[]+ rowEntity(row).notifications as () => { id: string }[])().map((n) => n.id),}))).toEqual([diff --git a/apps/web/src/features/notifications-inbox/queries/decode.ts b/apps/web/src/features/notifications-inbox/queries/decode.tsindex c2f217b30e..67ddffa40f 100644--- a/apps/web/src/features/notifications-inbox/queries/decode.ts+++ b/apps/web/src/features/notifications-inbox/queries/decode.ts@@ -1,6 +1,3 @@-import type { EntityData } from '@entity';-import { getChannelNotificationParams } from '@notifications/notification-navigation';-import type { UnifiedNotification } from '@notifications/types';import { attentionFeedSoupItem } from '@queries/attention-feed/attention-feed-entity';import { mapApiSoupItemToEntity } from '@queries/soup/transform-utils';import type {@@ -11,7 +8,6 @@ import type {import { mapGraphqlNotification } from '@service-storage/graphql-soup';import { match } from 'ts-pattern';import type {- InboxRowContent,InboxScope,NotificationInboxRow,} from '../context/notifications-inbox-context';@@ -113,60 +109,23 @@ export function encodeInboxScope(}/**- * The entity one row opens: it carries only the row's notifications, and a- * channel row names the message its newest notification is about, since a- * thread row's channel entity would otherwise open at the channel's latest.- */-function rowEntity(- entity: EntityData,- notifications: UnifiedNotification[]-): InboxRowContent['entity'] {- const read = () => notifications;- const [newest] = notifications;- if (!newest || entity.type !== 'channel') {- return { ...entity, notifications: read };- }- const { messageId, threadId } = getChannelNotificationParams(newest);- return messageId- ? { ...entity, notifications: read, target: { messageId, threadId } }- : { ...entity, notifications: read };-}--/** Rows decoded by an earlier read, with the wire data each came from. */-export type InboxRowMemo = {- previous: ReadonlyMap<string, { wire: string; row: NotificationInboxRow }>;- next: Map<string, { wire: string; row: NotificationInboxRow }>;-};--/**- * Project one inbox entry into rows. Each row's entity carries only that- * row's notifications, so entity-based helpers (icons, preview targets) see- * what the row shows. An entity the app does not list, or an entry without a- * valid place, is dropped. With a memo, a row that did not change keeps its- * object.+ * Project one inbox entry into rows, as plain data the source reconciles+ * into its store. An entity the app does not list, or an entry without a+ * valid place, is dropped.*/export function toInboxGroup(- entry: NotificationInboxEntryFieldsFragment,- memo?: InboxRowMemo+ entry: NotificationInboxEntryFieldsFragment): NotificationInboxGroup | null {const sortAt = Date.parse(entry.sortAt);const soupItem = attentionFeedSoupItem(entry.entity);if (!soupItem || Number.isNaN(sortAt)) return null;const entity = mapApiSoupItemToEntity(soupItem);- const entityWire = memo ? JSON.stringify(entry.entity) : '';return {groupId: entry.groupId,sortAt,rows: entry.rows.flatMap((row) => {const latestAt = Date.parse(row.latestAt);if (Number.isNaN(latestAt)) return [];- const wire = memo ? `${entityWire}${JSON.stringify(row)}` : '';- const known = memo?.previous.get(row.id);- if (memo && known?.wire === wire) {- memo.next.set(row.id, known);- return [known.row];- }- const notifications = row.notifications.map(mapGraphqlNotification);const decoded: NotificationInboxRow = {id: row.id,type: toRowType(row.rowType),@@ -178,12 +137,10 @@ export function toInboxGroup(unseen: row.unseen,count: row.count,content: {- entity: rowEntity(entity, notifications),- notifications,- entityAt: (notification) => rowEntity(entity, [notification]),+ entity,+ notifications: row.notifications.map(mapGraphqlNotification),},};- memo?.next.set(row.id, { wire, row: decoded });return [decoded];}),};diff --git a/apps/web/src/features/notifications-inbox/queries/notification-inbox-groups.test.ts b/apps/web/src/features/notifications-inbox/queries/notification-inbox-groups.test.tsindex 7e8555342d..62ae024023 100644--- a/apps/web/src/features/notifications-inbox/queries/notification-inbox-groups.test.ts+++ b/apps/web/src/features/notifications-inbox/queries/notification-inbox-groups.test.ts@@ -16,7 +16,6 @@ const row = (id: string, latestAt: number): NotificationInboxRow => ({content: {entity: {} as never,notifications: [],- entityAt: () => ({}) as never,},});diff --git a/apps/web/src/features/notifications-inbox/queries/notification-inbox-source.ts b/apps/web/src/features/notifications-inbox/queries/notification-inbox-source.tsindex b76952a2c6..f483c2988f 100644--- a/apps/web/src/features/notifications-inbox/queries/notification-inbox-source.ts+++ b/apps/web/src/features/notifications-inbox/queries/notification-inbox-source.ts@@ -5,14 +5,19 @@ import type { UnifiedNotification } from '@notifications/types';import { createLiveAttentionFeed } from '@queries/attention-feed/live-attention-feed';import {NotificationInboxDocument,- type NotificationInboxEntryFieldsFragment,type NotificationInboxQuery,type NotificationInboxQueryVariables,type NotificationInboxScopeInput,NotificationInboxUpdatesDocument,} from '@service-storage/graphql/generated/graphql';import { type Client, stringifyDocument } from '@urql/core';-import { type Accessor, createMemo, createSignal } from 'solid-js';+import {+ type Accessor,+ createComputed,+ createMemo,+ createSignal,+} from 'solid-js';+import { createStore, reconcile } from 'solid-js/store';import type {InboxFeedSource,InboxScope,@@ -28,7 +33,7 @@ import {withoutDoneRows,withSeenRows,} from '../core/inbox-row';-import { encodeInboxScope, type InboxRowMemo, toInboxGroup } from './decode';+import { encodeInboxScope, toInboxGroup } from './decode';import {type NotificationInboxGroup,orderInboxRows,@@ -95,20 +100,6 @@ export function createNotificationInboxSource(const enabled = () =>options.enabled() && options.scope().rowTypes.length > 0;- // Every change rebuilds the pages; rows it didn't touch keep their objects,- // so what reads them, such as an open preview, doesn't rerun.- let decodedRows: InboxRowMemo['previous'] = new Map();- const readGroups = (- entries: readonly NotificationInboxEntryFieldsFragment[]- ) => {- const memo: InboxRowMemo = { previous: decodedRows, next: new Map() };- const groups = entries- .map((entry) => toInboxGroup(entry, memo))- .filter(isGroup);- decodedRows = memo.next;- return groups;- };-const query = createUrqlInfiniteQuery<NotificationInboxQuery,NotificationInboxQueryVariables,@@ -127,9 +118,10 @@ export function createNotificationInboxSource(requestPolicy: 'cache-and-network',keepPreviousData: true,select: ({ pages, pageParams }) => ({- groups: readGroups(- pages.flatMap((page) => page.user.notificationInbox.entries)- ),+ groups: pages+ .flatMap((page) => page.user.notificationInbox.entries)+ .map((entry) => toInboxGroup(entry))+ .filter(isGroup),cursors: [...pageParams],}),};@@ -148,8 +140,18 @@ export function createNotificationInboxSource(? [...current, id]: current.filter((candidate) => candidate !== id));- const ordered = createMemo(() =>- orderInboxRows(query.data?.groups ?? [], !query.hasNextPage)+ // Every change rebuilds the pages. The rows live in a store that each read+ // reconciles into by row id, so a row the change didn't touch keeps its+ // object and a changed one updates in place: what reads them, such as an+ // open preview, reruns only for what changed.+ const [ordered, setOrdered] = createStore<NotificationInboxRow[]>([]);+ createComputed(() =>+ setOrdered(+ reconcile(orderInboxRows(query.data?.groups ?? [], !query.hasNextPage), {+ key: 'id',+ merge: true,+ })+ ));const live = createLiveAttentionFeed({@@ -172,7 +174,7 @@ export function createNotificationInboxSource(// acknowledged was reopened, so it shows again; while it is still// loaded, the same revision is a change computed before the done.onPatches: (patches) => {- const present = new Set(ordered().map((row) => row.id));+ const present = new Set(ordered.map((row) => row.id));const reopened = patches.flatMap((patch) =>patch.__typename === 'NotificationInboxEntryUpserted'? patch.entry.rows.flatMap((row) => {@@ -189,8 +191,8 @@ export function createNotificationInboxSource(}},onRefetched: () => {- setDone((current) => settleRowMarks(current, ordered()));- setSeen((current) => settleRowMarks(current, ordered()));+ setDone((current) => settleRowMarks(current, ordered));+ setSeen((current) => settleRowMarks(current, ordered));},surface: 'notifications-inbox',});@@ -200,7 +202,7 @@ export function createNotificationInboxSource(? undefined: withSeenRows(withoutDoneNotifications(- withoutDoneRows(ordered(), done()),+ withoutDoneRows(ordered, done()),doneNotifications()),seen()diff --git a/apps/web/src/features/notifications-inbox/views/notifications-view.tsx b/apps/web/src/features/notifications-inbox/views/notifications-view.tsxindex 8d29f19053..3b52ce7c64 100644--- a/apps/web/src/features/notifications-inbox/views/notifications-view.tsx+++ b/apps/web/src/features/notifications-inbox/views/notifications-view.tsx@@ -28,6 +28,7 @@ import {} from '@components/app/previewTarget';import { useSplitPanelOrThrow } from '@components/app/split-layout/layoutUtils';import { SplitPanel } from '@components/app/split-panel';+import { StaticMarkdownContext } from '@core/component/LexicalMarkdown/component/core/StaticMarkdown';import { toast } from '@core/component/Toast/Toast';import { registerHotkey } from '@core/hotkey/hotkeys';import { TOKENS } from '@core/hotkey/tokens';@@ -113,6 +114,7 @@ import {crmCommentParams,} from '../primitives/notification-location';import { createRowActions, rowButtons } from '../primitives/row-actions';+import { rowEntity } from '../primitives/row-entity';type ActivationMetadata = { event?: MouseEvent; newSplit?: boolean };/** Stepping through the list and moving on from a done row replace the entry. */@@ -175,18 +177,12 @@ const previewSelection = (? undefined: entity;-/** The entity a row, or one of its notifications, is about. */-const entityOf = (- row: NotificationInboxRow,- notification?: UnifiedNotification-) => (notification ? row.content.entityAt(notification) : row.content.entity);-/*** A calendar event row as the Calendar reads it: its notifications, such as* a reminder naming the occurrence, behind an accessor.*/const calendarSelection = (- entity: ReturnType<typeof entityOf>+ entity: ReturnType<typeof rowEntity>): CalendarPreviewSelection | undefined => {if (entity.type !== 'calendar_event') return undefined;const { notifications } = entity;@@ -208,7 +204,7 @@ const previewTargetFor = (row: NotificationInboxRow,notification?: UnifiedNotification) => {- const entity = previewSelection(entityOf(row, notification));+ const entity = previewSelection(rowEntity(row, notification));if (!entity) return undefined;const target = previewBlockTarget(entity);const params =@@ -386,7 +382,7 @@ export function NotificationsView(props: NotificationsViewProps) {notification?: UnifiedNotification,history: HistoryOptions = {}) => {- const calendarEvent = calendarSelection(entityOf(row, notification));+ const calendarEvent = calendarSelection(rowEntity(row, notification));if (calendarEvent &&guard.canSelect(undefined) &&@@ -993,108 +989,114 @@ export function NotificationsView(props: NotificationsViewProps) {</ViewShell.Root>);+ // One editor renders every card's text; without it each line of each card+ // builds its own.return (- <SplitPanel.Root>- <SplitPanel.Body>- <Show when={!isTouchDevice()} fallback={touchLayout()}>- <div class="size-full min-h-0 bg-panel">- <ViewShell.Root- asidePreferenceKey="notifications"- // Rows read as sentences, so the list starts wider than a nav rail.- aside={{ width: 360, max: 480, preserveDuringResize: false }}- // Narrow, the list and what it opens take turns.- asideList={{- open:- props.calendarPreview.isOpen() ||- previewTarget() !== undefined,- onBack: () => closePreview(),- }}- main={{ preferredWidth: 640 }}- resizable- >- <ViewShell.Aside class="flex flex-col bg-panel">- <ListHeader- actions={- <>- <div class="relative">- <InboxFilterMenu- open={filterOpen()}- onOpenChange={setFilterOpen}- {...filterControls}+ <StaticMarkdownContext>+ <SplitPanel.Root>+ <SplitPanel.Body>+ <Show when={!isTouchDevice()} fallback={touchLayout()}>+ <div class="size-full min-h-0 bg-panel">+ <ViewShell.Root+ asidePreferenceKey="notifications"+ // Rows read as sentences, so the list starts wider than a nav rail.+ aside={{ width: 360, max: 480, preserveDuringResize: false }}+ // Narrow, the list and what it opens take turns.+ asideList={{+ open:+ props.calendarPreview.isOpen() ||+ previewTarget() !== undefined,+ onBack: () => closePreview(),+ }}+ main={{ preferredWidth: 640 }}+ resizable+ >+ <ViewShell.Aside class="flex flex-col bg-panel">+ <ListHeader+ actions={+ <>+ <div class="relative">+ <InboxFilterMenu+ open={filterOpen()}+ onOpenChange={setFilterOpen}+ {...filterControls}+ />+ </div>+ <InboxClearMenu+ unreadOnly={filters.filters().status === 'unread'}+ isShown={filters.isShown}+ onClear={clear}/>- </div>- <InboxClearMenu- unreadOnly={filters.filters().status === 'unread'}- isShown={filters.isShown}- onClear={clear}- />- <Button- size="icon-md"- variant="ghost"- aria-label={t('notificationsInbox.settings')}- tooltip={t('notificationsInbox.settings')}- onClick={() => props.onOpenSettings()}- >- <GearSixIcon class="size-4" />- </Button>- </>- }- />- <div class="shrink-0 px-3 pb-1">- <InboxStatusTabs- status={filters.filters().status}- onChange={filters.setStatus}+ <Button+ size="icon-md"+ variant="ghost"+ aria-label={t('notificationsInbox.settings')}+ tooltip={t('notificationsInbox.settings')}+ onClick={() => props.onOpenSettings()}+ >+ <GearSixIcon class="size-4" />+ </Button>+ </>+ }/>- </div>- <div- role="grid"- aria-label={t('nav.notifications')}- aria-activedescendant={list.focus.key()}- tabIndex={0}- class="relative flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden outline-none"- >- {listBody()}- </div>- </ViewShell.Aside>- <ViewShell.Main class="overflow-hidden">- <NotificationsCalendarPaneProvider- value={{ refocus: props.calendarPreview.refocus }}- >- {/* A calendar event shows under the view's calendar route,+ <div class="shrink-0 px-3 pb-1">+ <InboxStatusTabs+ status={filters.filters().status}+ onChange={filters.setStatus}+ />+ </div>+ <div+ role="grid"+ aria-label={t('nav.notifications')}+ aria-activedescendant={list.focus.key()}+ tabIndex={0}+ class="relative flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden outline-none"+ >+ {listBody()}+ </div>+ </ViewShell.Aside>+ <ViewShell.Main class="overflow-hidden">+ <NotificationsCalendarPaneProvider+ value={{ refocus: props.calendarPreview.refocus }}+ >+ {/* A calendar event shows under the view's calendar route,which loads lazily: suspend only this pane, so the listkeeps its place. */}- <Suspense>- <SplitRouter.Outlet- fallback={() => (- <Show- when={previewTarget()}- fallback={- <EmptyStatePanel- centered- graphic={EmptyStateInboxTrayGraphic}- title={t('notificationsInbox.noneSelectedTitle')}- description={t(- 'notificationsInbox.noneSelectedDescription'- )}+ <Suspense>+ <SplitRouter.Outlet+ fallback={() => (+ <Show+ when={previewTarget()}+ fallback={+ <EmptyStatePanel+ centered+ graphic={EmptyStateInboxTrayGraphic}+ title={t(+ 'notificationsInbox.noneSelectedTitle'+ )}+ description={t(+ 'notificationsInbox.noneSelectedDescription'+ )}+ />+ }+ >+ <PreviewPanel+ target={previewTarget()}+ navigationRequest={selection.navigationRequest()}+ orchestrator={orchestrator}+ splitPanelContext={panel}/>- }- >- <PreviewPanel- target={previewTarget()}- navigationRequest={selection.navigationRequest()}- orchestrator={orchestrator}- splitPanelContext={panel}- />- </Show>- )}- />- </Suspense>- </NotificationsCalendarPaneProvider>- </ViewShell.Main>- </ViewShell.Root>- </div>- </Show>- </SplitPanel.Body>- </SplitPanel.Root>+ </Show>+ )}+ />+ </Suspense>+ </NotificationsCalendarPaneProvider>+ </ViewShell.Main>+ </ViewShell.Root>+ </div>+ </Show>+ </SplitPanel.Body>+ </SplitPanel.Root>+ </StaticMarkdownContext>);}diff --git a/apps/web/src/lib/signals/focus.ts b/apps/web/src/lib/signals/focus.tsindex 81b6ea8fd2..b308477c84 100644--- a/apps/web/src/lib/signals/focus.ts+++ b/apps/web/src/lib/signals/focus.ts@@ -12,6 +12,9 @@ const [rawActiveElement, setRawActiveElement] = createSignal<Element | null>();const [dirty, setDirty] = createSignal(undefined, { equals: () => false });+// A listener passed `setDirty` itself would store the event, whose target+// keeps a removed view alive until the next focus change.+const markDirty = () => setDirty();export function mountGlobalFocusListener(withDebug?: boolean) {const owner = getOwner();@@ -22,19 +25,19 @@ export function mountGlobalFocusListener(withDebug?: boolean) {return;}onMount(() => {- document.addEventListener('focusin', setDirty);- document.addEventListener('focusout', setDirty);+ document.addEventListener('focusin', markDirty);+ document.addEventListener('focusout', markDirty);// Removing a focused editor (or one of its ancestors) does not reliably// emit focusout. Reconcile after DOM changes so consumers cannot keep// treating a detached search input/composer as the active editor.const observer = new MutationObserver(() => {- if (rawActiveElement() !== document.activeElement) setDirty();+ if (rawActiveElement() !== document.activeElement) markDirty();});observer.observe(document, { childList: true, subtree: true });onCleanup(() => {observer.disconnect();- document.removeEventListener('focusin', setDirty);- document.removeEventListener('focusout', setDirty);+ document.removeEventListener('focusin', markDirty);+ document.removeEventListener('focusout', markDirty);});});@@ -51,4 +54,4 @@ export function mountGlobalFocusListener(withDebug?: boolean) {}export const activeElement = rawActiveElement;-const _recheckFocus = () => setDirty();+const _recheckFocus = markDirty;diff --git a/apps/web/src/observability/flow.tsx b/apps/web/src/observability/flow.tsxindex a5db7817d7..2bcb5741a1 100644--- a/apps/web/src/observability/flow.tsx+++ b/apps/web/src/observability/flow.tsx@@ -300,6 +300,22 @@ function openNode(* Names and attributes are static categories, ids, and counts; never user* content.*/+/**+ * The scope a flow hands its subtree. Built outside the component so its+ * getter closes over the node alone: requests carry the scope in their+ * context and can outlive the view (a cached query another view still+ * reads), and a closure sharing the component's scope would keep its props,+ * and with them the view's whole tree, alive.+ */+function flowScope(current: Accessor<FlowNode>): FlowScope {+ return {+ get node() {+ return untrack(current);+ },+ current,+ };+}+export function TraceFlow(props: {name: string;attributes?: Attributes;@@ -317,12 +333,7 @@ export function TraceFlow(props: {untrack(() => props.sampling));const [current, setCurrent] = createSignal(start());- const scope: FlowScope = {- get node() {- return untrack(current);- },- current,- };+ const scope = flowScope(current);const releaseMount = scope.node.hold();// Effects of this subtree run in the same flush; let them hold first.onMount(() => queueMicrotask(releaseMount));