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(forms): size poll cards in messages to their content (#9313)
Wolf Mermelsteinfc604b7595e6
diff --git a/apps/web/AGENTS.md b/apps/web/AGENTS.mdindex f5471f919e..7ad149b213 100644--- a/apps/web/AGENTS.md+++ b/apps/web/AGENTS.md@@ -54,6 +54,12 @@ It uses the real records view with a local source and picker to exercise openingreplacement, cancellation, keyboard editing, and read-only references. Navigationadapter tests separately check file types, access failures, and split selection.+Poll cards in messages (the real `DocumentCard` around `FormCardView`) have a+backend-free desktop/phone regression: the card reserves its height from+`previewData.poll.optionCount` as a `min-height`, grows to wrapped text, and+never scrolls or clips inside:+`bunx playwright test --config src/lib/core/component/LexicalMarkdown/component/decorator/browser-test/playwright.config.ts poll-card.browser.e2e.ts`.+Pinch zoom on opened image files (Drive details and image splits) has abackend-free phone and tablet regression:`bunx playwright test --config src/features/block-image/browser-test/playwright.config.ts`.diff --git a/apps/web/src/features/block-form/core/poll-card-layout.test.ts b/apps/web/src/features/block-form/core/poll-card-layout.test.tsindex dfc41c2277..15cf8150b4 100644--- a/apps/web/src/features/block-form/core/poll-card-layout.test.ts+++ b/apps/web/src/features/block-form/core/poll-card-layout.test.ts@@ -1,10 +1,10 @@import { expect, it } from 'vitest';import { pollCardHeight } from './poll-card-layout';-it('reserves count-dependent space and bounds large polls', () => {- expect(pollCardHeight({ poll: { optionCount: 2 } })).toBe('18.25rem');- expect(pollCardHeight({ poll: { optionCount: 4 } })).toBe('24.75rem');- expect(pollCardHeight({ poll: { optionCount: 20 } })).toBe('40rem');+it('reserves count-dependent space', () => {+ expect(pollCardHeight({ poll: { optionCount: 2 } })).toBe('17rem');+ expect(pollCardHeight({ poll: { optionCount: 4 } })).toBe('23.5rem');+ expect(pollCardHeight({ poll: { optionCount: 20 } })).toBe('75.5rem');});it.each([diff --git a/apps/web/src/features/block-form/core/poll-card-layout.ts b/apps/web/src/features/block-form/core/poll-card-layout.tsindex cb9d137753..4735f52352 100644--- a/apps/web/src/features/block-form/core/poll-card-layout.ts+++ b/apps/web/src/features/block-form/core/poll-card-layout.ts@@ -16,7 +16,7 @@ export function pollCardHeight(previewData: unknown): string | undefined {count > 20)return;- // Fixed header/footer space plus 44px choices and 8px gaps at the default- // font size. Large polls scroll inside their card instead of moving chat.- return `${Math.min(11.75 + count * 3.25, 40)}rem`;+ // The card with a one-line question at the default font size: header and+ // footer plus 44px choices and 8px gaps. Wrapped text grows the card.+ return `${10.5 + count * 3.25}rem`;}diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/DocumentCard.test.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/DocumentCard.test.tsxindex 3587327f44..3d085a2b0a 100644--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/DocumentCard.test.tsx+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/DocumentCard.test.tsx@@ -233,15 +233,35 @@ it('reserves a poll’s height across suspended metadata loading', async () => {const placeholder = await screen.findByRole('status');expect(placeholder.closest<HTMLElement>('[data-slot="card"]')?.style.height- ).toBe('21.5rem');+ ).toBe('20.25rem');release?.();const content = await screen.findByText('form-1');- expect(content.closest<HTMLElement>('.rounded-xl')?.style.height).toBe(- '21.5rem'- );+ // The loaded card keeps the reservation as a floor and grows to its content.+ const card = content.closest<HTMLElement>('.rounded-xl');+ expect(card?.style.minHeight).toBe('20.25rem');+ expect(card?.style.height).toBe('auto');expect(screen.queryByRole('status')).toBeNull();});+it('reserves no poll height once the form turns out to be unavailable', async () => {+ mocks.access = 'no_access';+ render(() => (+ <MarkdownHostContext.Provider value="channel">+ <DocumentCard+ key="poll-node"+ documentId="form-1"+ documentName="Lunch?"+ blockName="form"+ blockParams={{}}+ previewData={{ poll: { optionCount: 3 } }}+ theme={{}}+ />+ </MarkdownHostContext.Provider>+ ));+ const message = await screen.findByText('You don’t have access to this poll');+ expect(message.closest<HTMLElement>('.rounded-xl')?.style.minHeight).toBe('');+});+it.each(['code', 'canvas', 'pdf'] as const)('mounts a %s preview inside a standalone markdown document',async (blockName) => {diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/DocumentCard.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/DocumentCard.tsxindex 771c88d08c..78ce7b5b8c 100644--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/DocumentCard.tsx+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/DocumentCard.tsx@@ -432,11 +432,20 @@ function DocumentCardInner(props: DocumentCardDecoratorProps) {// A form fits its content (a poll is a few rows); other previews keep a// resizable box.const resizable = () => isPreviewable() && props.blockName !== 'form';- const pollHeight = () =>- props.blockName === 'form' ? pollCardHeight(props.previewData) : undefined;- const boundedPreview = () => resizable() || Boolean(pollHeight());- const cardNoun = () =>- pollHeight() ? 'poll' : props.blockName === 'form' ? 'form' : 'item';+ const isPoll = () =>+ props.blockName === 'form' && Boolean(pollCardHeight(props.previewData));+ // A poll reserves its space before its form loads, then grows to fit. A+ // form the viewer can't open renders no body, so it reserves nothing.+ const pollMinHeight = () => {+ if (!isPoll()) return;+ const i = item();+ if (i && !i.loading && !isAccessiblePreviewItem(i)) return;+ return pollCardHeight(props.previewData);+ };+ const cardNoun = () => {+ if (isPoll()) return 'poll';+ return props.blockName === 'form' ? 'form' : 'item';+ };const [previewBoxHeight, setPreviewBoxHeight] = createSignal(stringifyPreviewBox(props.previewBox || DEFAULT_PREVIEW_BOX)[1]@@ -623,7 +632,8 @@ function DocumentCardInner(props: DocumentCardDecoratorProps) {resizable() && 'resize-y shrink-0 min-h-80')}style={{- height: pollHeight() ?? (resizable() ? previewBoxHeight() : 'auto'),+ height: resizable() ? previewBoxHeight() : 'auto',+ 'min-height': pollMinHeight(),}}onClick={(e) => {if (channelMessageId()) return;@@ -675,7 +685,7 @@ function DocumentCardInner(props: DocumentCardDecoratorProps) {data-lexical-interactiveclass={cn('mx-3 mt-2 mb-3 p-0',- boundedPreview() && 'flex min-h-0 flex-1'+ resizable() && 'flex min-h-0 flex-1')}data-document-card-controls>@@ -684,13 +694,13 @@ function DocumentCardInner(props: DocumentCardDecoratorProps) {offset={1}class={cn('w-full overflow-hidden rounded-lg',- boundedPreview() && 'min-h-0 flex-1'+ resizable() && 'min-h-0 flex-1')}><divclass={cn('relative min-w-0',- boundedPreview() && 'min-h-0 flex-1 overflow-y-auto'+ resizable() && 'min-h-0 flex-1 overflow-y-auto')}><Dynamic component={previewComponent()} {...props} />diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/browser-test/poll-card.browser.e2e.ts b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/browser-test/poll-card.browser.e2e.tsnew file mode 100644index 0000000000..0f10517cfe--- /dev/null+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/browser-test/poll-card.browser.e2e.ts@@ -0,0 +1,58 @@+import { expect, test } from '@playwright/test';++const fixture =+ '/src/lib/core/component/LexicalMarkdown/component/decorator/browser-test/poll-card.html';++for (const viewport of [+ { name: 'desktop', width: 1280, height: 800 },+ { name: 'phone', width: 390, height: 844 },+]) {+ for (const { poll, wraps } of [+ { poll: 'Two options', wraps: false },+ { poll: 'Long question', wraps: true },+ { poll: 'Many options', wraps: false },+ ]) {+ test(`${poll} poll card fits its content without moving on load on ${viewport.name}`, async ({+ page,+ }) => {+ await page.route('https://**', (route) => route.abort());+ await page.setViewportSize(viewport);+ await page.goto(fixture);+ const section = page.getByRole('region', { name: poll, exact: true });+ const card = section.locator('[data-slot="card"]').first();+ await expect(card).toBeVisible({ timeout: 30_000 });+ const reserved = (await card.boundingBox())!.height;++ await section.getByRole('button', { name: `Load ${poll}` }).click();+ await expect(section.getByText('Responses')).toBeVisible();+ const loaded = (await card.boundingBox())!.height;+ // One-line polls get exactly their space up front; wrapped text grows them.+ if (wraps) expect(loaded).toBeGreaterThan(reserved);+ else expect(loaded).toBe(reserved);++ // Nothing inside the card scrolls or is clipped: the "Poll" row and the+ // votes footer both sit within the card.+ const scrollers = await card.evaluate((element) =>+ [element, ...element.querySelectorAll('*')]+ // Screen-reader-only text is a 1px clip by design.+ .filter((node) => !node.classList.contains('sr-only'))+ .filter((node) => node.scrollHeight > node.clientHeight + 1)+ .filter((node) => getComputedStyle(node).overflowY !== 'visible')+ .map((node) => node.className)+ );+ expect(scrollers).toEqual([]);+ const box = (await card.boundingBox())!;+ for (const part of [+ section.getByText('Poll', { exact: true }),+ section.getByText(/votes? · one vote each/),+ section.getByText('Responses'),+ ]) {+ const partBox = (await part.boundingBox())!;+ expect(partBox.y).toBeGreaterThanOrEqual(box.y);+ expect(partBox.y + partBox.height).toBeLessThanOrEqual(+ box.y + box.height+ );+ }+ });+ }+}diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/browser-test/poll-card.html b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/browser-test/poll-card.htmlnew file mode 100644index 0000000000..25b7165461--- /dev/null+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/browser-test/poll-card.html@@ -0,0 +1,5 @@+<!doctype html>+<html lang="en">+ <head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Poll card height</title></head>+ <body><div id="root"></div><script type="module" src="./poll-card.tsx"></script></body>+</html>diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/browser-test/poll-card.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/browser-test/poll-card.tsxnew file mode 100644index 0000000000..83c21c1a14--- /dev/null+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/browser-test/poll-card.tsx@@ -0,0 +1,217 @@+import '@app/index.css';+import { ListSkeleton } from '@app/components/view-shell/ListSkeleton';+import { FormProvider } from '@app/features/block-form/context/form-context';+import type { FormDetail } from '@app/features/block-form/core/form-model';+import { createMockFormContext } from '@app/features/block-form/tests/mock-context';+import { FormCardView } from '@app/features/block-form/views/form-card-view';+import { AnalyticsContextProvider } from '@app/lib/analytics/analytics-context';+import { PosthogProvider } from '@app/lib/analytics/posthog';+import { UserContextProvider } from '@core/context/user';+import { authKeys } from '@queries/auth/keys';+import { queryClient } from '@queries/client';+import { previewKeys } from '@queries/preview/keys';+import type { PreviewItem } from '@queries/preview/types';+import { MemoryRouter, Route } from '@solidjs/router';+import { QueryClientProvider } from '@tanstack/solid-query';+import { Button } from '@ui';+import { createSignal, For, Show } from 'solid-js';+import { render } from 'solid-js/web';+import { channelTheme } from '../../../theme';+import { StaticMarkdownContext } from '../../core/StaticMarkdown';+import { DocumentCard } from '../DocumentCard';++queryClient.setQueryData(authKeys.userInfo.queryKey, {+ authenticated: true,+ email: '[email protected]',+});++const polls = [+ {+ label: 'Two options',+ question: 'Lunch?',+ options: ['Tacos', 'Pho'],+ },+ {+ label: 'Long question',+ question:+ 'Should we hide the support channels from the sidebar for everyone who is not on the support rotation this quarter, and keep them reachable from search?',+ options: [+ 'Yes, hide them for everyone outside the rotation',+ 'No, keep them visible',+ ],+ },+ {+ label: 'Many options',+ question: 'Which day works for the offsite?',+ options: [+ 'Monday',+ 'Tuesday',+ 'Wednesday',+ 'Thursday',+ 'Friday',+ 'Saturday',+ 'Sunday',+ 'Next Monday',+ ],+ },+];++function pollDetail(+ id: string,+ question: string,+ options: string[]+): FormDetail {+ return {+ form: {+ id,+ name: question,+ description: '',+ ownerId: 'macro|[email protected]',+ databaseId: 'database-1',+ tableId: 'table-1',+ audience: 'members',+ status: 'open',+ closesAt: null,+ tallyVisible: true,+ confirmationMessage: '',+ submittedColumnId: null,+ respondentColumnId: null,+ branding: { logoFileId: null, coverFileId: null, accentColor: null },+ },+ layout: {+ sections: [+ {+ id: 'section',+ title: '',+ description: '',+ kind: 'questions',+ gateRules: null,+ gateMessage: '',+ bookingTarget: null,+ questions: [+ {+ id: 'question',+ columnId: 'answer',+ helpText: '',+ required: true,+ widget: 'choice',+ },+ ],+ },+ ],+ },+ columns: [+ {+ id: 'answer',+ name: 'Answer',+ kind: { type: 'select', multi: false },+ options: options.map((label, index) => ({+ id: `option-${index}`,+ label,+ color: null,+ })),+ },+ ],+ access: 'edit',+ tableGone: false,+ };+}++function PollExample(props: {+ index: number;+ label: string;+ question: string;+ options: string[];+}) {+ const id = `01a19a29-0000-7000-8000-${String(props.index).padStart(12, '0')}`;+ const detail = pollDetail(id, props.question, props.options);+ queryClient.setQueryData(previewKeys.item(id).queryKey, {+ id,+ type: 'form',+ name: props.question,+ rawName: props.question,+ loading: false,+ access: 'access',+ } satisfies PreviewItem);+ const base = createMockFormContext({ detail });+ const { context } = createMockFormContext({+ detail,+ overrides: {+ responses: {+ ...base.context.responses,+ createTally: () => ({+ value: () => [+ {+ questionId: 'question',+ responses: 3,+ buckets: [{ kind: 'option', optionId: 'option-0', count: 3 }],+ },+ ],+ failure: () => undefined,+ }),+ },+ },+ });+ // The form's detail arrives after its card mounts, as in a channel.+ const [loaded, setLoaded] = createSignal(false);+ const Body = () => (+ <FormProvider value={context}>+ <Show+ when={loaded()}+ fallback={<ListSkeleton.Bar class="h-24 w-full rounded-xl" />}+ >+ <FormCardView+ detail={detail}+ refetch={async () => true}+ narrow={false}+ onOpen={() => {}}+ onOpenResponses={() => {}}+ />+ </Show>+ </FormProvider>+ );+ return (+ <section aria-label={props.label} class="max-w-xl">+ <Button onClick={() => setLoaded(true)}>Load {props.label}</Button>+ <DocumentCard+ key={id}+ documentId={id}+ documentName={props.question}+ blockName="form"+ blockParams={{}}+ previewData={{ poll: { optionCount: props.options.length } }}+ previewComponent={Body}+ theme={channelTheme}+ />+ </section>+ );+}++function Fixture() {+ return (+ <main class="h-screen space-y-6 overflow-y-auto bg-page p-4 text-ink">+ <For each={polls}>+ {(poll, index) => <PollExample index={index() + 1} {...poll} />}+ </For>+ </main>+ );+}++render(+ () => (+ <AnalyticsContextProvider>+ <PosthogProvider>+ <QueryClientProvider client={queryClient}>+ <UserContextProvider>+ <StaticMarkdownContext theme={channelTheme}>+ <MemoryRouter>+ <Route path="*" component={Fixture} />+ </MemoryRouter>+ </StaticMarkdownContext>+ </UserContextProvider>+ </QueryClientProvider>+ </PosthogProvider>+ </AnalyticsContextProvider>+ ),+ document.getElementById('root')!+);diff --git a/docs/agent-guide/forms.md b/docs/agent-guide/forms.mdindex 2d5c9399fc..c0a6f6f89b 100644--- a/docs/agent-guide/forms.md+++ b/docs/agent-guide/forms.md@@ -219,12 +219,13 @@ choice; removing a choice focuses its replacement. Duplicate choice names(ignore case and surrounding spaces) show an inline error and disable Postuntil corrected. Poll cards omit permission badges and display the questiononce, in the card header. Newly posted poll cards-store their option count in Lexical preview metadata to reserve their height-before loading. Choices have fixed-height rows; large polls and expanded-results scroll inside the card. Older cards without that metadata keep their-content-sized layout. A viewer without access to the card's item sees "You-don’t have access to this poll" (or form/item), and a deleted item reads "This-poll was deleted", never an empty card.+store their option count in Lexical preview metadata to reserve a minimum+height before loading, which matches a one-line poll. The card then grows to+its content (wrapped text, many options, expanded results); nothing scrolls or+clips inside it. Older cards without that metadata size to their content. A+viewer without access to the card's item sees "You don’t have access to this+poll" (or form/item), and a deleted item reads "This poll was deleted", never+an empty card.## Reading responses as an agent