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(email): mark each thread read when cached navigation keeps the view mounted (#7929)
teodd25c03fe279
diff --git a/apps/web/src/features/block-email/component/EmailThreadLoadGate.test.tsx b/apps/web/src/features/block-email/component/EmailThreadLoadGate.test.tsxindex 16a5456a31..c672788403 100644--- a/apps/web/src/features/block-email/component/EmailThreadLoadGate.test.tsx+++ b/apps/web/src/features/block-email/component/EmailThreadLoadGate.test.tsx@@ -3,19 +3,28 @@ import type { EntityLoadError } from '@core/component/EntityLoadGate';import type { ThreadQueryData, ThreadQueryResult } from '@queries/email/thread';import type { ApiThread } from '@service-email/generated/schemas';import { cleanup, render, screen } from '@solidjs/testing-library';-import { createSignal, onCleanup } from 'solid-js';+import { batch, createSignal, onCleanup, onMount } from 'solid-js';import { afterEach, expect, it, vi } from 'vitest';import {EmailThreadLoadGate,type EmailThreadLoadGateProps,} from './EmailThreadLoadGate';+const markers = vi.hoisted(() => ({+ mounts: [] as string[],+ releases: [] as string[],+}));vi.mock('@notifications', () => ({- EmailDebouncedReadMarker: (props: { threadId: string; linkId?: string }) => (- <span data-testid="read-marker">- {props.threadId}:{props.linkId}- </span>- ),+ EmailDebouncedReadMarker: (props: { threadId: string; linkId?: string }) => {+ const id = props.threadId;+ onMount(() => markers.mounts.push(id));+ onCleanup(() => markers.releases.push(id));+ return (+ <span data-testid="read-marker">+ {props.threadId}:{props.linkId}+ </span>+ );+ },}));vi.mock('@core/mobile/native-network-status', () => ({nativeNetworkStatus: () => 'online',@@ -182,3 +191,36 @@ it('retains the mounted composer during identity revalidation but respects serveexpect(screen.getByText('Not found')).toBeTruthy();expect(unmounted).toHaveBeenCalledOnce();});++it('restarts read marking for cached navigation without remounting the body', () => {+ markers.mounts.length = 0;+ markers.releases.length = 0;+ const [id, setId] = createSignal('a');+ const [data, setData] = createSignal<string | undefined>('cached');+ const [pending, setPending] = createSignal(false);+ render(() => (+ <EmailThreadLoadGate+ threadId={id()}+ notificationSource={+ {} as EmailThreadLoadGateProps<string>['notificationSource']+ }+ result={{ data, error: () => undefined, isPending: pending }}+ onRetry={() => {}}+ >+ <div data-testid="body" />+ </EmailThreadLoadGate>+ ));+ const body = screen.getByTestId('body');+ expect(markers.mounts).toEqual(['a']);+ setId('b');+ expect(markers.mounts).toEqual(['a', 'b']);+ expect(markers.releases).toEqual(['a']);+ expect(screen.getByTestId('body')).toBe(body);+ setId('b');+ expect(markers.mounts).toHaveLength(2);+ batch(() => {+ setData(undefined);+ setPending(true);+ });+ expect(markers.releases).toEqual(['a', 'b']);+});diff --git a/apps/web/src/features/block-email/component/EmailThreadLoadGate.tsx b/apps/web/src/features/block-email/component/EmailThreadLoadGate.tsxindex aa3ae0e068..35f35aaf65 100644--- a/apps/web/src/features/block-email/component/EmailThreadLoadGate.tsx+++ b/apps/web/src/features/block-email/component/EmailThreadLoadGate.tsx@@ -5,7 +5,7 @@ import {} from '@core/component/EntityLoadGate';import { EmailDebouncedReadMarker } from '@notifications';import type { ComponentProps, ParentProps } from 'solid-js';-import { Suspense } from 'solid-js';+import { Show, Suspense } from 'solid-js';export type EmailThreadLoadGateProps<Data> = ParentProps<{result: EntityLoadResult<Data>;@@ -40,12 +40,16 @@ export function EmailThreadLoadGate<Data>(loadErrorTitle="Unable to load this email"onRetry={props.onRetry}>- <EmailDebouncedReadMarker- notificationSource={props.notificationSource}- threadId={props.threadId}- linkId={props.linkId}- debounceTime={props.debounceTime}- />+ <Show when={props.threadId} keyed>+ {(threadId) => (+ <EmailDebouncedReadMarker+ notificationSource={props.notificationSource}+ threadId={threadId}+ linkId={props.linkId}+ debounceTime={props.debounceTime}+ />+ )}+ </Show>{props.children}</EntityLoadGate></Suspense>