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(channels): don't blank on load_around non existing message (#3093)
teof6ba5e8423a0
diff --git a/js/app/packages/channel/Channel/Channel.tsx b/js/app/packages/channel/Channel/Channel.tsxindex 0fb3759a0e..8c55962539 100644--- a/js/app/packages/channel/Channel/Channel.tsx+++ b/js/app/packages/channel/Channel/Channel.tsx@@ -3,6 +3,7 @@ import {useChannelMessagesQuery,createMessageIndex,getChannelMessagesQueryKey,+ isMissingChannelMessageError,} from '@queries/channel/channel-messages';import { queryClient } from '@queries/client';import {@@ -24,6 +25,7 @@ import {type ThreadListScrollTarget,} from './ThreadList';import { StaticMarkdownContext } from '@core/component/LexicalMarkdown/component/core/StaticMarkdown';+import { toast } from '@core/component/Toast/Toast';import { createThreadManager } from './thread-manager';import { createThreadPaginator } from './thread-paginator';import { useUserId } from '@core/context/user';@@ -142,6 +144,23 @@ export function Channel(props: ChannelProps) {targetMessageController.loadAroundMessageId);+ createEffect(+ on(+ [targetMessageController.loadAroundMessageId, () => messagesQuery.error],+ ([loadAroundMessageId, error]) => {+ if (!loadAroundMessageId || !isMissingChannelMessageError(error))+ return;++ toast.alert(+ 'Message no longer available',+ 'Showing the latest messages instead.'+ );+ clearStaleRestoredChannelData(props.channelId);+ targetMessageController.reset();+ }+ )+ );+const messageIndex = createMessageIndex(() => messagesQuery.data as ChannelMessagesData | undefined);diff --git a/js/app/packages/queries/channel/channel-messages.ts b/js/app/packages/queries/channel/channel-messages.tsindex 3c4678c03c..6a61b6a51d 100644--- a/js/app/packages/queries/channel/channel-messages.ts+++ b/js/app/packages/queries/channel/channel-messages.ts@@ -1,4 +1,4 @@-import { throwOnErr } from '@core/util/maybeResult';+import { MaybeResultError, throwOnErr } from '@core/util/maybeResult';import {commsServiceClient,type ApiChannelMessage,@@ -56,6 +56,13 @@ type ChannelMessagesPageParam = {previous_cursor: string | null;};+export function isMissingChannelMessageError(error: unknown): boolean {+ return (+ error instanceof MaybeResultError &&+ error.errors.some(({ code }) => code === 'NOT_FOUND' || code === 'GONE')+ );+}+export function channelMessagesQueryOptions(channelId: string,loadAroundMessageId: string | null@@ -94,6 +101,12 @@ export function channelMessagesQueryOptions(}: null,staleTime: Infinity,+ retry: (failureCount: number, error: Error) => {+ if (loadAroundMessageId && isMissingChannelMessageError(error)) {+ return false;+ }+ return failureCount < 1;+ },};}diff --git a/js/app/packages/queries/channel/tests/channel-messages.test.ts b/js/app/packages/queries/channel/tests/channel-messages.test.tsnew file mode 100644index 0000000000..c5dcf78bbe--- /dev/null+++ b/js/app/packages/queries/channel/tests/channel-messages.test.ts@@ -0,0 +1,83 @@+/**+ * @vitest-environment jsdom+ */++import { QueryClient } from '@tanstack/solid-query';+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';+import { MaybeResultError } from '@core/util/maybeResult';++const mocks = vi.hoisted(() => ({+ getChannelMessages: vi.fn(),+}));++let testQueryClient: QueryClient;++vi.mock('../../client', () => ({+ get queryClient() {+ return testQueryClient;+ },+}));++vi.mock('@service-comms/client', () => ({+ commsServiceClient: {+ getChannelMessages: mocks.getChannelMessages,+ },+}));++import {+ channelMessagesQueryOptions,+ isMissingChannelMessageError,+} from '../channel-messages';++beforeEach(() => {+ testQueryClient = new QueryClient();+ mocks.getChannelMessages.mockReset();+});++afterEach(() => {+ testQueryClient.clear();+});++describe('channelMessagesQueryOptions', () => {+ it.each([+ 'NOT_FOUND',+ 'GONE',+ ] as const)('throws missing load-around messages without retrying them for %s', async (code) => {+ mocks.getChannelMessages.mockResolvedValueOnce([+ [{ code, message: 'Message unavailable' }],+ null,+ ]);++ const options = channelMessagesQueryOptions('channel-1', 'message-missing');++ let error: unknown;+ try {+ await options.queryFn({ pageParam: null });+ } catch (err) {+ error = err;+ }++ if (!(error instanceof Error)) {+ throw new Error('Expected queryFn to throw an Error');+ }++ expect(error).toBeInstanceOf(MaybeResultError);+ expect(isMissingChannelMessageError(error)).toBe(true);+ expect(options.retry(0, error)).toBe(false);+ expect(mocks.getChannelMessages).toHaveBeenCalledTimes(1);+ expect(mocks.getChannelMessages).toHaveBeenCalledWith({+ channel_id: 'channel-1',+ limit: 50,+ next_cursor: null,+ previous_cursor: null,+ load_around_message_id: 'message-missing',+ });+ });++ it('preserves the default single retry for other errors', () => {+ const options = channelMessagesQueryOptions('channel-1', null);++ expect(options.retry(0, new Error('network'))).toBe(true);+ expect(options.retry(1, new Error('network'))).toBe(false);+ });+});