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(ios): keep navigation visible while offline queries are pending (#8497)
Peter Chinman95c830e9b14a
diff --git a/apps/web/AGENTS.md b/apps/web/AGENTS.mdindex f07810e31b..f1981554c3 100644--- a/apps/web/AGENTS.md+++ b/apps/web/AGENTS.md@@ -113,7 +113,7 @@ ownership. Cancel, logout, and the ten-minute timeout retire pending callbacks.engine and re-register in place, preserving durable storage and never replayinguncertain enqueues. See `docs/graphql-normalized-cache-plan.md`.- Mobile dock customization shares the navigation island’s measured capacity; persist ordering per user with `mobile-dock-order.ts`, preserve gated destinations, and keep Search and More fixed. Reorder handles drag without a hold delay; the rest of each row scrolls.-- Share sidebar and mobile dock unread presence through `components/app/use-navigation-unread.ts`; keep badges reactive to read/done changes and avoid fetching extra pages for counts.+- Share sidebar and mobile dock unread presence through `components/app/use-navigation-unread.ts`; keep badges reactive to read/done changes, guard all query data with `queryReadyGate` so pending preferences or paused queries cannot suspend the shell, and avoid fetching extra pages for counts.- Mobile dock search owns transient category/mode state in `features/command/mobile`; reuse the shared entity source and explicit full-text adapter rather than overlaying the dock query on view tabs or saved facets. See `docs/agent-guide/search.md` at the repository root.- Include known Macro users in typed All/People name searches without requiring a DM or CRM contact; resolve a matching person to their existing one-to-one DM while preserving name/email matching.- Keep mobile search sessions, result order, loaded rows, and scroll state with their Search history entry; preserve order before opening a result so viewedAt updates cannot move it on Back. Refresh row data in place and append later pages. Scope saved rows and scroll measurements to their account and reset result adapters/scrollers on account changes. Query/category changes rerank; a fresh dock search supplies a new session ID in Search's route state, including when reusing a native pane.diff --git a/apps/web/src/components/app/use-navigation-unread.test.ts b/apps/web/src/components/app/use-navigation-unread.test.tsxsimilarity index 67%rename from apps/web/src/components/app/use-navigation-unread.test.tsrename to apps/web/src/components/app/use-navigation-unread.test.tsxindex 03e38d8f9f..798e842550 100644--- a/apps/web/src/components/app/use-navigation-unread.test.ts+++ b/apps/web/src/components/app/use-navigation-unread.test.tsx@@ -1,7 +1,16 @@import type { EmailEntity } from '@entity/types/entity';import type { UnifiedNotification } from '@notifications/types';+import type { GetNotificationTypePreferencesResponse } from '@service-notification/generated/schemas/getNotificationTypePreferencesResponse';import type { NotificationState } from '@service-storage/graphql/generated/graphql';-import { createRoot, createSignal } from 'solid-js';+import { cleanup, render, screen } from '@solidjs/testing-library';+import {+ onlineManager,+ QueryClient,+ QueryClientProvider,+ type UseQueryResult,+ useQuery,+} from '@tanstack/solid-query';+import { createEffect, createRoot, createSignal, Suspense } from 'solid-js';import { afterEach, describe, expect, it, vi } from 'vitest';import { useNavigationUnread } from './use-navigation-unread';@@ -82,12 +91,19 @@ const message: UnifiedNotification = {};let dispose: VoidFunction;+const clients: QueryClient[] = [];afterEach(() => {+ cleanup();dispose?.();+ for (const client of clients.splice(0)) client.clear();+ onlineManager.setOnline(true);vi.clearAllMocks();});-function setup(graphql = false) {+function setup(+ graphql = false,+ preferences?: () => UseQueryResult<GetNotificationTypePreferencesResponse>+) {return createRoot((cleanup) => {dispose = cleanup;const [graphqlEnabled, setGraphqlEnabled] = createSignal(graphql);@@ -96,23 +112,31 @@ function setup(graphql = false) {mocks.withLocalState.mockImplementation(({ state }) =>done() ? 'done' : state);- mocks.notificationPreferences.mockImplementation(() => ({- get data() {- return { disabled_types: disabledTypes() };- },- }));+ mocks.notificationPreferences.mockImplementation(+ preferences ??+ (() => ({+ isPending: false,+ get data() {+ return { disabled_types: disabledTypes() };+ },+ }))+ );const [witnesses, setWitnesses] = createSignal<{ id: string; state: NotificationState }[]>([]);mocks.graphqlFlag.mockImplementation(() => ({ enabled: graphqlEnabled() }));const [loading, setLoading] = createSignal(true);+ const [fetching, setFetching] = createSignal(true);mocks.channels.mockReturnValue({get isEnabled() {return graphqlEnabled();},- get isLoading() {+ get isPending() {return loading();},+ get isLoading() {+ return loading() && fetching();+ },get data() {if (loading()) throw new Error('Read pending unread query');return witnesses();@@ -123,9 +147,12 @@ function setup(graphql = false) {UnifiedNotification[]>([]);const query = {- get isLoading() {+ get isPending() {return loading();},+ get isLoading() {+ return loading() && fetching();+ },get data() {if (loading()) throw new Error('Read pending resource');return { entities: emails() };@@ -142,6 +169,7 @@ function setup(graphql = false) {return {unread: useNavigationUnread(),setLoading,+ setFetching,setEmails,setNotifications,setWitnesses,@@ -153,6 +181,101 @@ function setup(graphql = false) {}describe('navigation unread presence', () => {+ it('does not read pending email or channel data when their requests pause', () => {+ const { unread, setFetching } = setup(true);+ setFetching(false);+ expect(unread('mail')).toBe(false);+ expect(unread('channels')).toBe(false);+ });++ it.each([true, false])(+ 'keeps the shell mounted with pending preferences (online=%s), then applies them',+ async (online) => {+ onlineManager.setOnline(online);+ const response =+ Promise.withResolvers<GetNotificationTypePreferencesResponse>();+ const applied = Promise.withResolvers<void>();+ const client = new QueryClient({+ defaultOptions: { queries: { retry: false } },+ });+ clients.push(client);+ function Shell() {+ const { unread, setLoading, setEmails } = setup(false, () =>+ useQuery(() => ({+ queryKey: ['preferences'],+ queryFn: () => response.promise,+ }))+ );+ setLoading(false);+ setEmails([unreadEmail]);+ createEffect(() => {+ if (!unread('mail')) applied.resolve();+ });+ return <nav data-testid="shell" data-unread={unread('mail')} />;+ }+ render(() => (+ <QueryClientProvider client={client}>+ <Suspense fallback={<div data-testid="suspended" />}>+ <Shell />+ </Suspense>+ </QueryClientProvider>+ ));+ const shell = screen.getByTestId('shell');+ expect(shell.dataset.unread).toBe('true');+ expect(screen.queryByTestId('suspended')).toBeNull();+ expect(client.getQueryState(['preferences'])?.fetchStatus).toBe(+ online ? 'fetching' : 'paused'+ );+ onlineManager.setOnline(true);+ response.resolve({ disabled_types: ['new_email'] });+ await applied.promise;+ expect(shell.dataset.unread).toBe('false');+ expect(screen.getByTestId('shell')).toBe(shell);+ expect(screen.queryByTestId('suspended')).toBeNull();+ }+ );++ it('retains cached disabled preferences after a failed background refresh', async () => {+ const response =+ Promise.withResolvers<GetNotificationTypePreferencesResponse>();+ const failed = Promise.withResolvers<void>();+ const client = new QueryClient({+ defaultOptions: { queries: { retry: false } },+ });+ clients.push(client);+ function Shell() {+ const { unread, setLoading, setEmails } = setup(false, () => {+ const query = useQuery(() => ({+ queryKey: ['preferences'],+ queryFn: () => response.promise,+ initialData: { disabled_types: ['new_email'] },+ }));+ createEffect(() => {+ if (query.isError) failed.resolve();+ });+ return query;+ });+ setLoading(false);+ setEmails([unreadEmail]);+ return <nav data-testid="shell" data-unread={unread('mail')} />;+ }+ render(() => (+ <QueryClientProvider client={client}>+ <Suspense fallback={<div data-testid="suspended" />}>+ <Shell />+ </Suspense>+ </QueryClientProvider>+ ));+ const shell = screen.getByTestId('shell');+ expect(shell.dataset.unread).toBe('false');+ response.reject(new Error('Service unreachable'));+ await failed.promise;+ expect(client.getQueryState(['preferences'])?.status).toBe('error');+ expect(screen.getByTestId('shell')).toBe(shell);+ expect(shell.dataset.unread).toBe('false');+ expect(screen.queryByTestId('suspended')).toBeNull();+ });+it('does not read pending resources or badge unrelated navigation', () => {const { unread } = setup();for (const id of ['home', 'mail', 'channels', 'documents', 'agents']) {diff --git a/apps/web/src/components/app/use-navigation-unread.ts b/apps/web/src/components/app/use-navigation-unread.tsindex 091ac39e86..876915a111 100644--- a/apps/web/src/components/app/use-navigation-unread.ts+++ b/apps/web/src/components/app/use-navigation-unread.ts@@ -14,6 +14,7 @@ import { notificationIsRead } from '@entity/utils/notification';import { notificationStateFromGraphql } from '@notifications/notification-state';import { isUnreadChannelMessageNotification } from '@notifications/top-level-channel-notification';import { createChannelUnreadQuery } from '@queries/channel/unread-presence';+import { queryReadyGate } from '@queries/gate';import { useNotificationTypePreferencesQuery } from '@queries/notification/type-preferences';import { makeGraphqlSoupInput } from '@queries/soup/graphql/ast';import {@@ -32,7 +33,8 @@ export function useNavigationUnread() {const graphqlFlag = useFeatureFlag(enableGraphqlSoup);const preferencesQuery = useNotificationTypePreferencesQuery();const isTypeDisabled = (type: string) =>- preferencesQuery.data?.disabled_types.includes(type) ?? false;+ queryReadyGate(preferencesQuery) &&+ preferencesQuery.data.disabled_types.includes(type);const channels = createChannelUnreadQuery(makeGraphqlSoupInput({// Preserve the previous feed's 500-entity candidate bound, but select@@ -67,15 +69,15 @@ export function useNavigationUnread() {// Respect user preference: hide badge when email notifications are disabled.const emailUnread = createMemo(() => {if (isTypeDisabled('new_email')) return false;- if (email.isLoading) return false;- return (email.data?.entities ?? []).some(+ if (!queryReadyGate(email)) return false;+ return email.data.entities.some((entity) => entity.type === 'email' && !entity.isRead && !entity.done);});const channelsUnread = createMemo(() => {if (graphqlFlag().enabled) {- if (!channels.isEnabled || channels.isLoading) return false;- return (channels.data ?? []).some((notification) => {+ if (!channels.isEnabled || !queryReadyGate(channels)) return false;+ return channels.data.some((notification) => {const state = notificationStateFromGraphql(notification.state);return ((notificationSource.withLocalState?.({diff --git a/apps/web/src/features/home/queries/use-home-unread-query.test.ts b/apps/web/src/features/home/queries/use-home-unread-query.test.tsindex ad94fc1837..a91f5fbaf9 100644--- a/apps/web/src/features/home/queries/use-home-unread-query.test.ts+++ b/apps/web/src/features/home/queries/use-home-unread-query.test.ts@@ -67,11 +67,16 @@ function setup(initialNotifiedSort = false) {const [notifiedSort, setNotifiedSort] = createSignal(initialNotifiedSort);mocks.notifiedSort.mockImplementation(notifiedSort);const [state, setState] = createSignal<'unseen' | 'seen' | 'done'>();+ const [pending, setPending] = createSignal(false);mocks.legacyUnread.mockReturnValue(true);mocks.legacy.mockReturnValue({query: {isLoading: false,+ get isPending() {+ return pending();+ },get data() {+ if (pending()) throw new Error('Read paused initial Soup query');if (enabled() && !notifiedSort())throw new Error('Read inactive full Soup query');return { entities: [] };@@ -96,7 +101,7 @@ function setup(initialNotifiedSort = false) {}),});const unread = useHomeUnreadQuery(enabled);- return { unread, setEnabled, setState, setNotifiedSort };+ return { unread, setEnabled, setState, setNotifiedSort, setPending };});const queries = () => operations.filter((op) => op.kind === 'query');const respond = (state: 'UNSEEN' | 'SEEN', error?: CombinedError) =>@@ -132,6 +137,15 @@ function setup(initialNotifiedSort = false) {}describe('Home unread presence query', () => {+ it('does not read a paused initial legacy query', () => {+ const h = setup();+ h.setPending(true);+ expect(h.unread()).toBe(false);+ expect(mocks.legacyUnread).not.toHaveBeenCalled();+ h.setPending(false);+ expect(h.unread()).toBe(true);+ });+it('selects bounded witnesses rather than historical notification content', () => {const fields: string[] = [];const edges: string[] = [];diff --git a/apps/web/src/features/home/queries/use-home-unread-query.ts b/apps/web/src/features/home/queries/use-home-unread-query.tsindex 187080782d..adae9f761e 100644--- a/apps/web/src/features/home/queries/use-home-unread-query.ts+++ b/apps/web/src/features/home/queries/use-home-unread-query.ts@@ -3,6 +3,7 @@ import { enableInboxNotifiedSort } from '@core/constant/featureFlags';import { createLiveQuery } from '@graphql-cache/solid/create-live-query';import { registerActivityRevalidator } from '@queries/activity/push-registry';import { registerChannelNotificationRefresh } from '@queries/channel/register-notification-refresh';+import { queryReadyGate } from '@queries/gate';import {registerActiveGraphqlSoupQuery,registerGraphqlSoupRevalidations,@@ -80,8 +81,8 @@ export function useHomeUnreadQuery(return () => {if (!enabled()) {- if (legacy.query.isLoading) return false;- return legacy.hasUnreadEntity(legacy.query.data?.entities ?? []);+ if (!queryReadyGate(legacy.query)) return false;+ return legacy.hasUnreadEntity(legacy.query.data.entities);}return hasHomeUnreadWitness(items(),diff --git a/docs/agent-guide/navigation.md b/docs/agent-guide/navigation.mdindex b0937d119b..c832c12266 100644--- a/docs/agent-guide/navigation.md+++ b/docs/agent-guide/navigation.md@@ -418,6 +418,11 @@ edge so an older unread item can keep the dot lit. These witnesses must never beused as the complete mark-read/done input. The experimental notification-timesort remains on its existing REST path; disabling GraphQL or enabling that sortmust not construct an unsupported GraphQL input or blank the app shell.+Cold offline launch must retain navigation even while notification preferences+or badge queries are pending. Unknown preferences use the default enabled+behavior; loaded disabled preferences still suppress Email's dot, including+after a failed refresh. Verify both unreachable services while the OS reports+online and a paused offline transport, then reconnect without remounting chrome.Opening a view alone does not clear its dot — reading or completing the representeditems does. The button'saccessible description is `Unread items` while its dot is active.