Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(channel): fix reply target routing, nits for preview cards, disallow same block in preview and split (#6428)

Seamus9b675f4f2517
diff --git a/apps/web/src/components/app/PreviewPanel.tsx b/apps/web/src/components/app/PreviewPanel.tsx
index b4be1996f7..7eea191894 100644
--- a/apps/web/src/components/app/PreviewPanel.tsx
+++ b/apps/web/src/components/app/PreviewPanel.tsx
@@ -110,7 +110,9 @@ function PreviewPanelContent(
const [attachHotkeys, previewHotkeyScope] =
useHotkeyDOMScope('preview-panel');
- const blockInstance = createMemo(() => {
+ const blockInstance = createMemo<
+ ReturnType<BlockOrchestrator['createBlockInstance']> | undefined
+ >((previous) => {
const entity = props.selectedEntity;
const target = match(entity)
@@ -199,6 +201,13 @@ function PreviewPanelContent(
aliasContext: undefined,
}));
+ if (previous?.type === target.blockType && previous.id === target.blockId) {
+ return previous;
+ }
+ if (props.orchestrator.isBlockMounted(target.blockType, target.blockId)) {
+ return undefined;
+ }
+
return props.orchestrator.createBlockInstance(
target.blockType,
target.blockId,
@@ -214,6 +223,7 @@ function PreviewPanelContent(
() => props.selectedEntity,
(entity) => {
setInteractedWith(false);
+ if (!blockInstance()) return;
if (
entity.type === 'channel' ||
entity.type === 'channel_message' ||
@@ -313,7 +323,16 @@ function PreviewPanelContent(
onFocusOut={props.onFocusOut}
>
<Suspense>
- <Dynamic component={blockInstance().element} />
+ <Show
+ when={blockInstance()}
+ fallback={
+ <div class="flex size-full items-center justify-center text-sm text-ink-muted">
+ Content already open.
+ </div>
+ }
+ >
+ {(instance) => <Dynamic component={instance().element} />}
+ </Show>
</Suspense>
</PreviewPanelContext>
</SplitPanelContext.Provider>
diff --git a/apps/web/src/components/app/split-layout/layoutManager.ts b/apps/web/src/components/app/split-layout/layoutManager.ts
index 6f9d86f89f..e21406d45a 100644
--- a/apps/web/src/components/app/split-layout/layoutManager.ts
+++ b/apps/web/src/components/app/split-layout/layoutManager.ts
@@ -6,6 +6,7 @@ import type {
BlockName,
} from '@core/block';
import type { ResizeZoneCtx } from '@core/component/Resize/types';
+import { toast } from '@core/component/Toast/Toast';
import { isBlockAlias, resolveBlockAlias } from '@core/constant/allBlocks';
import { settingsTabToSlug } from '@core/constant/settingsTabsConfig';
import { isTouchDevice } from '@core/mobile/isTouchDevice';
@@ -2010,6 +2011,17 @@ export function createSplitLayout(
content: SplitContent,
options: OpenWithSplitOptions = {}
): SplitHandle | undefined {
+ // Inline previews register with the orchestrator without owning a split.
+ // Preserve that mount instead of attaching its shared handle a second time.
+ if (
+ content.type !== 'component' &&
+ !getSplitByContent(content.type, content.id) &&
+ orchestrator.isBlockMounted(resolveBlockAlias(content.type), content.id)
+ ) {
+ toast.alert('Content already open.');
+ return undefined;
+ }
+
if (options.reopen === 'latest') {
// Fire-and-forget so it covers every open path (fresh mount, duplicate
// activation, interceptor-consumed navigation). The block-handle proxy
diff --git a/apps/web/src/components/app/split-layout/tests/layoutManager.test.ts b/apps/web/src/components/app/split-layout/tests/layoutManager.test.ts
index dc1fa19c56..eb020bb064 100644
--- a/apps/web/src/components/app/split-layout/tests/layoutManager.test.ts
+++ b/apps/web/src/components/app/split-layout/tests/layoutManager.test.ts
@@ -5,6 +5,7 @@ import {
withListNavigationSource,
} from '@app/features/soup/collection/list-navigation-source';
import type { ResizeZoneCtx } from '@core/component/Resize/types';
+import { toast } from '@core/component/Toast/Toast';
import type { BlockOrchestrator } from '@core/orchestrator';
import { createRoot } from 'solid-js';
import { beforeAll, describe, expect, it, vi } from 'vitest';
@@ -16,6 +17,10 @@ import {
import { createMobileSwipeLayout } from '../mobile/createMobileSwipeLayout';
import { previewControllerWidthForContent } from '../previewController';
+vi.mock('@core/component/Toast/Toast', () => ({
+ toast: { alert: vi.fn() },
+}));
+
vi.mock('../componentRegistry', () => ({
resolveComponent: vi.fn((id: string, params: Record<string, string>) => ({
type: 'mock-component',
@@ -48,6 +53,7 @@ beforeAll(() => {
function createMockOrchestrator(): BlockOrchestrator {
return {
+ isBlockMounted: vi.fn(() => false),
createBlockInstance: vi.fn((_type, id, _splitId) => ({
node: { type: 'mock-node', id },
detach: vi.fn(),
@@ -58,6 +64,35 @@ function createMockOrchestrator(): BlockOrchestrator {
}
describe('layoutManager', () => {
+ it('rejects opening a previewed block until its mount is released', () => {
+ createRoot((dispose) => {
+ const orchestrator = createMockOrchestrator();
+ const manager = createSplitLayout(orchestrator, [
+ { type: 'component', id: 'inbox' },
+ ]);
+ vi.mocked(orchestrator.isBlockMounted).mockReturnValue(true);
+
+ expect(
+ manager.openWithSplit(
+ { type: 'channel', id: 'preview-channel' },
+ { preferNewSplit: true }
+ )
+ ).toBeUndefined();
+ expect(manager.splits()).toHaveLength(1);
+ expect(orchestrator.createBlockInstance).not.toHaveBeenCalled();
+ expect(toast.alert).toHaveBeenCalledWith('Content already open.');
+
+ vi.mocked(orchestrator.isBlockMounted).mockReturnValue(false);
+ manager.openWithSplit(
+ { type: 'channel', id: 'preview-channel' },
+ { preferNewSplit: true }
+ );
+ expect(manager.splits()).toHaveLength(2);
+ expect(orchestrator.createBlockInstance).toHaveBeenCalledOnce();
+ dispose();
+ });
+ });
+
describe('swapSplit', () => {
it('swaps adjacent splits and delegates the panel reorder to Resize', () => {
createRoot((dispose) => {
diff --git a/apps/web/src/components/app/split-layout/tests/layoutUrlSync.test.ts b/apps/web/src/components/app/split-layout/tests/layoutUrlSync.test.ts
index 758a3d7050..c3710bf082 100644
--- a/apps/web/src/components/app/split-layout/tests/layoutUrlSync.test.ts
+++ b/apps/web/src/components/app/split-layout/tests/layoutUrlSync.test.ts
@@ -40,6 +40,7 @@ beforeAll(() => {
function createMockOrchestrator(): BlockOrchestrator {
return {
+ isBlockMounted: vi.fn(() => false),
createBlockInstance: vi.fn((_type, id, _splitId) => ({
node: { type: 'mock-node', id },
detach: vi.fn(),
diff --git a/apps/web/src/components/app/split-layout/tests/splitFocusTracker.test.ts b/apps/web/src/components/app/split-layout/tests/splitFocusTracker.test.ts
index 4e8613211b..7ad6c4c125 100644
--- a/apps/web/src/components/app/split-layout/tests/splitFocusTracker.test.ts
+++ b/apps/web/src/components/app/split-layout/tests/splitFocusTracker.test.ts
@@ -44,6 +44,7 @@ beforeAll(() => {
function createMockOrchestrator(): BlockOrchestrator {
return {
+ isBlockMounted: vi.fn(() => false),
createBlockInstance: vi.fn((_type, id, _splitId) => ({
node: { type: 'mock-node', id },
detach: vi.fn(),
diff --git a/apps/web/src/components/ui/components/Dropdown.tsx b/apps/web/src/components/ui/components/Dropdown.tsx
index 7ca1e79ecc..bce96b2eb8 100644
--- a/apps/web/src/components/ui/components/Dropdown.tsx
+++ b/apps/web/src/components/ui/components/Dropdown.tsx
@@ -2,7 +2,13 @@ import { isModality } from '@core/mobile/inputModality';
import { isTouchDevice } from '@core/mobile/isTouchDevice';
import { DropdownMenu as KobalteDropdownMenu } from '@kobalte/core/dropdown-menu';
import CheckIcon from '@phosphor/check.svg';
-import { type ComponentProps, onCleanup, splitProps } from 'solid-js';
+import {
+ type ComponentProps,
+ createSignal,
+ onCleanup,
+ Show,
+ splitProps,
+} from 'solid-js';
import { cn } from '../utils/classname';
import {
addCtrlJKMenuNavigation,
@@ -50,6 +56,8 @@ export type DropdownContentProps = ComponentProps<
depth?: SurfaceProps['depth'];
mount?: PortalMount;
portalScope?: DropdownPortalScope;
+ /** Block pointer interaction behind the menu with a transparent backdrop. */
+ blockingBackdrop?: boolean;
};
export type DropdownTriggerProps = ComponentProps<
typeof KobalteDropdownMenu.Trigger
@@ -173,6 +181,7 @@ function callRef<T>(ref: ((el: T) => void) | undefined, el: T) {
function DropdownContent(props: DropdownContentProps) {
let searchRef: HTMLDivElement | undefined;
let contentRef: HTMLElement | undefined;
+ const [backdropZIndex, setBackdropZIndex] = createSignal<string>();
const [local, rest] = splitProps(props, [
'depth',
'class',
@@ -181,8 +190,13 @@ function DropdownContent(props: DropdownContentProps) {
'children',
'ref',
'onOpenAutoFocus',
+ 'blockingBackdrop',
]);
const handleOpenAutoFocus = (event: Event) => {
+ if (local.blockingBackdrop && contentRef) {
+ // Match custom menu layers; the following menu paints above the backdrop.
+ setBackdropZIndex(getComputedStyle(contentRef).zIndex);
+ }
local.onOpenAutoFocus?.(event);
// A tap-opened menu shouldn't start with a hover-like highlight
if (!event.defaultPrevented && contentRef && !isModality('touch')) {
@@ -202,6 +216,13 @@ function DropdownContent(props: DropdownContentProps) {
<KobalteDropdownMenu.Portal
mount={resolvePortalMount(searchRef, local.mount, local.portalScope)}
>
+ <Show when={local.blockingBackdrop}>
+ <div
+ class="fixed inset-0 z-action-menu pointer-events-auto"
+ style={{ 'z-index': backdropZIndex() }}
+ aria-hidden="true"
+ />
+ </Show>
<KobalteDropdownMenu.Content
class={cn(
// Paint the same surface as context menus, including custom
diff --git a/apps/web/src/lib/core/component/DocumentPreview.tsx b/apps/web/src/lib/core/component/DocumentPreview.tsx
index 904bc995e8..5ee3de2b41 100644
--- a/apps/web/src/lib/core/component/DocumentPreview.tsx
+++ b/apps/web/src/lib/core/component/DocumentPreview.tsx
@@ -704,7 +704,7 @@ export function DocumentPreviewContent(props: DocumentPreviewContentProps) {
>
<DotsThree />
</Dropdown.Trigger>
- <Dropdown.Content class="z-nested-action-menu">
+ <Dropdown.Content blockingBackdrop class="z-nested-action-menu">
<Dropdown.Group>
<Show when={props.previewInfo?.showPreview}>
<Dropdown.Item
@@ -732,7 +732,7 @@ export function DocumentPreviewContent(props: DocumentPreviewContentProps) {
<Show when={canOpenInChat()}>
<Dropdown.Item onSelect={handleOpenInChat}>
<SparkleIcon class="size-4" />
- Open Document in AI Chat
+ Ask Macro
</Dropdown.Item>
</Show>
<Dropdown.Item onSelect={handleCopy}>
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/ReplyTarget.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/ReplyTarget.tsx
index 7826a5b76b..6b7ae2324b 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/ReplyTarget.tsx
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/ReplyTarget.tsx
@@ -1,4 +1,5 @@
import { URL_PARAMS as CHANNEL_PARAMS } from '@block-channel/constants';
+import { useMaybeBlockId, useMaybeBlockName } from '@core/block';
import { StaticMarkdown } from '@core/component/LexicalMarkdown/component/core/StaticMarkdown';
import { singleLineMarkdownTheme } from '@core/component/LexicalMarkdown/theme';
import { getDisplayName, tryMacroId } from '@core/user';
@@ -11,6 +12,8 @@ import { openDocument } from '../core/BlockLink';
/** Single-line channel reply reference rendered by a ReplyTargetNode. */
export function ReplyTarget(props: ReplyTargetDecoratorProps) {
+ const currentBlockId = useMaybeBlockId();
+ const currentBlockName = useMaybeBlockName();
const channelBots = useChannelBotsQuery(() => props.channelId);
const senderName = () =>
getBotDisplayName(props.senderId, undefined, channelBots.data) ||
@@ -27,7 +30,10 @@ export function ReplyTarget(props: ReplyTargetDecoratorProps) {
[CHANNEL_PARAMS.message]: props.targetMessageId,
[CHANNEL_PARAMS.thread]: props.targetThreadId,
},
- openInNewSplitForMention(event.shiftKey, true)
+ openInNewSplitForMention(
+ event.shiftKey,
+ currentBlockName !== 'channel' || currentBlockId !== props.channelId
+ )
);
});
diff --git a/apps/web/src/lib/core/orchestrator.test.tsx b/apps/web/src/lib/core/orchestrator.test.tsx
new file mode 100644
index 0000000000..a7d275f728
--- /dev/null
+++ b/apps/web/src/lib/core/orchestrator.test.tsx
@@ -0,0 +1,43 @@
+import { render } from '@solidjs/testing-library';
+import type { ParentProps } from 'solid-js';
+import { expect, it, vi } from 'vitest';
+import { createBlockOrchestrator } from './orchestrator';
+
+vi.mock('./block', () => ({
+ Block: (props: ParentProps) => props.children,
+ ValidNestingCombinations: {},
+}));
+vi.mock('./constant/allBlocks', () => ({
+ blocks: { channel: { component: () => <div>Channel content</div> } },
+}));
+vi.mock('./internal/BlockLoader', () => ({ BlockLoader: () => null }));
+vi.mock('./internal/BlockEffectRunner', () => ({
+ BlockEffectRunner: () => null,
+}));
+vi.mock('./component/LoadingBlock', () => ({ LoadingBlock: () => null }));
+
+it('keeps one live mount and preserves its handle when a duplicate unmounts', async () => {
+ const orchestrator = createBlockOrchestrator();
+ const first = orchestrator.createBlockInstance('channel', 'channel-1');
+ const firstView = render(first.element);
+ const navigate = vi.fn();
+ first.handle.registerMethod('goToLocationFromParams', navigate);
+
+ const duplicate = orchestrator.createBlockInstance('channel', 'channel-1');
+ const duplicateView = render(duplicate.element);
+ expect(duplicateView.container.textContent).toBe('Content already open.');
+ expect(firstView.container.textContent).toBe('Channel content');
+ expect(orchestrator.isBlockMounted('channel', 'channel-1')).toBe(true);
+
+ duplicateView.unmount();
+ const handle = await orchestrator.getBlockHandle('channel-1', 'channel');
+ await handle?.goToLocationFromParams({ message: 'message-1' });
+ expect(navigate).toHaveBeenCalledOnce();
+
+ firstView.unmount();
+ expect(orchestrator.isBlockMounted('channel', 'channel-1')).toBe(false);
+ const reopened = orchestrator.createBlockInstance('channel', 'channel-1');
+ const reopenedView = render(reopened.element);
+ expect(reopenedView.container.textContent).toBe('Channel content');
+ reopenedView.unmount();
+});
diff --git a/apps/web/src/lib/core/orchestrator.tsx b/apps/web/src/lib/core/orchestrator.tsx
index d5f53c39be..8f5aa8ed08 100644
--- a/apps/web/src/lib/core/orchestrator.tsx
+++ b/apps/web/src/lib/core/orchestrator.tsx
@@ -92,6 +92,7 @@ type BlockInstance = {
type: BlockName;
id: string;
element: () => JSXElement;
+ isMounted: () => boolean;
nested?: NestedState<any>;
handle: OwnedBlockHandle<any>;
};
@@ -104,7 +105,7 @@ type CreateBlockOptions<Name extends BlockName = BlockName> = {
aliasContext?: BlockAliasContext;
};
-type UnmanagedBlockInstance = Omit<BlockInstance, 'handle'>;
+type UnmanagedBlockInstance = Omit<BlockInstance, 'handle' | 'isMounted'>;
/**
* Creates an unmanaged block instance
@@ -309,6 +310,8 @@ type CreateBlockInstanceFn = (
) => BlockInstance;
export type BlockOrchestrator = {
+ /** Whether a managed block is currently mounted in any surface. */
+ isBlockMounted: (type: BlockName, id: string) => boolean;
/** Get a publicly accessible handle to a block instance */
getBlockHandle: GetBlockHandleFn;
/**
@@ -435,11 +438,29 @@ export function createBlockOrchestrator(): BlockOrchestrator {
},
});
+ let mounted = false;
+ const mountOnce = () => {
+ if (mounted) {
+ return (
+ <div class="flex size-full items-center justify-center text-sm text-ink-muted">
+ Content already open.
+ </div>
+ );
+ }
+
+ mounted = true;
+ onCleanup(() => {
+ mounted = false;
+ });
+ return element();
+ };
+
const instance: BlockInstance = {
key,
type,
id,
- element,
+ element: mountOnce,
+ isMounted: () => mounted,
nested: opts?.nested,
handle: ownedHandle,
};
@@ -468,6 +489,8 @@ export function createBlockOrchestrator(): BlockOrchestrator {
}
return {
+ isBlockMounted: (type, id) =>
+ instances.get(keyOf(type, id))?.isMounted() ?? false,
getBlockHandle,
createBlockInstance: createManagedBlockInstance,
rekeyBlockInstance,
diff --git a/docs/AGENT_GUIDE/channels.md b/docs/AGENT_GUIDE/channels.md
index 6e701bb3f9..92b100f177 100644
--- a/docs/AGENT_GUIDE/channels.md
+++ b/docs/AGENT_GUIDE/channels.md
@@ -50,7 +50,9 @@ files`, `Format`, a `Task` switch (turns the message into a task), `Send message
Hover a message for its action menu. `Reply` on a top-level message opens that thread. On
an existing thread reply, it inserts a one-line reply-target reference into the composer;
-clicking the reference navigates back to that reply. If text in the message is
+clicking the reference navigates back to that reply. References to the current
+channel navigate in place, including inside the preview panel, without opening
+another split. If text in the message is
browser-selected before `Reply` is clicked, the reference previews only the selected text.
Clicking `Reply` again for a message already referenced anywhere in the draft keeps
the existing reference and draft unchanged, even if a different text selection is used.
diff --git a/docs/AGENT_GUIDE/documents.md b/docs/AGENT_GUIDE/documents.md
index 213202c2e7..d96faa7a36 100644
--- a/docs/AGENT_GUIDE/documents.md
+++ b/docs/AGENT_GUIDE/documents.md
@@ -58,7 +58,9 @@ Hover a document reference chip to open its preview without navigating. With
the preview open, the compact header shows a tinted icon, title, and author/time
byline. Click the title to open the document; the Reference actions ellipsis menu contains copy
link, split, embed/collapse, AI, and delete actions when applicable. The preview
-stays open while this menu is active. Images use an inset frame and task chips
+stays open while this menu is active, and moving over other reference chips must
+not open their previews. Click outside or press Escape to dismiss the menu;
+other references can then be hovered again. Images use an inset frame and task chips
appear below the header. Long titles wrap in place without a full-name tooltip.
With `ENABLE_GRAPHQL_SOUP` enabled, the popup reuses the reference's live `ItemPreviews`
diff --git a/docs/AGENT_GUIDE/navigation.md b/docs/AGENT_GUIDE/navigation.md
index 38d59d2f68..a4681b59bc 100644
--- a/docs/AGENT_GUIDE/navigation.md
+++ b/docs/AGENT_GUIDE/navigation.md
@@ -27,6 +27,12 @@
Splits: the app is a tiling window manager. A second pane appends its own segment to the URL
(`/app/<left>/<right>`). Each pane has its own Close / Go Back / Go Forward buttons.
+A block mounted in an inline preview cannot also open in a split. An attempt
+shows `Content already open.` and keeps the preview in place. Select another
+preview item or leave that view before opening the block in a split. Duplicate
+mounts reached through direct layout paths show the same message instead of a
+second block instance.
+
## Sidebar (a11y names are load-bearing)
- Top: buttons `Search` and `Create`. Clicking sidebar `Search` opens a menu