Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.
Python agent-orchestrationaiai-agentschatopsdiscordlangchainmcpmicrosoft-teamsmulti-agentopen-sourceopenaiself-hostedslack
fix(console): keep the reader's place and retry the right page on load earlier (CHOO-3783)
raullopez-sandboxf7e00da40b42
diff --git a/console/apps/switch-console-desktop/src/renderer/features/chats/components/chat-panel.tsx b/console/apps/switch-console-desktop/src/renderer/features/chats/components/chat-panel.tsxindex ef0eeb138..4a59e644b 100644--- a/console/apps/switch-console-desktop/src/renderer/features/chats/components/chat-panel.tsx+++ b/console/apps/switch-console-desktop/src/renderer/features/chats/components/chat-panel.tsx@@ -149,7 +149,7 @@ export const ChatPanel = observer(function ChatPanel({className="flex items-center justify-between gap-3 bg-background-1 px-5 py-2 text-sm"><span>{timeline.loadError}</span>- <Button size="sm" variant="outline" onClick={() => void timeline.load()}>+ <Button size="sm" variant="outline" onClick={() => timeline.retryLoad()}>Try again</Button></div>diff --git a/console/apps/switch-console-desktop/src/renderer/features/chats/components/chat-timeline.tsx b/console/apps/switch-console-desktop/src/renderer/features/chats/components/chat-timeline.tsxindex bf769cb76..c7038677c 100644--- a/console/apps/switch-console-desktop/src/renderer/features/chats/components/chat-timeline.tsx+++ b/console/apps/switch-console-desktop/src/renderer/features/chats/components/chat-timeline.tsx@@ -234,7 +234,7 @@ export const ChatTimelineView = observer(function ChatTimelineView({return (<div className="flex flex-col">{timeline.hasMore && (- <div className={cn('flex justify-center', spacing())}>+ <div className={cn('flex justify-center [overflow-anchor:none]', spacing())}><Buttonsize="sm"variant="ghost"diff --git a/console/apps/switch-console-desktop/src/renderer/features/chats/stores/chat-timeline-store.ts b/console/apps/switch-console-desktop/src/renderer/features/chats/stores/chat-timeline-store.tsindex 34d2434a4..c06eede9a 100644--- a/console/apps/switch-console-desktop/src/renderer/features/chats/stores/chat-timeline-store.ts+++ b/console/apps/switch-console-desktop/src/renderer/features/chats/stores/chat-timeline-store.ts@@ -102,6 +102,8 @@ export class ChatTimeline {loaded = false;loading = false;loadError: string | null = null;+ /** The failure in {@link loadError} was loading earlier messages, not the newest. */+ olderFailed = false;/** The person is not a member of the room. */notMember = false;/** The person was a member and lost access while the chat was known. */@@ -165,6 +167,7 @@ export class ChatTimeline {if (this.loading) return;this.loading = true;this.loadError = null;+ this.olderFailed = false;const held = this.newestSeq;try {let page = await this.api.messages(this.roomId, null, PAGE_SIZE);@@ -204,10 +207,13 @@ export class ChatTimeline {runInAction(() => {for (const message of page.messages) this.apply(message);this.hasMore = page.hasMore;+ this.loadError = null;+ this.olderFailed = false;});} catch (error) {runInAction(() => {this.loadError = chatFailure(error).message;+ this.olderFailed = true;});} finally {runInAction(() => {@@ -216,6 +222,11 @@ export class ChatTimeline {}}+ /** Ask again for what last failed to load. */+ retryLoad(): void {+ void (this.olderFailed ? this.loadOlder() : this.load());+ }+/** Send a message; returns its request id. */send(input: SendInput): string {const send: PendingSend = {diff --git a/console/apps/switch-console-desktop/src/renderer/features/chats/ui/message-scroller.tsx b/console/apps/switch-console-desktop/src/renderer/features/chats/ui/message-scroller.tsxindex ca126a995..66e170a9b 100644--- a/console/apps/switch-console-desktop/src/renderer/features/chats/ui/message-scroller.tsx+++ b/console/apps/switch-console-desktop/src/renderer/features/chats/ui/message-scroller.tsx@@ -79,7 +79,8 @@ function MessageScroller({ className, ...props }: React.ComponentProps<'div'>) {}function MessageScrollerViewport({ className, onScroll, ...props }: React.ComponentProps<'div'>) {- const { viewportRef, setViewport, followingRef, setAtBottom } = useMessageScrollerContext();+ const { viewportRef, setViewport, followingRef, atBottom, setAtBottom } =+ useMessageScrollerContext();const attach = React.useCallback((node: HTMLDivElement | null) => {viewportRef.current = node;@@ -104,14 +105,16 @@ function MessageScrollerViewport({ className, onScroll, ...props }: React.CompononScroll?.(event);};- // No scroll anchoring: when content above the end grows, the browser would- // shift scrollTop to hold its anchor, and that scroll reads as the reader- // leaving the bottom, so following stops.+ // No scroll anchoring while following: when content above the end grows, the+ // browser would shift scrollTop to hold its anchor, and that scroll reads as+ // the reader leaving the bottom, so following stops. Scrolled up, anchoring+ // keeps the reader's place when earlier messages are prepended.return (<divdata-slot="message-scroller-viewport"className={cn(- 'size-full min-h-0 min-w-0 overflow-y-auto overscroll-contain [overflow-anchor:none] [scrollbar-gutter:stable]',+ 'size-full min-h-0 min-w-0 overflow-y-auto overscroll-contain [scrollbar-gutter:stable]',+ atBottom && '[overflow-anchor:none]',className)}{...props}diff --git a/console/apps/switch-console-desktop/src/renderer/tests/chat-timeline-store.test.ts b/console/apps/switch-console-desktop/src/renderer/tests/chat-timeline-store.test.tsindex 47f19248e..7f0fe8bab 100644--- a/console/apps/switch-console-desktop/src/renderer/tests/chat-timeline-store.test.ts+++ b/console/apps/switch-console-desktop/src/renderer/tests/chat-timeline-store.test.ts@@ -247,4 +247,29 @@ describe('ChatTimeline', () => {);expect(timeline.hasMore).toBe(false);});++ it('retries a failed load of earlier messages, not the newest page, and clears the error', async () => {+ let fail = false;+ const asked: (number | null)[] = [];+ const { value } = api({+ messages: async (_room, before) => {+ asked.push(before);+ if (fail) throw networkError();+ return before === null+ ? { messages: [message(51), message(52)], headSeq: 52, hasMore: true }+ : { messages: [message(50)], headSeq: 52, hasMore: false };+ },+ });+ const timeline = new ChatTimeline('room-1', value);+ await timeline.load();+ fail = true;+ await timeline.loadOlder();+ expect(timeline.loadError).not.toBeNull();++ fail = false;+ timeline.retryLoad();+ await vi.waitFor(() => expect(timeline.messages.map((m) => m.seq)).toEqual([50, 51, 52]));+ expect(asked).toEqual([null, 51, 51]);+ expect(timeline.loadError).toBeNull();+ });});