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
chore(agents): reserve 16:9 cards while walkthrough artifacts load (#6861)
Wolf Mermelsteinfd83b5584f70
diff --git a/apps/web/src/features/block-agent/debug/Gallery.tsx b/apps/web/src/features/block-agent/debug/Gallery.tsxindex 426a519cc2..cc217be8c2 100644--- a/apps/web/src/features/block-agent/debug/Gallery.tsx+++ b/apps/web/src/features/block-agent/debug/Gallery.tsx@@ -7,6 +7,8 @@import { StaticMarkdownContext } from '@core/component/LexicalMarkdown/component/core/StaticMarkdown';import { MagicChipView } from '@core/component/LexicalMarkdown/component/decorator/MagicChip/MagicChipView';import type { MagicChipPresentation } from '@core/component/LexicalMarkdown/component/decorator/MagicChip/presentation';+import { MarkdownImage } from '@core/component/LexicalMarkdown/component/decorator/MarkdownImage';+import { MediaLoadingPlaceholder } from '@core/component/LexicalMarkdown/component/decorator/MediaLoadingPlaceholder';import { useUserId } from '@core/context/user';import FileText from '@phosphor/file-text.svg';import MagnifyingGlass from '@phosphor/magnifying-glass.svg';@@ -1258,6 +1260,38 @@ export default function AgentUiGallery() {<Message message={FIXTURE_MESSAGE} inFlight={false} /></Item>+ <Item label="AgentMessage (multi-artifact loading)">+ <p class="text-xs text-ink-muted">+ Walkthrough files without a known size reserve a 16:9 card each,+ named from the file, instead of a stack of floating spinners.+ </p>+ <div class="max-w-xl text-base">+ <p class="mb-1 text-sm text-ink-muted">Thoughted</p>+ <p class="mb-2">Done and looking good.</p>+ <MarkdownImage+ key="artifact-image-1"+ srcType="url"+ id=""+ url=""+ alt="walkthrough.png"+ width={0}+ height={0}+ scale={1}+ />+ <MarkdownImage+ key="artifact-image-2"+ srcType="url"+ id=""+ url=""+ alt="agents_list.png"+ width={0}+ height={0}+ scale={1}+ />+ <MediaLoadingPlaceholder kind="video" label="demo.mp4" />+ </div>+ </Item>+<Item label="AgentMessage (Cursor turn in flight)"><p class="text-xs text-ink-muted">Earlier reasoning has settled. Only the trailing thought stilldiff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/MarkdownImage.test.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/MarkdownImage.test.tsxnew file mode 100644index 0000000000..3f0774b68b--- /dev/null+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/MarkdownImage.test.tsx@@ -0,0 +1,71 @@+/**+ * @vitest-environment jsdom+ */++import { render, screen } from '@solidjs/testing-library';+import { describe, expect, it, vi } from 'vitest';++const mediaPlugin = vi.hoisted(() => ({+ $upgradeDSSMediaUrl: vi.fn(),+ getMediaUrl: vi.fn(),+ ON_MEDIA_COMPONENT_MOUNT_COMMAND: 'ON_MEDIA_COMPONENT_MOUNT_COMMAND',+ UPDATE_MEDIA_SIZE_COMMAND: 'UPDATE_MEDIA_SIZE_COMMAND',+ UPLOAD_MEDIA_FAILURE_COMMAND: 'UPLOAD_MEDIA_FAILURE_COMMAND',+ UPLOAD_MEDIA_START_COMMAND: 'UPLOAD_MEDIA_START_COMMAND',+ UPLOAD_MEDIA_SUCCESS_COMMAND: 'UPLOAD_MEDIA_SUCCESS_COMMAND',+}));+vi.mock('../../plugins/media', () => mediaPlugin);+vi.mock('../../plugins', () => mediaPlugin);+vi.mock('@core/component/Lightbox', () => ({+ Lightbox: () => null,+}));+vi.mock('@core/component/Toast/Toast', () => ({+ toast: { failure: vi.fn() },+}));++import { MarkdownImage } from './MarkdownImage';+import { MarkdownVideo } from './MarkdownVideo';++const unsetMedia = {+ srcType: 'url',+ id: '',+ width: 0,+ height: 0,+ scale: 1,+} as const;++describe('markdown media loading', () => {+ it('shows a reserved image card while the file has no size yet', () => {+ render(() => (+ <MarkdownImage+ {...unsetMedia}+ key="image"+ url="https://files.macro.com/walkthrough.png"+ alt="walkthrough.png"+ />+ ));+ const card = screen.getByRole('status', {+ name: 'Loading walkthrough.png',+ });+ expect(card.getAttribute('data-media-loading')).toBe('image');+ expect(card.className).toContain('aspect-video');+ });++ it('shows a reserved video card named from the url', () => {+ render(() => (+ <MarkdownVideo+ {...unsetMedia}+ key="video"+ url="https://files.macro.com/agents_list.mp4"+ controls+ />+ ));+ const card = screen.getByRole('status', {+ name: 'Loading agents_list.mp4',+ });+ expect(card.getAttribute('data-media-loading')).toBe('video');+ expect(card.className).toContain('aspect-video');+ // Unknown size used to set max-height: 0, which clipped the card.+ expect(card.parentElement?.style.maxHeight).toBe('');+ });+});diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/MarkdownImage.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/MarkdownImage.tsxindex 3178cdd169..4b2898a6a9 100644--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/MarkdownImage.tsx+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/MarkdownImage.tsx@@ -45,6 +45,7 @@ import {} from '../../plugins/media';import { removeNodeAndRestoreSelection } from '../../plugins/shared/removeNodeAndRestoreSelection';import { MediaButtons } from './MediaButtons';+import { MediaLoadingPlaceholder } from './MediaLoadingPlaceholder';import { ResizeHandle } from './ResizeHandle';type ImageState = 'loading' | 'ok' | 'error';@@ -316,7 +317,10 @@ export function MarkdownImage(props: ImageDecoratorProps) {crossorigin="anonymous"class={cn('h-full object-contain',- (state() === 'loading' || state() === 'error') && 'invisible'+ (state() === 'loading' || state() === 'error') && 'invisible',+ state() === 'loading' &&+ !effectiveDims()[0] &&+ 'absolute inset-0 size-0')}draggable={true}use:internalDrag={true}@@ -337,9 +341,16 @@ export function MarkdownImage(props: ImageDecoratorProps) {</Show><Show when={state() === 'loading'}>- <div class="absolute top-0 left-0 size-full flex flex-col justify-center items-center gap-2 text-ink-extra-muted bg-hover/50">- <Spinner />- </div>+ <Show+ when={effectiveDims()[0] > 0}+ fallback={+ <MediaLoadingPlaceholder kind="image" label={props.alt} />+ }+ >+ <div class="absolute top-0 left-0 size-full flex flex-col justify-center items-center gap-2 text-ink-extra-muted bg-hover/50">+ <Spinner />+ </div>+ </Show></Show><Show when={uploading() && state() !== 'error'}>diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/MarkdownVideo.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/MarkdownVideo.tsxindex eb6c51c1e8..66e31d77fd 100644--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/MarkdownVideo.tsx+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/MarkdownVideo.tsx@@ -39,6 +39,10 @@ import {} from '../../plugins';import { removeNodeAndRestoreSelection } from '../../plugins/shared/removeNodeAndRestoreSelection';import { MediaButtons } from './MediaButtons';+import {+ MediaLoadingPlaceholder,+ mediaFileNameFromUrl,+} from './MediaLoadingPlaceholder';import { ResizeHandle } from './ResizeHandle';type VideoState = 'loading' | 'ok' | 'error';@@ -255,7 +259,9 @@ export function MarkdownVideo(props: VideoDecoratorProps) {'pattern-edge-muted pattern-diagonal-8 min-h-44')}style={{- 'max-height': `${videoDims() ? videoDims()[1] * scale() : 640}px`,+ 'max-height': videoDims()[1]+ ? `${videoDims()[1] * scale()}px`+ : undefined,'aspect-ratio':videoDims()[0] && videoDims()[1]? `${videoDims()[0] / videoDims()[1]}`@@ -297,7 +303,10 @@ export function MarkdownVideo(props: VideoDecoratorProps) {crossorigin="anonymous"class={cn('h-full object-contain',- (state() === 'loading' || state() === 'error') && 'invisible'+ (state() === 'loading' || state() === 'error') && 'invisible',+ state() === 'loading' &&+ !videoDims()[0] &&+ 'absolute inset-0 size-0')}draggable={true}ref={videoRef}@@ -316,9 +325,19 @@ export function MarkdownVideo(props: VideoDecoratorProps) {</Show><Show when={state() === 'loading'}>- <div class="absolute top-0 left-0 size-full flex flex-col justify-center items-center gap-2 text-ink-extra-muted bg-hover/50">- <Spinner />- </div>+ <Show+ when={videoDims()[0] > 0}+ fallback={+ <MediaLoadingPlaceholder+ kind="video"+ label={mediaFileNameFromUrl(props.url)}+ />+ }+ >+ <div class="absolute top-0 left-0 size-full flex flex-col justify-center items-center gap-2 text-ink-extra-muted bg-hover/50">+ <Spinner />+ </div>+ </Show></Show><Show when={uploading() && state() !== 'error'}>diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/MediaLoadingPlaceholder.test.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/MediaLoadingPlaceholder.test.tsxnew file mode 100644index 0000000000..b868a97c76--- /dev/null+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/MediaLoadingPlaceholder.test.tsx@@ -0,0 +1,48 @@+/**+ * @vitest-environment jsdom+ */++import { render, screen } from '@solidjs/testing-library';+import { describe, expect, it } from 'vitest';+import {+ MediaLoadingPlaceholder,+ mediaFileNameFromUrl,+} from './MediaLoadingPlaceholder';++describe('MediaLoadingPlaceholder', () => {+ it('reserves a 16:9 card and names the file that is still loading', () => {+ render(() => (+ <MediaLoadingPlaceholder kind="image" label="walkthrough.png" />+ ));+ const card = screen.getByRole('status', {+ name: 'Loading walkthrough.png',+ });+ expect(card.getAttribute('data-media-loading')).toBe('image');+ expect(card.className).toContain('aspect-video');+ expect(screen.getByText('walkthrough.png')).toBeTruthy();+ });++ it('falls back to Image or Video when the file has no name', () => {+ const view = render(() => <MediaLoadingPlaceholder kind="video" />);+ expect(screen.getByRole('status', { name: 'Loading Video' })).toBeTruthy();+ expect(screen.getByText('Video')).toBeTruthy();++ view.unmount();+ render(() => <MediaLoadingPlaceholder kind="image" label=" " />);+ expect(screen.getByRole('status', { name: 'Loading Image' })).toBeTruthy();+ });+});++describe('mediaFileNameFromUrl', () => {+ it('keeps a file name and drops opaque ids', () => {+ expect(+ mediaFileNameFromUrl('https://files.macro.com/walkthrough.mp4')+ ).toBe('walkthrough.mp4');+ expect(+ mediaFileNameFromUrl(+ 'https://static-file-service-dev.macro.com/file/499fcf96-b38f-4660-9994-8b6a7da58f13'+ )+ ).toBeUndefined();+ expect(mediaFileNameFromUrl('not a url')).toBeUndefined();+ });+});diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/MediaLoadingPlaceholder.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/MediaLoadingPlaceholder.tsxnew file mode 100644index 0000000000..33c9794d28--- /dev/null+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/MediaLoadingPlaceholder.tsx@@ -0,0 +1,67 @@+/**+ * Reserved card while a markdown image or video is still fetching.+ *+ * Artifact markdown (cloud-agent screenshots and recordings) arrives without+ * width/height, so the media node itself has no box. Without this placeholder+ * the loading spinner sits in a zero-height overlay and a run of files+ * collapses to a stack of dots.+ */++import VideoIcon from '@phosphor/file-video.svg';+import ImageIcon from '@phosphor/image.svg';+import LoadingSpinner from '@phosphor/spinner.svg';+import { cn } from '@ui';+import { Show } from 'solid-js';++export function MediaLoadingPlaceholder(props: {+ kind: 'image' | 'video';+ /** File name from the image alt text, or the last path segment of a video. */+ label?: string;+}) {+ const caption = () => {+ const label = props.label?.trim();+ if (label) return label;+ return props.kind === 'video' ? 'Video' : 'Image';+ };++ return (+ <div+ role="status"+ aria-busy="true"+ aria-label={`Loading ${caption()}`}+ data-media-loading={props.kind}+ class={cn(+ 'relative w-full max-w-[640px] aspect-video overflow-hidden',+ 'rounded-xl border border-edge bg-skeleton skeleton-shimmer'+ )}+ >+ <div class="absolute inset-0 flex items-center justify-center text-ink-extra-muted">+ <LoadingSpinner class="size-5 animate-spin" />+ </div>+ <div class="absolute inset-x-0 bottom-0 flex items-center gap-1.5 bg-surface/80 px-3 py-2 text-xs text-ink-muted">+ <Show+ when={props.kind === 'video'}+ fallback={<ImageIcon class="size-3.5 shrink-0" />}+ >+ <VideoIcon class="size-3.5 shrink-0" />+ </Show>+ <span class="truncate">{caption()}</span>+ </div>+ </div>+ );+}++/** Last path segment when it looks like a file name, otherwise undefined. */+export function mediaFileNameFromUrl(url: string): string | undefined {+ try {+ const last = new URL(url, 'https://macro.invalid').pathname+ .split('/')+ .filter(Boolean)+ .at(-1);+ if (!last) return undefined;+ const decoded = decodeURIComponent(last);+ return decoded.includes('.') ? decoded : undefined;+ } catch {+ return undefined;+ }+}