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(mentions): defer candidate ranking until the menu opens (#7801)
Sean Aye67ada9bd958e
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu.test.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu.test.tsxindex 9b7227b177..b1b0d639b0 100644--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu.test.tsx+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu.test.tsx@@ -1,15 +1,20 @@import type { IUser } from '@core/user';import { cleanup, fireEvent, render, screen } from '@solidjs/testing-library';+import { createEditor } from 'lexical';import { createSignal, type ParentProps } from 'solid-js';import { afterEach, expect, it, vi } from 'vitest';import { createMenuOperations } from '../../../shared/inlineMenu';import { useEmailSearchMention } from './hooks/useEmailSearchMention';import { MentionsMenu } from './MentionsMenu';+import * as mobileSort from './utils/mobileSort';const mocks = vi.hoisted(() => ({crmEnabled: false,+ mobile: false,requestedBuckets: [] as string[],contacts: [] as import('@core/context/quickAccess').EntityItem[],+ hasMoreContacts: false,+ loadMoreContacts: vi.fn(async () => {}),}));vi.mock('@app/features/crm/record-adapter', () => ({@@ -18,9 +23,9 @@ vi.mock('@app/features/crm/record-adapter', () => ({return {entities: () => mocks.contacts,totalCount: () => mocks.contacts.length,- hasMore: () => false,+ hasMore: () => mocks.hasMoreContacts,isLoadingMore: () => false,- loadMore: async () => {},+ loadMore: mocks.loadMoreContacts,};},}));@@ -65,7 +70,7 @@ vi.mock('@core/context/user', () => ({vi.mock('@core/constant/allBlocks', () => ({fileTypeToBlockName: () => 'md',}));-vi.mock('@core/mobile/isMobile', () => ({ isMobile: () => false }));+vi.mock('@core/mobile/isMobile', () => ({ isMobile: () => mocks.mobile }));vi.mock('@core/util/dateSearch/useDateSearch', () => ({useDateSearch: () => () => [],}));@@ -95,8 +100,11 @@ const originalScrollIntoView = Element.prototype.scrollIntoView;afterEach(() => {mocks.crmEnabled = false;+ mocks.mobile = false;mocks.requestedBuckets = [];mocks.contacts = [];+ mocks.hasMoreContacts = false;+ mocks.loadMoreContacts.mockClear();cleanup();vi.useRealTimers();vi.restoreAllMocks();@@ -145,6 +153,110 @@ it('keeps matching category and row nodes mounted across typing and updated peopexpect(menu.isOpen()).toBe(false);});+it.each([false, true])(+ 'leaves closed mention sources idle and refreshes them on reopen (mobile: %s)',+ async (mobile) => {+ mocks.mobile = mobile;+ vi.useFakeTimers();+ Element.prototype.scrollIntoView = vi.fn();+ const sort = vi.spyOn(mobileSort, 'sortMobileMentions');+ const seamus: IUser = {+ id: 'macro|[email protected]',+ name: 'Seamus Edson',+ email: '[email protected]',+ };+ const [users, setUsers] = createSignal([seamus]);+ const readUsers = vi.fn(users);+ const readEntities = vi.fn(() => []);+ const menu = createMenuOperations();+ const onPick = vi.fn();+ render(() => (+ <MentionsMenu+ menu={menu}+ users={readUsers}+ entities={readEntities}+ sources={['users', 'documents', 'channels']}+ anchor={document.createElement('div')}+ onPick={onPick}+ />+ ));++ expect(readUsers).not.toHaveBeenCalled();+ expect(readEntities).not.toHaveBeenCalled();+ expect(sort).not.toHaveBeenCalled();+ menu.setSearchTerm('sea');+ await vi.advanceTimersByTimeAsync(100);+ expect(readUsers).not.toHaveBeenCalled();+ expect(readEntities).not.toHaveBeenCalled();+ expect(sort).not.toHaveBeenCalled();++ menu.openMenu();+ expect(screen.getByTitle('Seamus Edson [email protected]')).toBeTruthy();+ expect(readUsers).toHaveBeenCalled();+ expect(readEntities).toHaveBeenCalled();+ if (mobile) expect(sort).toHaveBeenCalled();++ menu.closeMenu();+ readUsers.mockClear();+ readEntities.mockClear();+ sort.mockClear();+ const updated = { ...seamus, name: 'Seamus Updated' };+ setUsers([updated]);+ menu.setSearchTerm('updated');+ await vi.advanceTimersByTimeAsync(100);+ expect(readUsers).not.toHaveBeenCalled();+ expect(readEntities).not.toHaveBeenCalled();+ expect(sort).not.toHaveBeenCalled();++ menu.openMenu();+ expect(screen.getByTitle('Seamus Updated [email protected]')).toBeTruthy();+ fireEvent.keyDown(document, { key: 'Enter' });+ await vi.advanceTimersByTimeAsync(0);+ expect(onPick).toHaveBeenCalledWith(+ expect.objectContaining({ data: updated })+ );+ expect(menu.isOpen()).toBe(false);+ }+);++it('only paginates an open mobile menu and resumes on reopen', async () => {+ mocks.mobile = true;+ mocks.crmEnabled = true;+ mocks.hasMoreContacts = true;+ Element.prototype.scrollIntoView = vi.fn();+ vi.mocked(useEmailSearchMention).mockReturnValue({+ emails: () => [],+ totalCount: () => 0,+ hasMore: () => false,+ isLoadingMore: () => false,+ loadMore: async () => {},+ });+ const menu = createMenuOperations();+ const editor = createEditor();+ render(() => (+ <MentionsMenu+ menu={menu}+ editor={editor}+ users={() => []}+ sources={['users']}+ includeContacts+ />+ ));+ expect(mocks.loadMoreContacts).not.toHaveBeenCalled();++ menu.openMenu();+ await Promise.resolve();+ expect(mocks.loadMoreContacts).toHaveBeenCalledTimes(1);++ menu.closeMenu();+ await Promise.resolve();+ expect(mocks.loadMoreContacts).toHaveBeenCalledTimes(1);++ menu.openMenu();+ await Promise.resolve();+ expect(mocks.loadMoreContacts).toHaveBeenCalledTimes(2);+});+it('offers CRM companies and contacts', () => {mocks.crmEnabled = true;vi.mocked(useEmailSearchMention).mockReturnValue({diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu.tsxindex c73f9746df..757429c46c 100644--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu.tsx+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu.tsx@@ -323,6 +323,10 @@ function MentionsMenuInner(props: MentionsMenuProps) {});const bucketConfigs = createLazyMemo((): BucketConfig[] => {+ // Binning and pagination read these eagerly, outside the menu's Show.+ // Keep closed composers from gathering and ranking mention candidates.+ if (!menuOpen()) return [];+if (isMobile()) {return [{diff --git a/docs/AGENT_GUIDE/channels.md b/docs/AGENT_GUIDE/channels.mdindex 16d8796286..e6670af385 100644--- a/docs/AGENT_GUIDE/channels.md+++ b/docs/AGENT_GUIDE/channels.md@@ -180,6 +180,12 @@ it should open only one menu.The same software-keyboard check applies to `:` for emoji and `/` for formattingcommands: type a search and tap a result without sending the draft.+Closed mention menus do not gather, rank, or paginate candidates. When checking+channel-switch performance, include touch navigation back to the list and reopening+a cached channel without typing `@`. Then open mentions, search, close, and reopen:+results must reflect current people and entities, and scrolling or keyboard+navigation must still load more results. Check both mobile and desktop.+The shared `@` menu also offers `Recent agent sessions` after Channels andbefore Companies (the latest 500 accessible sessions, searchable by title orpersona). These inline chips show the shared