fix(dashboard): load all messages in chat on initial open (useChat + useQuickChat)

Both useChat (full ChatView) and useQuickChat (FAB) loaded only the first 50
messages on open and never paginated further. In useChat, loadMoreMessages
exists but ChatView never calls it — dead code. In useQuickChat, there was
no pagination at all.

Fix: add fetchAllMessagesInChat / fetchAllMessages helpers (paginate through
the API 200-msg cap), replace all limit:50 initial-load call sites, and
add stale-session guards via activeSessionRef before calling setMessages.
hasMoreMessages is set to false after a full initial load.

Forward-pagination path in useChat (isPaginationRequest=true) is preserved
for backward compat.
This commit is contained in:
Josemi Liebana
2026-05-22 14:42:42 +02:00
parent fbf7e2cb4d
commit 64056b380d
3 changed files with 76 additions and 17 deletions

View File

@@ -0,0 +1,15 @@
---
"@runfusion/fusion": patch
---
Fix `useChat` truncating sessions longer than 50 messages on initial open.
`loadMessages()` fetched `{ limit: 50 }` for the initial load. The
`loadMoreMessages` callback was never called from `ChatView` (no scroll
sentinel exists), so sessions beyond 50 messages were permanently cut off.
Fix: introduce `fetchAllMessagesInChat()` that paginates through the API's
200-message cap and replace the initial load path. A stale-session guard
(via `activeSessionRef`) prevents overwriting a switched session's messages.
The forward-pagination path (`isPaginationRequest = true`) is preserved
unchanged for backward compatibility.