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(channel): restore mount-time thread reply prefetch (#7351)
teo9d29efc0d20a
diff --git a/apps/web/src/features/channel/Thread/ChannelThread.tsx b/apps/web/src/features/channel/Thread/ChannelThread.tsxindex d202fee24d..ccf84930f6 100644--- a/apps/web/src/features/channel/Thread/ChannelThread.tsx+++ b/apps/web/src/features/channel/Thread/ChannelThread.tsx@@ -43,6 +43,7 @@ export function ChannelThread(props: ThreadProps) {const hasReplies = () => thread().reply_count > 0;const fetchRepliesEnabled = createThreadRepliesFetchGate({threadId: () => props.data().id,+ replyCount: () => thread().reply_count,isExpanded: props.isExpanded,isFindBarOpen: props.isFindBarOpen,targetThreadId: () => props.targetNavigation?.targetThreadId(),diff --git a/apps/web/src/features/channel/Thread/create-thread-replies-fetch-gate.ts b/apps/web/src/features/channel/Thread/create-thread-replies-fetch-gate.tsindex 725951b2f1..d0ee58c75b 100644--- a/apps/web/src/features/channel/Thread/create-thread-replies-fetch-gate.ts+++ b/apps/web/src/features/channel/Thread/create-thread-replies-fetch-gate.ts@@ -1,10 +1,12 @@import { deferredGate } from '@core/util/debounce';import type { Accessor } from 'solid-js';+import { DEFAULT_VISIBLE_REPLY_GROUP_COUNT } from './utils/thread-reply-indicator-helpers';export const THREAD_REPLIES_FETCH_DEBOUNCE_MS = 300;type CreateThreadRepliesFetchGateOptions = {threadId: Accessor<string>;+ replyCount: Accessor<number>;isExpanded: Accessor<boolean>;isFindBarOpen: Accessor<boolean>;targetThreadId: Accessor<string | undefined>;@@ -12,8 +14,7 @@ type CreateThreadRepliesFetchGateOptions = {};/**- * Collapsed threads use their timeline preview without fetching full replies.- * Delays explicit expansion/navigation fetches while transient rows unmount.+ * Delays reply fetching long enough for transiently mounted threads to unmount.* Cmd+F navigation is the only immediate path because it needs the targeted* reply list before it can position the active search result.*/@@ -23,7 +24,10 @@ export function createThreadRepliesFetchGate(const isTargetedReply = () =>!!options.targetReplyId() &&options.targetThreadId() === options.threadId();- const shouldFetchReplies = () => isTargetedReply() || options.isExpanded();+ const shouldFetchReplies = () =>+ isTargetedReply() ||+ options.isExpanded() ||+ options.replyCount() > DEFAULT_VISIBLE_REPLY_GROUP_COUNT;const debouncedFetchReplies = deferredGate(shouldFetchReplies,THREAD_REPLIES_FETCH_DEBOUNCE_MSdiff --git a/apps/web/src/features/channel/Thread/tests/create-thread-replies-fetch-gate.test.ts b/apps/web/src/features/channel/Thread/tests/create-thread-replies-fetch-gate.test.tsindex 353d98bdf5..3cbb4e53cb 100644--- a/apps/web/src/features/channel/Thread/tests/create-thread-replies-fetch-gate.test.ts+++ b/apps/web/src/features/channel/Thread/tests/create-thread-replies-fetch-gate.test.ts@@ -4,10 +4,12 @@ import {createThreadRepliesFetchGate,THREAD_REPLIES_FETCH_DEBOUNCE_MS,} from '../create-thread-replies-fetch-gate';+import { DEFAULT_VISIBLE_REPLY_GROUP_COUNT } from '../utils/thread-reply-indicator-helpers';type FixtureOptions = {isExpanded?: boolean;isFindBarOpen?: boolean;+ replyCount?: number;targetReplyId?: string;targetThreadId?: string;};@@ -31,6 +33,7 @@ describe('createThreadRepliesFetchGate', () => {dispose = rootDispose;enabled = createThreadRepliesFetchGate({threadId: () => 'thread-1',+ replyCount: () => options.replyCount ?? 0,isExpanded: () => options.isExpanded ?? false,isFindBarOpen: () => options.isFindBarOpen ?? false,targetThreadId: () => options.targetThreadId,@@ -45,11 +48,17 @@ describe('createThreadRepliesFetchGate', () => {await Promise.resolve();};- it('does not fetch full replies merely because a collapsed thread stays mounted', async () => {- const fixture = createFixture();+ it('waits 300ms before enabling an ordinary thread reply fetch', async () => {+ const fixture = createFixture({+ replyCount: DEFAULT_VISIBLE_REPLY_GROUP_COUNT + 1,+ });await flushEffects();- vi.advanceTimersByTime(THREAD_REPLIES_FETCH_DEBOUNCE_MS * 10);+expect(fixture.enabled()).toBe(false);+ vi.advanceTimersByTime(THREAD_REPLIES_FETCH_DEBOUNCE_MS - 1);+ expect(fixture.enabled()).toBe(false);+ vi.advanceTimersByTime(1);+ expect(fixture.enabled()).toBe(true);});it('also debounces expansion and non-find-bar reply navigation', async () => {