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(tasks): reuse cached project identities without resetting scroll (#9449)

dev-rb3a447e0ce113
diff --git a/apps/web/AGENTS.md b/apps/web/AGENTS.md
index 794ab30d58..5c31496653 100644
--- a/apps/web/AGENTS.md
+++ b/apps/web/AGENTS.md
@@ -311,6 +311,10 @@ key, and projects sort by name with No Project last. Data a grouped list shows
about its groups (labels, order, membership) is computed on the server and
mirrored by the cache's local grouping projection; never add a side cache in
feature code to cover a remount.
+Project identity chips use cache-first reads and the shared `GraphqlUser.initiative`
+entity resolver to reuse complete authorized records from project lists or details.
+Keep cold row metadata reads non-suspending so virtual scrolling never detaches
+its list; permission revalidation remains independent of row mounts.
Resolve server date-group keys through the shared `DATE_GROUP_BUCKETS` metadata
in `lib/queries/soup/grouped/api.ts` for labels and display order; cached Mail
diff --git a/apps/web/docs/graphql-normalized-cache-plan.md b/apps/web/docs/graphql-normalized-cache-plan.md
index 0bdbfa4275..b68e1ce6ba 100644
--- a/apps/web/docs/graphql-normalized-cache-plan.md
+++ b/apps/web/docs/graphql-normalized-cache-plan.md
@@ -783,8 +783,13 @@ unrelated fields.
### Adoption and mutation coverage
Mounted project details, project identity chips, and agent-session mentions use
-this live path as well. Mention lookups share stable batches: adding another
-visible item does not clear an existing item's data or restart its request.
+this live path as well. Project identity reads are cache-first; the shared
+`GraphqlUser.initiative` entity resolver lets them reuse complete authorized
+project records loaded by Soup or detail queries, without fetching on row remount.
+Missing fields still require an authorized network read. Detail reads retain
+cache-and-network behavior, and identity reads retain explicit permission
+revalidation. Mention lookups share stable batches: adding another visible item
+does not clear an existing item's data or restart its request.
Project creation links the complete server-normalized record to its detail query,
including when the user root is not cached yet. Async creation stops publishing
after viewer changes, cache replacement, or storage reset.
diff --git a/apps/web/src/features/entity/README.md b/apps/web/src/features/entity/README.md
index abebe3a533..fa9db09f8d 100644
--- a/apps/web/src/features/entity/README.md
+++ b/apps/web/src/features/entity/README.md
@@ -40,6 +40,8 @@ even when a sent-only email has no Unarchive action.
`ProjectBreadCrumb.collapsed` keeps a keyboard-accessible, borderless ghost folder
button with its link color and a circular icon-only target. Its hover card shows
the folder heading and full path on separate rows.
+Pending folder previews keep the task list mounted and its scroll position intact;
+the label retains its small loading bar until the folder path is ready.
The list folder glyph is 16px on desktop and 20px on phones, matching neighboring
property icons while keeping its existing pill and touch target.
Task grids use their existing measured overflow controller to collapse folder
diff --git a/apps/web/src/features/entity/components/ProjectBreadCrumb.test.ts b/apps/web/src/features/entity/components/ProjectBreadCrumb.test.ts
new file mode 100644
index 0000000000..3086a52c2f
--- /dev/null
+++ b/apps/web/src/features/entity/components/ProjectBreadCrumb.test.ts
@@ -0,0 +1,153 @@
+import type { ProjectPreviewData } from '@service-storage/generated/schemas';
+import { cleanup, render, waitFor } from '@solidjs/testing-library';
+import {
+ QueryClient,
+ QueryClientProvider,
+ useQuery,
+} from '@tanstack/solid-query';
+import { type Accessor, createComponent, Suspense } from 'solid-js';
+import { insert } from 'solid-js/web';
+import { afterEach, expect, it, vi } from 'vitest';
+import { ProjectBreadCrumb } from './ProjectBreadCrumb';
+
+const request = vi.hoisted(() => vi.fn<() => Promise<ProjectPreviewData>>());
+
+vi.mock('@queries/storage/project-preview', () => ({
+ useProjectPreviewQuery: (projectId: Accessor<string>) =>
+ useQuery(() => ({
+ queryKey: ['project-preview', projectId()],
+ queryFn: request,
+ retry: false,
+ })),
+}));
+
+afterEach(() => {
+ cleanup();
+ request.mockReset();
+});
+
+it('keeps the list mounted and scrolled while a folder preview resolves', async () => {
+ const response = Promise.withResolvers<ProjectPreviewData>();
+ request.mockReturnValue(response.promise);
+ const client = new QueryClient({
+ defaultOptions: { queries: { retry: false } },
+ });
+ const onClick = vi.fn();
+ const listItem = document.createElement('div');
+ listItem.textContent = 'Existing list row';
+ const fallback = document.createElement('div');
+ fallback.textContent = 'Parent fallback';
+
+ const view = render(() =>
+ createComponent(QueryClientProvider, {
+ client,
+ get children() {
+ return createComponent(Suspense, {
+ fallback,
+ get children() {
+ const viewport = document.createElement('div');
+ viewport.append(listItem);
+ insert(
+ viewport,
+ createComponent(ProjectBreadCrumb, {
+ entity: {
+ type: 'project',
+ id: 'row',
+ name: 'Row',
+ ownerId: 'owner',
+ projectId: 'folder',
+ },
+ onClick,
+ })
+ );
+ return viewport;
+ },
+ });
+ },
+ })
+ );
+
+ const viewport = listItem.parentElement!;
+ viewport.scrollTop = 128;
+ expect(view.container.contains(listItem)).toBe(true);
+ expect(view.container.contains(fallback)).toBe(false);
+ expect(viewport.querySelector('.skeleton-shimmer')).not.toBeNull();
+ expect(viewport.scrollTop).toBe(128);
+ expect(request).toHaveBeenCalledOnce();
+
+ response.resolve({
+ id: 'folder',
+ name: 'Folder',
+ owner: 'owner',
+ path: ['Parent', 'Folder'],
+ });
+ await waitFor(() =>
+ expect(viewport.querySelector('button')?.getAttribute('aria-label')).toBe(
+ 'Parent/Folder'
+ )
+ );
+ expect(view.container.contains(fallback)).toBe(false);
+ expect(listItem.parentElement).toBe(viewport);
+ expect(viewport.scrollTop).toBe(128);
+ view.getByRole('button', { name: 'Parent/Folder' }).click();
+ expect(onClick).toHaveBeenCalledWith(
+ {
+ type: 'project',
+ id: 'folder',
+ name: 'Folder',
+ ownerId: 'owner',
+ updatedAt: undefined,
+ },
+ expect.any(MouseEvent)
+ );
+ client.clear();
+});
+
+it('keeps a failed preview non-interactive without suspending the list', async () => {
+ const response = Promise.withResolvers<ProjectPreviewData>();
+ request.mockReturnValue(response.promise);
+ const client = new QueryClient({
+ defaultOptions: { queries: { retry: false } },
+ });
+ const onClick = vi.fn();
+ const fallback = document.createElement('div');
+ fallback.textContent = 'Parent fallback';
+
+ const view = render(() =>
+ createComponent(QueryClientProvider, {
+ client,
+ get children() {
+ return createComponent(Suspense, {
+ fallback,
+ get children() {
+ return createComponent(ProjectBreadCrumb, {
+ entity: {
+ type: 'project',
+ id: 'row',
+ name: 'Row',
+ ownerId: 'owner',
+ projectId: 'folder',
+ },
+ onClick,
+ });
+ },
+ });
+ },
+ })
+ );
+
+ expect(request).toHaveBeenCalledOnce();
+ response.reject(new Error('Preview unavailable'));
+ await waitFor(() =>
+ expect(
+ view.container.querySelector('button')?.getAttribute('aria-disabled')
+ ).toBe('true')
+ );
+ await waitFor(() =>
+ expect(view.container.querySelector('.skeleton-shimmer')).toBeNull()
+ );
+ expect(view.container.contains(fallback)).toBe(false);
+ view.getByRole('button').click();
+ expect(onClick).not.toHaveBeenCalled();
+ client.clear();
+});
diff --git a/apps/web/src/features/entity/components/ProjectBreadCrumb.tsx b/apps/web/src/features/entity/components/ProjectBreadCrumb.tsx
index 156134866c..ae3a0a2912 100644
--- a/apps/web/src/features/entity/components/ProjectBreadCrumb.tsx
+++ b/apps/web/src/features/entity/components/ProjectBreadCrumb.tsx
@@ -1,9 +1,10 @@
import { ListSkeleton } from '@app/components/view-shell/ListSkeleton';
import { t } from '@app/lib/i18n';
import FolderIcon from '@icon/system/regular/folder-simple.svg';
+import { queryReadyGate } from '@queries/gate';
import { useProjectPreviewQuery } from '@queries/storage/project-preview';
import { buttonClasses, cn, HoverCard } from '@ui';
-import { Show, Suspense } from 'solid-js';
+import { Show } from 'solid-js';
import type { ProjectContainedEntity, ProjectEntity } from '../types/entity';
import { truncatedPath } from '../utils/path';
@@ -16,11 +17,13 @@ export function ProjectBreadCrumb(props: {
}) {
const projectQuery = useProjectPreviewQuery(() => props.entity.projectId);
const fullPath = () =>
- projectQuery.data?.path.join('/') || projectQuery.data?.name;
+ queryReadyGate(projectQuery)
+ ? projectQuery.data.path.join('/') || projectQuery.data.name
+ : undefined;
const handleClick = (e: MouseEvent) => {
e.preventDefault();
- if (!projectQuery.isSuccess) return;
+ if (!projectQuery.isSuccess || !queryReadyGate(projectQuery)) return;
e.stopPropagation();
const data = projectQuery.data;
@@ -64,15 +67,20 @@ export function ProjectBreadCrumb(props: {
>
<FolderIcon class="size-4 shrink-0 mobile:size-5" />
<Show when={!props.collapsed}>
- <Suspense fallback={<ListSkeleton.Bar class="h-2 w-10" />}>
- <Show when={projectQuery.data}>
- {(data) => (
- <div class="truncate">
- {truncatedPath(data().path, MAX_PATH_LENGTH)}
- </div>
- )}
- </Show>
- </Suspense>
+ <Show
+ when={queryReadyGate(projectQuery) ? projectQuery.data : undefined}
+ fallback={
+ projectQuery.isPending ? (
+ <ListSkeleton.Bar class="h-2 w-10" />
+ ) : undefined
+ }
+ >
+ {(data) => (
+ <div class="truncate">
+ {truncatedPath(data().path, MAX_PATH_LENGTH)}
+ </div>
+ )}
+ </Show>
</Show>
</HoverCard>
);
diff --git a/apps/web/src/features/projects/projects.test.tsx b/apps/web/src/features/projects/projects.test.tsx
index 10c003e997..7fcd189d4b 100644
--- a/apps/web/src/features/projects/projects.test.tsx
+++ b/apps/web/src/features/projects/projects.test.tsx
@@ -2,6 +2,7 @@ import { cleanup, render } from '@solidjs/testing-library';
import { QueryClient } from '@tanstack/solid-query';
import {
type Client,
+ cacheExchange,
createClient,
type Exchange,
getOperationName,
@@ -12,8 +13,9 @@ import {
createSignal,
type ParentProps,
Show,
+ Suspense,
} from 'solid-js';
-import { afterEach, expect, it, vi } from 'vitest';
+import { afterEach, expect, it, onTestFinished, vi } from 'vitest';
import { filter, fromPromise, mergeMap, pipe } from 'wonka';
const mocks = vi.hoisted(() => ({
@@ -124,21 +126,27 @@ function setupGraphql() {
completedTaskCount: 0,
sharePermission: { id: 'share', owner: 'viewer', linkShare: 'DISABLED' },
};
- mocks.soup.mockImplementation(async (operation) => ({
- operation,
- stale: false,
- hasNext: false,
- data: {
- user: {
- id: 'viewer',
- ...(['Initiative', 'InitiativeIdentity'].includes(
- getOperationName(operation.query) ?? ''
- )
- ? { initiative }
- : { soup: { nextCursor: 'next', items: [initiative] } }),
+ mocks.soup.mockImplementation(async (operation) => {
+ const requestedProject =
+ operation.variables?.initiativeId === 'other-project'
+ ? { ...initiative, id: 'other-project', displayName: 'Another project' }
+ : initiative;
+ return {
+ operation,
+ stale: false,
+ hasNext: false,
+ data: {
+ user: {
+ id: 'viewer',
+ ...(['Initiative', 'InitiativeIdentity'].includes(
+ getOperationName(operation.query) ?? ''
+ )
+ ? { initiative: requestedProject }
+ : { soup: { nextCursor: 'next', items: [initiative] } }),
+ },
},
- },
- }));
+ };
+ });
const exchange: Exchange = () => (operations) =>
pipe(
operations,
@@ -149,6 +157,7 @@ function setupGraphql() {
url: 'http://test.invalid/graphql',
exchanges: [exchange],
});
+ return exchange;
}
const callsFor = (name: string) =>
mocks.soup.mock.calls.filter(([op]) => getOperationName(op.query) === name);
@@ -293,6 +302,46 @@ it('reads chip identity without the fields that check every task', async () => {
expect(selection).not.toContain(field);
});
+it('reuses cached chip identities when virtual rows remount but still fetches misses', async () => {
+ const exchange = setupGraphql();
+ const client = createClient({
+ url: 'http://test.invalid/graphql',
+ exchanges: [cacheExchange, exchange],
+ });
+ const mount = (id: string) =>
+ createRoot((dispose) => {
+ onTestFinished(dispose);
+ return {
+ dispose,
+ query: createProjectIdentityQuery(
+ () => client,
+ () => 'viewer',
+ () => id
+ ),
+ };
+ });
+
+ const first = mount('launch');
+ await vi.waitFor(() => expect(first.query.data?.name).toBe('Launch'));
+ first.dispose();
+ expect(callsFor('InitiativeIdentity')).toHaveLength(1);
+
+ const remounted = mount('launch');
+ expect(remounted.query.data?.name).toBe('Launch');
+ remounted.dispose();
+ expect(callsFor('InitiativeIdentity')).toHaveLength(1);
+
+ const missing = mount('other-project');
+ await vi.waitFor(() =>
+ expect(missing.query.data).toMatchObject({
+ id: 'other-project',
+ name: 'Another project',
+ })
+ );
+ missing.dispose();
+ expect(callsFor('InitiativeIdentity')).toHaveLength(2);
+});
+
function controlledClient() {
const requests: {
operation: Operation;
@@ -343,6 +392,41 @@ function controlledClient() {
};
}
+it('keeps the list mounted while a cold identity read settles', async () => {
+ setupGraphql();
+ const data = (
+ await mocks.soup({
+ query: (
+ await import('@service-storage/graphql/generated/graphql')
+ ).InitiativeIdentityDocument,
+ })
+ ).data;
+ const { client, requests } = controlledClient();
+ function Row() {
+ const query = createProjectIdentityQuery(
+ () => client,
+ () => 'viewer',
+ () => 'launch'
+ );
+ return <span>{query.data?.name ?? 'Loading'}</span>;
+ }
+ const view = render(() => (
+ <Suspense fallback={<span>Suspended</span>}>
+ <div data-testid="scroller">
+ <Row />
+ </div>
+ </Suspense>
+ ));
+ const scroller = view.getByTestId('scroller');
+ scroller.scrollTop = 480;
+ expect(view.queryByText('Suspended')).toBeNull();
+ requests[0].next(data);
+ expect(scroller.textContent).toBe('Launch');
+ expect(view.getByTestId('scroller')).toBe(scroller);
+ expect(scroller.scrollTop).toBe(480);
+ expect(view.queryByText('Suspended')).toBeNull();
+});
+
it('keeps permission denials latched across cache hits and hides disabled detail identities', async () => {
setupGraphql();
const data = (
diff --git a/apps/web/src/features/projects/queries/project-identity.ts b/apps/web/src/features/projects/queries/project-identity.ts
index 2ed1f7924f..6aceb9e995 100644
--- a/apps/web/src/features/projects/queries/project-identity.ts
+++ b/apps/web/src/features/projects/queries/project-identity.ts
@@ -14,7 +14,12 @@ import {
mapInitiativeDetail,
mapInitiativeIdentity,
} from '@service-storage/initiative';
-import { type Client, type DocumentInput, stringifyDocument } from '@urql/core';
+import {
+ type Client,
+ type DocumentInput,
+ type RequestPolicy,
+ stringifyDocument,
+} from '@urql/core';
import { type Accessor, createMemo } from 'solid-js';
import type { ProjectIdentity } from '../core/project';
import { toProjectDetail } from './project-model';
@@ -78,7 +83,8 @@ function createAuthorizedProjectQuery<
client: () => Client,
userId: Accessor<string | undefined>,
projectId: Accessor<string>,
- enabled: Accessor<boolean>
+ enabled: Accessor<boolean>,
+ requestPolicy: RequestPolicy = 'cache-and-network'
) {
const active = () => enabled() && Boolean(userId() && projectId());
const authorization = createQueryAuthorization(() =>
@@ -89,7 +95,7 @@ function createAuthorizedProjectQuery<
() => (active() ? { initiativeId: projectId() } : undefined),
() => ({
client: client(),
- requestPolicy: 'cache-and-network',
+ requestPolicy,
keepPreviousData: false,
onResult: authorization.onResult,
select: (data) => ({ viewerId: data.user.id, value: select(data) }),
@@ -171,7 +177,8 @@ export function createProjectIdentityQuery(
client,
userId,
projectId,
- enabled
+ enabled,
+ 'cache-first'
);
}
diff --git a/apps/web/src/lib/service-clients/service-storage/graphql-soup.ts b/apps/web/src/lib/service-clients/service-storage/graphql-soup.ts
index 3f222988aa..3cd32a2169 100644
--- a/apps/web/src/lib/service-clients/service-storage/graphql-soup.ts
+++ b/apps/web/src/lib/service-clients/service-storage/graphql-soup.ts
@@ -848,6 +848,9 @@ export function getGraphqlSoupClient(): Client {
'input',
'threadId',
]),
+ initiative: entityFromArgument('GraphqlSoupInitiative', [
+ 'initiativeId',
+ ]),
},
},
// Session identity witness: the viewer id present on every soup
diff --git a/docs/agent-guide/tasks.md b/docs/agent-guide/tasks.md
index dcfe011ce3..46cab63423 100644
--- a/docs/agent-guide/tasks.md
+++ b/docs/agent-guide/tasks.md
@@ -608,6 +608,14 @@ also usable. An initial cache miss still shows failure; HTTP and GraphQL errors
remain visible even with cached rows. Change filters while retaining prior rows:
those older results must not hide a failure for the new, uncached query.
+For project labels, warm the Projects list or a project detail, then scroll tasks
+referencing that project out of view and back. With GraphQL caching enabled,
+row remounts must reuse complete cached identities without new
+`InitiativeIdentity` requests; missing identity fields still fetch. Explicit
+permission refreshes remain separate. Hold a cold folder-preview or identity
+request while scrolling on desktop and phone: only the row metadata may show
+loading, and the list must remain mounted at the same scroll position.
+
## Reviews view
With `enable-tasks-reviews` enabled (on by default in development),