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(databases): keep cell previews mounted across unchanged polls (#7765)

teoffa53ea71263
diff --git a/apps/web/src/features/crm/queries/pipeline-data.test.tsx b/apps/web/src/features/crm/queries/pipeline-data.test.tsx
index e750be357f..b965e0b5d3 100644
--- a/apps/web/src/features/crm/queries/pipeline-data.test.tsx
+++ b/apps/web/src/features/crm/queries/pipeline-data.test.tsx
@@ -160,6 +160,16 @@ it('reads all pages through pipeline identity and supplies primary references to
expect(host.data().rows.snapshot()?.rows[1].cells.company).toBe('company2');
});
+it('keeps column identity when a background refresh returns the same schema', async () => {
+ const host = setup();
+ await waitFor(() =>
+ expect(host.data().rows.snapshot()?.rows).toHaveLength(2)
+ );
+ const columns = host.data().rows.columns();
+ expect((await host.data().rows.refresh('refresh')).isOk()).toBe(true);
+ expect(host.data().rows.columns()).toBe(columns);
+});
+
it('writes references through the pipeline operation endpoint and returns the inserted row identity', async () => {
const host = setup();
await waitFor(() => expect(host.data().rows.snapshot()).toBeDefined());
diff --git a/apps/web/src/features/database/components/grid-cell.preview.test.tsx b/apps/web/src/features/database/components/grid-cell.preview.test.tsx
new file mode 100644
index 0000000000..c05b2f868b
--- /dev/null
+++ b/apps/web/src/features/database/components/grid-cell.preview.test.tsx
@@ -0,0 +1,101 @@
+import { createLivePreviewBatcher } from '@queries/preview/live-batcher';
+import { cleanup, render, screen } from '@solidjs/testing-library';
+import { createSignal, For, onCleanup } from 'solid-js';
+import { afterEach, expect, it, vi } from 'vitest';
+import type { DatabaseViewColumn } from '../core/database-view';
+import { GridCell } from './grid-cell';
+
+afterEach(() => {
+ cleanup();
+ vi.useRealTimers();
+});
+
+it('retains a company preview when refreshed row objects still reference the same company', () => {
+ const column: DatabaseViewColumn = {
+ id: 'company',
+ name: 'Company',
+ dataType: 'ENTITY',
+ specificEntityType: 'COMPANY',
+ options: [],
+ isMultiSelect: false,
+ writable: true,
+ };
+ const [row, setRow] = createSignal({ company: 'company-1' });
+ let mounts = 0;
+ let disposals = 0;
+ function Preview(props: { id: string }) {
+ mounts++;
+ onCleanup(() => disposals++);
+ return <span data-testid="company-preview">{props.id}</span>;
+ }
+ render(() => (
+ <GridCell
+ column={column}
+ value={row().company}
+ canEdit
+ onWrite={vi.fn(async () => true)}
+ onAddOption={vi.fn(async () => true)}
+ renderMentionValue={(id) => <Preview id={id} />}
+ />
+ ));
+ const original = screen.getByTestId('company-preview');
+ expect(mounts).toBe(1);
+ setRow({ company: 'company-1' });
+ expect(screen.getByTestId('company-preview')).toBe(original);
+ expect(mounts).toBe(1);
+ expect(disposals).toBe(0);
+ setRow({ company: 'company-2' });
+ expect(screen.getByTestId('company-preview').textContent).toBe('company-2');
+});
+
+it('keeps multiple preview batches and duplicate references across row refreshes', () => {
+ vi.useFakeTimers();
+ const column: DatabaseViewColumn = {
+ id: 'company',
+ name: 'Company',
+ dataType: 'ENTITY',
+ specificEntityType: 'COMPANY',
+ options: [],
+ isMultiSelect: false,
+ writable: true,
+ };
+ const initial = Array.from({ length: 123 }, (_, index) => ({
+ company: `company-${index % 103}`,
+ }));
+ const [rows, setRows] = createSignal(initial);
+ const start = vi.fn((items: string[]) => ({
+ value: items,
+ dispose: vi.fn(),
+ }));
+ const batcher = createLivePreviewBatcher({ start });
+ let mounts = 0;
+ function Preview(props: { id: string }) {
+ mounts++;
+ const [batch, setBatch] = createSignal<string[]>();
+ const subscription = batcher.acquire(props.id, props.id, setBatch);
+ onCleanup(subscription.dispose);
+ return <span>{batch()?.includes(props.id) ? props.id : 'Loading...'}</span>;
+ }
+ render(() => (
+ <For each={initial}>
+ {(_, index) => (
+ <GridCell
+ column={column}
+ value={rows()[index()].company}
+ canEdit
+ onWrite={vi.fn(async () => true)}
+ onAddOption={vi.fn(async () => true)}
+ renderMentionValue={(id) => <Preview id={id} />}
+ />
+ )}
+ </For>
+ ));
+ vi.advanceTimersByTime(30);
+ expect(start.mock.calls.map(([items]) => items.length)).toEqual([50, 50, 3]);
+ for (let refresh = 0; refresh < 5; refresh++) {
+ setRows((previous) => previous.map((row) => ({ ...row })));
+ vi.advanceTimersByTime(30);
+ }
+ expect(start).toHaveBeenCalledTimes(3);
+ expect(mounts).toBe(123);
+});
diff --git a/apps/web/src/features/database/components/grid-cell.tsx b/apps/web/src/features/database/components/grid-cell.tsx
index 5e10a322ba..48a419c466 100644
--- a/apps/web/src/features/database/components/grid-cell.tsx
+++ b/apps/web/src/features/database/components/grid-cell.tsx
@@ -482,7 +482,9 @@ function TextCell(props: {
onBeginEdit: (seed?: string, event?: Event) => void;
onClearEntity: () => void;
}) {
- const formatted = () => formatCellValue(props.column, props.value);
+ // Refreshes rebuild row objects; only a changed value may rerun renderers and remount previews.
+ const value = createMemo(() => props.value);
+ const formatted = () => formatCellValue(props.column, value());
return (
<button
ref={props.ref}
@@ -490,7 +492,7 @@ function TextCell(props: {
class="flex min-h-9 w-full min-w-0 items-center rounded px-2.5 py-1.5 text-left text-[13px] leading-5 outline-none hover:bg-hover focus-visible:ring-2 focus-visible:ring-ink/50"
classList={{
'text-ink-muted': !props.editable,
- 'text-ink-placeholder': props.value === null && !props.mentionPreview,
+ 'text-ink-placeholder': value() === null && !props.mentionPreview,
'font-medium': props.column.dataType === 'STRING',
}}
aria-label={
@@ -553,9 +555,9 @@ function TextCell(props: {
<Switch
fallback={
(props.column.dataType === 'STRING' &&
- typeof props.value === 'string' &&
+ typeof value() === 'string' &&
props.renderTextValue
- ? props.renderTextValue(props.value)
+ ? props.renderTextValue(String(value()))
: formatted()) || (
<span class="opacity-40">{props.emptyLabel || '—'}</span>
)
@@ -567,16 +569,14 @@ function TextCell(props: {
<Match
when={
props.isEntity &&
- typeof props.value === 'string' &&
+ typeof value() === 'string' &&
props.renderMentionValue
? props.column.specificEntityType
: undefined
}
>
{(entityType) => (
- <>
- {props.renderMentionValue?.(String(props.value), entityType())}
- </>
+ <>{props.renderMentionValue?.(String(value()), entityType())}</>
)}
</Match>
</Switch>
diff --git a/apps/web/src/features/database/queries/api-source.ts b/apps/web/src/features/database/queries/api-source.ts
index b36db1b86b..713d9f32a0 100644
--- a/apps/web/src/features/database/queries/api-source.ts
+++ b/apps/web/src/features/database/queries/api-source.ts
@@ -67,6 +67,8 @@ export function createDatabaseApiSource(args: {
const table = useQuery(
() => ({
queryKey: [...key, 'schema'],
+ // Polls refetch the schema; stable columns keep cells from remounting previews.
+ reconcile: 'id',
queryFn: async () => {
const result = await api.readTable(tableId);
if (result.isErr()) throw result.error;
diff --git a/docs/AGENT_GUIDE/databases.md b/docs/AGENT_GUIDE/databases.md
index 0f759f4d33..596af669d3 100644
--- a/docs/AGENT_GUIDE/databases.md
+++ b/docs/AGENT_GUIDE/databases.md
@@ -96,6 +96,8 @@ keeps it available when a view filter excludes it. Cell edits and **Add column**
use pipeline authorization. Viewer grants hide editing controls. The CRM editor
fixture (`features/crm/browser-test/editor.html`) covers the real pipeline API
adapter and shared provider against local test responses.
+Pipelines poll every five seconds. A poll that returns unchanged data must not
+remount company previews or request them again.
## Properties and records