From 47917094adfff05451dcecbdd26192384e4742c8 Mon Sep 17 00:00:00 2001 From: mesalogo Date: Thu, 8 Oct 2026 17:08:49 +0800 Subject: [PATCH] revert: restore batched chat history loading --- src/renderer/src/App.tsx | 30 +++++++++++++++++++- src/renderer/src/ConversationHistorySlot.tsx | 13 ++------- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/renderer/src/App.tsx b/src/renderer/src/App.tsx index d95326f3..f53e6e94 100644 --- a/src/renderer/src/App.tsx +++ b/src/renderer/src/App.tsx @@ -131,7 +131,10 @@ import type { ImageViewerItem, Message, } from "./ChatTimeline"; -import type { ChatScrollSnapshot } from "./ChatHistoryPane"; +import { + messageRenderBatchSize, + type ChatScrollSnapshot, +} from "./ChatHistoryPane"; import { usePaneOrder } from "./pane-order"; import { getConversationDisplayTitle, isUnusedConversation, type Conversation } from "./chat-conversation"; import { @@ -1803,6 +1806,9 @@ function App(): React.JSX.Element { ), [], ); + const [visibleMessageCounts, setVisibleMessageCounts] = useState< + Record + >({}); const sidebarRef = useRef(null); const sidebarToggleRef = useRef(null); const livePrimarySidebarWidthRef = useRef(primarySidebarWidth); @@ -1857,6 +1863,15 @@ function App(): React.JSX.Element { }, [], ); + const handleVisibleMessageCountChange = useCallback( + (conversationId: string, count: number): void => { + setVisibleMessageCounts((current) => ({ + ...current, + [conversationId]: count, + })); + }, + [], + ); const closeNarrowSidebar = useCallback((): void => { setSidebarOpen(false); requestAnimationFrame(() => sidebarToggleRef.current?.focus()); @@ -4565,6 +4580,11 @@ function App(): React.JSX.Element { delete next[conversationId]; return next; }); + setVisibleMessageCounts((current) => { + const next = { ...current }; + delete next[conversationId]; + return next; + }); setConversationActivity(conversationId, false); const remaining = conversationStore.getState().filter( (conversation) => conversation.id !== conversationId, @@ -5921,6 +5941,7 @@ function App(): React.JSX.Element { const index = conversation.messages.findIndex(item => item.id === targetId); if (index < 0 || !snapshot.messages.some(message => message.id === targetId)) notify({ tone: 'info', message: t('magicNotes:capture.missingMessage') }); else { + setVisibleMessageCounts(current => ({ ...current, [source.conversationId]: Math.max(current[source.conversationId] ?? messageRenderBatchSize, conversation.messages.length - index) })); setNoteMessageNavigation({ conversationId: source.conversationId, messageId: targetId, requestId: Date.now() }); } } @@ -7060,12 +7081,19 @@ function App(): React.JSX.Element { onSelectTask={setSelectedAssistantTaskId} onSetInput={setQuickActionInput} onSetScheduleEnabled={setAssistantScheduleEnabled} + onVisibleMessageCountChange={ + handleVisibleMessageCountChange + } quickActions={quickActions} schedules={assistantSchedules} scrollSnapshot={chatScrollSnapshots[conversationId]} selectedAssistantTaskId={selectedAssistantTaskId} store={conversationStore} tasks={tasksByConversation.get(conversationId) ?? emptyConversationTasks} + visibleMessageCount={ + visibleMessageCounts[conversationId] ?? + messageRenderBatchSize + } /> ))} {activeProject?.kind === "channel" && diff --git a/src/renderer/src/ConversationHistorySlot.tsx b/src/renderer/src/ConversationHistorySlot.tsx index 38ab2d97..fd0ec5ca 100644 --- a/src/renderer/src/ConversationHistorySlot.tsx +++ b/src/renderer/src/ConversationHistorySlot.tsx @@ -37,9 +37,7 @@ function ConversationHistoryLoader({ conversationId, active, load }: { ; } -type PaneProps = Omit, "conversation" | "taskStrip" | "artifactById" | "onVisibleMessageCountChange" | "visibleMessageCount">; - -const ignoreVisibleMessageCountChange = (): void => undefined; +type PaneProps = Omit, "conversation" | "taskStrip" | "artifactById">; export type ConversationHistorySlotProps = PaneProps & { conversationId: string; @@ -112,12 +110,5 @@ export const ConversationHistorySlot = memo(function ConversationHistorySlot({ /> ); } - return ; + return ; });