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): make mention chips clickable inside the agent and chat composers (#6818)
Wolf Mermelsteinde198d1f2834
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/AgentSessionMention.test.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/AgentSessionMention.test.tsxindex 249c7abae1..0f7907ca05 100644--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/AgentSessionMention.test.tsx+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/AgentSessionMention.test.tsx@@ -10,11 +10,6 @@ const mocks = vi.hoisted(() => ({vi.mock('@components/app/split-layout/layout', () => ({useSplitLayout: () => ({ openWithSplit: mocks.open }),}));-vi.mock('@core/util/useSplitNavigationHandler', () => ({- useSplitNavigationHandler: (onClick: (event: MouseEvent) => void) => ({- onClick,- }),-}));vi.mock('@queries/agent-session/mentions', () => ({useAgentSessionMentionPreview: () => mocks.query,}));@@ -114,6 +109,23 @@ describe('agent session mention rendering', () => {expect.anything());});+ it('opens from inside an editable editor, whose shell stops click propagation', () => {+ render(() => (+ <div on:click={(event) => event.stopPropagation()}>+ <AgentSessionMention+ id="session"+ label="Old title"+ key="node"+ theme={{}}+ />+ </div>+ ));+ fireEvent.click(screen.getByText('Fix mentions'));+ expect(mocks.open).toHaveBeenCalledWith(+ { type: 'agent', id: 'session' },+ expect.anything()+ );+ });it.each(['no_access', 'does_not_exist'])('hides saved metadata and disables opening for %s',(access) => {diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/AgentSessionMention.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/AgentSessionMention.tsxindex 4790f2137d..4b8af3cde9 100644--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/AgentSessionMention.tsx+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/AgentSessionMention.tsx@@ -2,7 +2,7 @@ import { useSplitLayout } from '@components/app/split-layout/layout';import { PopupPreview } from '@core/component/DocumentPreview';import { HoverCard } from '@core/component/HoverCard';import { openInNewSplitForMention } from '@core/util/openInNewSplit';-import { useSplitNavigationHandler } from '@core/util/useSplitNavigationHandler';+import { useNativeSplitNavigationHandler } from '@core/util/useSplitNavigationHandler';import {$isAgentSessionMentionNode,type AgentSessionMentionDecoratorProps,@@ -66,10 +66,12 @@ export function AgentSessionMention(props: AgentSessionMentionDecoratorProps) {COMMAND_PRIORITY_NORMAL));- const navigation = useSplitNavigationHandler<HTMLSpanElement>((event) => {- event.stopPropagation();- open(event);- });+ const navigation = useNativeSplitNavigationHandler<HTMLSpanElement>(+ (event) => {+ event.stopPropagation();+ open(event);+ }+ );const canExpand = () => Boolean(session() && wrapper?.isInteractable());const setExpanded = (expanded: boolean) => {if (!canExpand()) return;diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/ContactMention.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/ContactMention.tsxindex 434e196364..3b51ee13e0 100644--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/ContactMention.tsx+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/ContactMention.tsx@@ -1,6 +1,6 @@import { useSplitLayout } from '@components/app/split-layout/layout';import { openInNewSplitForMention } from '@core/util/openInNewSplit';-import { useSplitNavigationHandler } from '@core/util/useSplitNavigationHandler';+import { useNativeSplitNavigationHandler } from '@core/util/useSplitNavigationHandler';import type { ContactMentionDecoratorProps } from '@macro-inc/lexical-core';import BuildingIcon from '@phosphor/buildings.svg';import UserIcon from '@phosphor/user.svg';@@ -98,7 +98,7 @@ export function ContactMention(props: ContactMentionDecoratorProps) {);}- const navHandlers = useSplitNavigationHandler(openContact);+ const navHandlers = useNativeSplitNavigationHandler(openContact);return (<>diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/DocumentMention.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/DocumentMention.tsxindex ce39073b96..5bf5e5fc51 100644--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/DocumentMention.tsx+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/DocumentMention.tsx@@ -27,7 +27,7 @@ import { canNestBlock } from '@core/orchestrator';import { formatDate } from '@core/util/date';import { matches } from '@core/util/match';import { openInNewSplitForMention } from '@core/util/openInNewSplit';-import { useSplitNavigationHandler } from '@core/util/useSplitNavigationHandler';+import { useNativeSplitNavigationHandler } from '@core/util/useSplitNavigationHandler';import {$convertMentionToCard,$isDocumentMentionNode,@@ -124,8 +124,8 @@ function SkillSlashText(props: {const systemSkills = useSystemSkillsQuery();const openSkill = createCallback((e: MouseEvent) => {if (systemSkills.isSystemSkillId(props.documentId)) return;- // Also keeps the outer mention click handler (read-only contexts) from- // opening the skill a second time.+ // Also keeps the outer mention click handler from opening the skill a+ // second time.e.stopPropagation();openDocument('skill',@@ -635,7 +635,10 @@ function DocumentMentionInner(props: DocumentMentionDecoratorProps) {});};- const navHandlers = useSplitNavigationHandler<HTMLSpanElement>((e) => {+ // Native listeners: inside an editable editor (the agent and chat+ // composers) the shell stops click propagation before Solid's delegated+ // handlers run, which left the chip inert there.+ const navHandlers = useNativeSplitNavigationHandler<HTMLSpanElement>((e) => {e.stopPropagation();const i = item();if (diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/PullRequestMention.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/PullRequestMention.tsxindex c2370dc626..4984279e2b 100644--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/PullRequestMention.tsx+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/PullRequestMention.tsx@@ -1,7 +1,10 @@import { useSplitLayout } from '@components/app/split-layout/layout';import { HoverCard } from '@core/component/HoverCard';import { openInNewSplitForMention } from '@core/util/openInNewSplit';-import { useSplitNavigationHandler } from '@core/util/useSplitNavigationHandler';+import {+ useNativeSplitNavigationHandler,+ useSplitNavigationHandler,+} from '@core/util/useSplitNavigationHandler';import {$isPullRequestMentionNode,HISTORIC_TAG,@@ -453,7 +456,7 @@ export function PullRequestMention(props: PullRequestMentionDecoratorProps) {);}- const navHandlers = useSplitNavigationHandler<HTMLSpanElement>((e) => {+ const navHandlers = useNativeSplitNavigationHandler<HTMLSpanElement>((e) => {e.stopPropagation();open(e);});diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/Snapshot.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/Snapshot.tsxindex f19dc67966..782c7649e3 100644--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/Snapshot.tsx+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/Snapshot.tsx@@ -8,7 +8,7 @@ import { HoverCard } from '@core/component/HoverCard';import { verifyBlockName } from '@core/constant/allBlocks';import { matches } from '@core/util/match';import { openInNewSplitForMention } from '@core/util/openInNewSplit';-import { useSplitNavigationHandler } from '@core/util/useSplitNavigationHandler';+import { useNativeSplitNavigationHandler } from '@core/util/useSplitNavigationHandler';import {$isSnapshotNode,type SnapshotDecoratorProps,@@ -112,7 +112,7 @@ function SnapshotInner(props: SnapshotDecoratorProps) {removeNodeAndRestoreSelection(editor, props.key, $isSnapshotNode);};- const navHandlers = useSplitNavigationHandler<HTMLSpanElement>((e) => {+ const navHandlers = useNativeSplitNavigationHandler<HTMLSpanElement>((e) => {e.stopPropagation();if (matches(item(), (i) => !i.loading && i.access === 'access')) {open(e);diff --git a/apps/web/src/lib/core/util/useSplitNavigationHandler.test.tsx b/apps/web/src/lib/core/util/useSplitNavigationHandler.test.tsxnew file mode 100644index 0000000000..a4436e6fa2--- /dev/null+++ b/apps/web/src/lib/core/util/useSplitNavigationHandler.test.tsx@@ -0,0 +1,85 @@+import { cleanup, fireEvent, render } from '@solidjs/testing-library';+import { afterEach, describe, expect, it, vi } from 'vitest';+import {+ useNativeSplitNavigationHandler,+ useSplitNavigationHandler,+} from './useSplitNavigationHandler';++afterEach(cleanup);++/**+ * Stands in for the editable editor shell (`MarkdownShell`), which stops+ * click and mousedown propagation at the editor's wrapper element.+ */+function EditorShell(props: { children: any }) {+ return (+ <div+ on:click={(event) => event.stopPropagation()}+ on:mousedown={(event) => event.stopPropagation()}+ >+ {props.children}+ </div>+ );+}++describe('useSplitNavigationHandler', () => {+ it('opens on click and blocks the mousedown default outside an editor', () => {+ const onClick = vi.fn();+ const view = render(() => (+ <span {...useSplitNavigationHandler<HTMLSpanElement>(onClick)}>+ Mention+ </span>+ ));+ const chip = view.getByText('Mention');+ expect(fireEvent.mouseDown(chip)).toBe(false);+ fireEvent.click(chip);+ expect(onClick).toHaveBeenCalledTimes(1);+ });++ it('never fires inside an editor shell, because delegation is cut off', () => {+ const onClick = vi.fn();+ const view = render(() => (+ <EditorShell>+ <span {...useSplitNavigationHandler<HTMLSpanElement>(onClick)}>+ Mention+ </span>+ </EditorShell>+ ));+ fireEvent.click(view.getByText('Mention'));+ expect(onClick).not.toHaveBeenCalled();+ });+});++describe('useNativeSplitNavigationHandler', () => {+ it('opens on click inside an editor shell', () => {+ const onClick = vi.fn();+ const view = render(() => (+ <EditorShell>+ <span {...useNativeSplitNavigationHandler<HTMLSpanElement>(onClick)}>+ Mention+ </span>+ </EditorShell>+ ));+ const chip = view.getByText('Mention');+ expect(fireEvent.mouseDown(chip)).toBe(false);+ fireEvent.click(chip);+ expect(onClick).toHaveBeenCalledTimes(1);+ });++ it('lets the handler stop the click from reaching ancestors', () => {+ const outer = vi.fn();+ const view = render(() => (+ <div on:click={outer}>+ <span+ {...useNativeSplitNavigationHandler<HTMLSpanElement>((event) =>+ event.stopPropagation()+ )}+ >+ Mention+ </span>+ </div>+ ));+ fireEvent.click(view.getByText('Mention'));+ expect(outer).not.toHaveBeenCalled();+ });+});diff --git a/apps/web/src/lib/core/util/useSplitNavigationHandler.ts b/apps/web/src/lib/core/util/useSplitNavigationHandler.tsindex f1bbfd49b5..4ab950176d 100644--- a/apps/web/src/lib/core/util/useSplitNavigationHandler.ts+++ b/apps/web/src/lib/core/util/useSplitNavigationHandler.ts@@ -19,3 +19,24 @@ export function useSplitNavigationHandler<T extends HTMLElement>(onClick,};}++/**+ * `useSplitNavigationHandler` for elements rendered inside an editable Lexical+ * editor, such as mention chips in a composer. Solid's `onClick`/`onMouseDown`+ * are delegated to `document`, and an editable editor's shell stops click and+ * mousedown propagation before they get there, so the delegated handlers never+ * run. Native `on:` listeners fire on the element itself, ahead of the shell.+ */+export function useNativeSplitNavigationHandler<T extends HTMLElement>(+ onClick: JSX.EventHandler<T, MouseEvent>+): {+ 'on:mousedown': JSX.EventHandler<T, MouseEvent>;+ 'on:click': JSX.EventHandler<T, MouseEvent>;+} {+ return {+ 'on:mousedown': (e) => {+ e.preventDefault();+ },+ 'on:click': onClick,+ };+}diff --git a/docs/AGENT_GUIDE/ai-chat.md b/docs/AGENT_GUIDE/ai-chat.mdindex e98bca2bda..52fb7e1f4f 100644--- a/docs/AGENT_GUIDE/ai-chat.md+++ b/docs/AGENT_GUIDE/ai-chat.md@@ -400,6 +400,9 @@ used in chat and channels; they serialize as mention-chip tags in the promptthe agent sees (`<m-document-mention>` for docs/channels/chats/tasks/emails/calendarevents/skills, `<m-date-mention>` for a day or time, `<m-agent-session-mention>`for an agent session, `<m-user-mention>` for a person, and the other chip tags).+Clicking a chip while it still sits in the composer (Home, the Agents page, or+an agent session) opens the mentioned item in a new split and leaves the draft+and caret untouched; it does not send anything.Agent replies that emit those tags render as clickable chips in thetranscript (and in the originating channel thread). An agent-session chip with`"expanded":true` renders as the Magic Chip card that follows the session's