fix: stop infinite scroll feedback when no more messages
Scroll handler now checks !hasMore to avoid calling fetchOlderMessages when all messages are loaded. Previously the handler would fire on every scroll event (since scrollTop stayed < 100), creating a .then() callback loop that adjusted scroll position repeatedly, causing 'stuck' scrolling.
This commit is contained in:
@@ -156,6 +156,7 @@ export function DMChat() {
|
||||
const fetchMessages = useConversationStore((s) => s.fetchMessages);
|
||||
const fetchOlderMessages = useConversationStore((s) => s.fetchOlderMessages);
|
||||
const isLoadingOlder = useConversationStore((s) => s.isLoadingOlder);
|
||||
const hasMore = useConversationStore((s) => id ? s.hasMoreByConversation[id] !== false : true);
|
||||
const isLoading = useConversationStore((s) => s.isLoading);
|
||||
const sendMessage = useConversationStore((s) => s.sendMessage);
|
||||
const fetchConversations = useConversationStore((s) => s.fetchConversations);
|
||||
@@ -189,7 +190,7 @@ export function DMChat() {
|
||||
|
||||
const handleScroll = useCallback(() => {
|
||||
const el = scrollContainerRef.current;
|
||||
if (!el || !id || isLoadingOlder) return;
|
||||
if (!el || !id || isLoadingOlder || !hasMore) return;
|
||||
if (el.scrollTop < 100) {
|
||||
const prevHeight = el.scrollHeight;
|
||||
fetchOlderMessages(id).then(() => {
|
||||
@@ -198,7 +199,7 @@ export function DMChat() {
|
||||
});
|
||||
});
|
||||
}
|
||||
}, [id, isLoadingOlder, fetchOlderMessages]);
|
||||
}, [id, isLoadingOlder, hasMore, fetchOlderMessages]);
|
||||
const messages = id ? messagesByConv[id] || [] : [];
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user