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(channels): open rail splits without waiting for notifications (#9348)
gbirman36fc892c02f3
diff --git a/apps/web/AGENTS.md b/apps/web/AGENTS.mdindex 76cbab0604..a0db5e061d 100644--- a/apps/web/AGENTS.md+++ b/apps/web/AGENTS.md@@ -567,6 +567,8 @@ resolved session ID; keep the existing `AgentSessionProvider` subscription to[dragging rows into a folder](../../docs/agent-guide/navigation.md#dragging-rows-into-a-folder).- Keep channel rail and title menus on `CHANNEL_ACTION_VIEW_CONTEXT`, includingthe shared desktop `Open in new split` action and its mobile/capacity guards.+ Rail splits open at latest before notifications load; only rows that stand+ for a notification (Home, Inbox) wait for it to choose a target.- Gate the Chat redesign with `enable-chat-sidebar-sections`; wait for its result, restore the tabbed rail when off, and keep mobile unchanged.Keep the original rail renderer and label dialogs in `components/rail/`; build the redesigned rail and section dialogs in `components/rail/next/`, with shared controller, context, and row primitives outside `next/`.With the flag on, keep desktop Chat sections in a scrolling stack with Favorites first and DMs directly below; personal and team-shared section assignments remain independent, including when dragging a row out of its originating section.diff --git a/apps/web/src/features/channel/Channel/channel-actions.ts b/apps/web/src/features/channel/Channel/channel-actions.tsindex ab78d7370d..9f027b5117 100644--- a/apps/web/src/features/channel/Channel/channel-actions.ts+++ b/apps/web/src/features/channel/Channel/channel-actions.ts@@ -10,4 +10,6 @@ export const CHANNEL_ACTION_VIEW_CONTEXT: EntityActionViewContext = {supportsMarkDone: false,supportsOpenInNewSplit: true,senderBucket: undefined,+ channelNavigation: 'latest',+ channelReadScope: 'top-level',};diff --git a/apps/web/src/features/channels-view/components/rail/ChannelsRail.test.tsx b/apps/web/src/features/channels-view/components/rail/ChannelsRail.test.tsxindex 85e5d9ec3b..933a4cbc4c 100644--- a/apps/web/src/features/channels-view/components/rail/ChannelsRail.test.tsx+++ b/apps/web/src/features/channels-view/components/rail/ChannelsRail.test.tsx@@ -591,73 +591,59 @@ describe('explicit channel activation read marking', () => {expect(mocks.markRead).not.toHaveBeenCalled();});- it.each([false, true])(- 'ignores superseded hydration (shift-click: %s)',- async (shiftKey) => {- let resolve!: (channel: WithNotification<ChannelEntity>) => void;- mocks.hydrate.mockReturnValueOnce(- new Promise((value) => {- resolve = value;- })- );- mount();- fireEvent.click(screen.getByRole('button'), { shiftKey });- expect(mocks.select).not.toHaveBeenCalled();- expect(mocks.openSplit).not.toHaveBeenCalled();- fireEvent.click(screen.getByRole('button'));- await waitFor(() => expect(mocks.select).toHaveBeenCalledOnce());- resolve(hydrated);- await Promise.resolve();- expect(mocks.select).toHaveBeenCalledOnce();- expect(mocks.openSplit).not.toHaveBeenCalled();- expect(mocks.markRead).toHaveBeenCalledExactlyOnceWith(- hydrated,- mocks.source,- { channelReadScope: 'top-level' }- );- }- );-- it('hydrates shift-clicks and opens at latest with top-level read marking', async () => {+ it('ignores superseded hydration', async () => {let resolve!: (channel: WithNotification<ChannelEntity>) => void;mocks.hydrate.mockReturnValueOnce(- new Promise((done) => {- resolve = done;+ new Promise((value) => {+ resolve = value;}));mount();- fireEvent.click(screen.getByRole('button'), { shiftKey: true });+ fireEvent.click(screen.getByRole('button'));+ expect(mocks.select).not.toHaveBeenCalled();expect(mocks.openSplit).not.toHaveBeenCalled();+ fireEvent.click(screen.getByRole('button'));+ await waitFor(() => expect(mocks.select).toHaveBeenCalledOnce());resolve(hydrated);- await waitFor(() =>- expect(mocks.openSplit).toHaveBeenCalledExactlyOnceWith(hydrated, {- openInNewSplit: true,- referredFrom: 'channels',- notificationSource: mocks.source,- channelNavigation: 'latest',- channelReadScope: 'top-level',- })+ await Promise.resolve();+ expect(mocks.select).toHaveBeenCalledOnce();+ expect(mocks.openSplit).not.toHaveBeenCalled();+ expect(mocks.markRead).toHaveBeenCalledExactlyOnceWith(+ hydrated,+ mocks.source,+ { channelReadScope: 'top-level' });+ });++ it('opens a shift-click at latest without waiting for notifications', () => {+ mocks.hydrate.mockReturnValue(new Promise(() => {}));+ mount();+ fireEvent.click(screen.getByRole('button'), { shiftKey: true });+ expect(mocks.openSplit).toHaveBeenCalledExactlyOnceWith(channel, {+ openInNewSplit: true,+ referredFrom: 'channels',+ notificationSource: mocks.source,+ channelNavigation: 'latest',+ channelReadScope: 'top-level',+ });+ expect(mocks.hydrate).not.toHaveBeenCalled();expect(mocks.select).not.toHaveBeenCalled();});- it.each([false, true])(- 'reports hydration failures without opening a partial edge (shift-click: %s)',- async (shiftKey) => {- const log = vi.spyOn(console, 'error').mockImplementation(() => {});- mocks.hydrate.mockRejectedValueOnce(new Error('failed'));- try {- mount();- fireEvent.click(screen.getByRole('button'), { shiftKey });- await waitFor(() => expect(mocks.failure).toHaveBeenCalledOnce());- expect(mocks.markRead).not.toHaveBeenCalled();- expect(mocks.select).not.toHaveBeenCalled();- expect(mocks.openSplit).not.toHaveBeenCalled();- } finally {- log.mockRestore();- }+ it('reports hydration failures without marking a re-click read', async () => {+ const log = vi.spyOn(console, 'error').mockImplementation(() => {});+ mocks.hydrate.mockRejectedValueOnce(new Error('failed'));+ try {+ mount();+ fireEvent.click(screen.getByRole('button'));+ await waitFor(() => expect(mocks.failure).toHaveBeenCalledOnce());+ expect(mocks.markRead).not.toHaveBeenCalled();+ expect(mocks.select).not.toHaveBeenCalled();+ expect(mocks.openSplit).not.toHaveBeenCalled();+ } finally {+ log.mockRestore();}- );+ });});describe('channel row presses', () => {diff --git a/apps/web/src/features/channels-view/components/rail/ChannelsRail.tsx b/apps/web/src/features/channels-view/components/rail/ChannelsRail.tsxindex 4ca1070505..a090e112ec 100644--- a/apps/web/src/features/channels-view/components/rail/ChannelsRail.tsx+++ b/apps/web/src/features/channels-view/components/rail/ChannelsRail.tsx@@ -247,10 +247,16 @@ export function ChannelsRail(props: ChannelsRailProps) {reportActivationError(new Error('Missing channel id'));return;}+ // A split opens at the row's target or at latest, so nothing it needs+ // depends on notifications. The open hydrates them to mark the read.+ if (openInNewSplit) {+ fireAndForget(selectChannel(channel, channelId, true), 'channels-view');+ return;+ }// A different channel owns its loading UI and notification hydration.// Select it before fetching so the rail and destination respond to the// click immediately. Re-clicks still refresh and re-aim the open channel.- if (!openInNewSplit && selectedChannel()?.id !== channelId) {+ if (selectedChannel()?.id !== channelId) {setSelectedChannel(channelPreviewSelection(channelId, {target: channel.target@@ -268,12 +274,12 @@ export function ChannelsRail(props: ChannelsRailProps) {// instances of that constructor. Detect the pending edge structurally.if ('then' in selection) {fireAndForget(- selectHydratedChannel(selection, request, channelId, openInNewSplit),+ selectHydratedChannel(selection, request, channelId, false),'channels-view');} else {fireAndForget(- selectChannel(selection, channelId, openInNewSplit),+ selectChannel(selection, channelId, false),'channels-view');}diff --git a/apps/web/src/features/next-soup/actions/entity-action-context.ts b/apps/web/src/features/next-soup/actions/entity-action-context.tsindex b2a1c6762a..b9f6931361 100644--- a/apps/web/src/features/next-soup/actions/entity-action-context.ts+++ b/apps/web/src/features/next-soup/actions/entity-action-context.ts@@ -16,6 +16,12 @@ export type EntityActionViewContext = {supportsMarkDone: boolean;supportsOpenInNewSplit: boolean;senderBucket: EntityActionSenderBucket | undefined;+ /**+ * How an open action treats a conversation, for views whose rows don't+ * stand for a notification. Unset views keep the open defaults.+ */+ channelNavigation?: 'latest';+ channelReadScope?: 'top-level';};export type EntityActionNavigationEvent = {diff --git a/apps/web/src/features/next-soup/utils.ts b/apps/web/src/features/next-soup/utils.tsindex 88776b0a01..3bb75bfe7c 100644--- a/apps/web/src/features/next-soup/utils.ts+++ b/apps/web/src/features/next-soup/utils.ts@@ -766,29 +766,36 @@ export const openEntityInSplitFromUnifiedList = async (splitContent = withListNavigationSource(splitContent, splitHandle);}- const hydrateNotificationsAndMarkSeen = async (+ const hydrateNotificationsAndMarkSeen = (channel: ChannelEntity,notificationSource: NotificationSource- ) => {- try {- const hydrated = await hydrateChannelNotificationSelection(- channel,- notificationSource.withLocalOverrides- );- const view = splitManager.findOpenView(content);- // A late response must not mark a closed conversation or a mobile pane- // that the user has already left. Hydration never reopens or retargets it.- if (!view || (isTouchDevice() && !view.topLevelSplit?.isActive())) return;- markChannelNotificationsSeenOnOpen(hydrated, notificationSource, {- channelReadScope: options.channelReadScope,- });- } catch (error) {- console.error('Failed to load conversation notifications after opening', {- channelId: channel.id,- error,- });- }- };+ ) =>+ Telemetry.span('channel.open.notifications', async (span) => {+ span.setAttr('channel.id', channel.id);+ try {+ const hydrated = await hydrateChannelNotificationSelection(+ channel,+ notificationSource.withLocalOverrides+ );+ const view = splitManager.findOpenView(content);+ // A late response must not mark a closed conversation or a mobile pane+ // that the user has already left. Hydration never reopens or retargets it.+ if (!view || (isTouchDevice() && !view.topLevelSplit?.isActive())) {+ span.setAttr('channel.open.outcome', 'left');+ return;+ }+ markChannelNotificationsSeenOnOpen(hydrated, notificationSource, {+ channelReadScope: options.channelReadScope,+ });+ span.setAttr('channel.open.outcome', 'loaded');+ } catch (error) {+ span.setAttr('channel.open.outcome', 'failed');+ console.error(+ 'Failed to load conversation notifications after opening',+ { channelId: channel.id, error }+ );+ }+ });let markedNotifications = false;const markNotificationsSeen = () => {diff --git a/apps/web/src/features/soup/createSoupEntityActions.test.ts b/apps/web/src/features/soup/createSoupEntityActions.test.tsnew file mode 100644index 0000000000..88857c744a--- /dev/null+++ b/apps/web/src/features/soup/createSoupEntityActions.test.ts@@ -0,0 +1,127 @@+import type {+ EntityActionListState,+ EntityActionViewContext,+} from '@app/features/next-soup/actions';+import { CHANNEL_ACTION_VIEW_CONTEXT } from '@channel/Channel/channel-actions';+import type { EntityData } from '@entity';+import { beforeEach, describe, expect, it, vi } from 'vitest';+import { createSoupEntityActions } from './createSoupEntityActions';++const mocks = vi.hoisted(() => ({+ action: () => ({ canExecute: () => false, execute: () => {} }),+ open: vi.fn(+ async (+ _entity: unknown,+ _options: { channelNavigation?: string; channelReadScope?: string }+ ) => {}+ ),+ source: {},+}));++vi.mock('@app/features/next-soup/actions', () => ({+ emailSenderBucket: () => undefined,+ makeArchiveSessionAction: mocks.action,+ makeBlockSenderAction: mocks.action,+ makeChannelPictureAction: mocks.action,+ makeCopyAction: mocks.action,+ makeCopyBranchNameAction: mocks.action,+ makeCopyEntityIdAction: mocks.action,+ makeCopyLinkAction: mocks.action,+ makeCreateReminderAction: mocks.action,+ makeDeleteAction: mocks.action,+ makeDownloadAction: mocks.action,+ makeFavoriteAction: mocks.action,+ makeGithubLinkAction: mocks.action,+ makeMarkDoneAction: mocks.action,+ makeMarkNotDoneAction: mocks.action,+ makeMarkNotificationsReadAction: mocks.action,+ makeMarkReadAction: mocks.action,+ makeMarkSenderNoiseAction: mocks.action,+ makeMarkSenderSignalAction: mocks.action,+ makeMarkUnreadAction: mocks.action,+ makeMoveToProjectAction: mocks.action,+ makeMuteAction: mocks.action,+ makeRemoveFromProjectAction: mocks.action,+ makeRenameAction: mocks.action,+ makeShareAction: mocks.action,+}));+vi.mock('@app/features/crm/crm-action-items', () => ({+ createCrmEntityActionItems: () => () => [],+}));+vi.mock('@app/features/next-soup/utils', () => ({+ markRowNotificationsSeenOnOpen: vi.fn(),+ openEntityInSplitFromUnifiedList: mocks.open,+ restoreSoupFocus: vi.fn(),+}));+vi.mock('@app/features/property/editor/hooks/useAllProperties', () => ({+ useAllProperties: () => () => [],+}));+vi.mock('@app/features/property/editor/state/propertyEditor', () => ({+ openPropertyEditor: vi.fn(),+}));+vi.mock('@app/lib/analytics/analytics-context', () => ({+ useAnalytics: () => ({ track: vi.fn() }),+}));+vi.mock('@app/lib/analytics/posthog', () => ({+ useFeatureFlag: () => () => ({ enabled: false }),+}));+vi.mock('@app/lib/i18n', () => ({ t: (key: string) => key }));+vi.mock('@app/signal/splitLayout', () => ({+ globalSplitManager: () => ({+ getSplitByContent: () => undefined,+ canAppendSplit: () => true,+ }),+}));+vi.mock('@components/app/GlobalAppState', () => ({+ useGlobalNotificationSource: () => mocks.source,+}));+vi.mock('@core/context/user', () => ({ useUserId: () => () => 'user' }));+vi.mock('@core/mobile/isMobile', () => ({ isMobile: () => false }));++const channel = {+ type: 'channel',+ id: 'channel',+ name: 'General',+ unreadNotifications: [],+} as unknown as EntityData;++const openFromMenu = async (viewContext: EntityActionViewContext) => {+ const { buildActionGroups } = createSoupEntityActions();+ const item = buildActionGroups({} as EntityActionListState, [channel], {+ viewContext,+ })+ .flatMap((group) => group.items)+ .find(({ id }) => id === 'open-in-split');+ await item?.onClick();+};++beforeEach(() => mocks.open.mockClear());++describe('Open in new split on a conversation', () => {+ it('opens a channel rail row at latest with its top-level read scope', async () => {+ await openFromMenu(CHANNEL_ACTION_VIEW_CONTEXT);++ expect(mocks.open).toHaveBeenCalledExactlyOnceWith(+ channel,+ expect.objectContaining({+ openInNewSplit: true,+ notificationSource: mocks.source,+ channelNavigation: 'latest',+ channelReadScope: 'top-level',+ })+ );+ });++ it('keeps a row from another list aimed at its notification', async () => {+ await openFromMenu({+ supportsMarkDone: true,+ supportsOpenInNewSplit: true,+ senderBucket: undefined,+ });++ expect(mocks.open).toHaveBeenCalledOnce();+ const options = mocks.open.mock.calls[0]?.[1];+ expect(options?.channelNavigation).toBeUndefined();+ expect(options?.channelReadScope).toBeUndefined();+ });+});diff --git a/apps/web/src/features/soup/createSoupEntityActions.ts b/apps/web/src/features/soup/createSoupEntityActions.tsindex ce6a7d1d48..441c450a53 100644--- a/apps/web/src/features/soup/createSoupEntityActions.ts+++ b/apps/web/src/features/soup/createSoupEntityActions.ts@@ -300,6 +300,8 @@ export function createSoupEntityActions(splitHandle,referredFrom: 'entity-actions-menu',notificationSource,+ channelNavigation: viewContext.channelNavigation,+ channelReadScope: viewContext.channelReadScope,});};diff --git a/docs/agent-guide/channels.md b/docs/agent-guide/channels.mdindex ea8069deb9..87cfa4da73 100644--- a/docs/agent-guide/channels.md+++ b/docs/agent-guide/channels.md@@ -1187,6 +1187,11 @@ links still open their target. Each accepted click marks top-level notificationsfrom the full loaded edge seen; an abbreviated list edge is never sufficient.A rejected selection or unavailable split must not mark the conversation read.Non-participant rows retain their membership status and do not mark notifications.+Shift-click and the row menu's `Open in new split` open a loaded row without+waiting for notifications: hold the single-channel `SoupNotifications` request+(`UPDATED_AT`, limit 1) and the split must still appear at once. Its full edge+loads after the open. A failed load leaves the split open and skips that marking;+messages on screen still mark themselves read as they become visible.Shift-click a favorite whose channel is not loaded in the rail: its membershipand full notification edge load before the split opens with the same top-levelread policy. Selecting another channel while that request is pending must cancel