From c6b5d2e77bd5d95aac20fa7d6c998aa319a8a152 Mon Sep 17 00:00:00 2001 From: wizardchen Date: Thu, 18 Jun 2026 16:53:10 +0800 Subject: [PATCH] feat(frontend): enhance chat scroll handling for improved user experience - Implement logic to accurately detect user scroll direction, preventing false positives during content loading. - Update scroll handling in both `useEmbedChatSession` and chat view to maintain auto-follow functionality during streaming. - Introduce a mechanism to differentiate between actual upward scrolls and content growth, enhancing chat usability. --- frontend/src/composables/useEmbedChatSession.ts | 16 +++++++++++++++- frontend/src/views/chat/index.vue | 16 +++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/frontend/src/composables/useEmbedChatSession.ts b/frontend/src/composables/useEmbedChatSession.ts index 4734abc3..3ebff793 100644 --- a/frontend/src/composables/useEmbedChatSession.ts +++ b/frontend/src/composables/useEmbedChatSession.ts @@ -152,8 +152,22 @@ export function useEmbedChatSession(options: { const debouncedScrollTop = debounce(onChatScrollTop, 500) + let lastScrollTop = 0 const handleScroll = () => { - userHasScrolledUp.value = !isNearBottom() + const el = scrollContainer.value + if (el) { + const currentTop = el.scrollTop + // Only an actual upward scroll detaches from the live edge. Content that + // grows after a chunk (images, diagrams) keeps scrollTop fixed and would + // otherwise fire a stale scroll event that falsely marks the user as + // scrolled up, killing the auto-follow during streaming. + if (currentTop < lastScrollTop - 1) { + userHasScrolledUp.value = !isNearBottom() + } else if (isNearBottom()) { + userHasScrolledUp.value = false + } + lastScrollTop = currentTop + } debouncedScrollTop() } diff --git a/frontend/src/views/chat/index.vue b/frontend/src/views/chat/index.vue index 21653a20..89c29378 100644 --- a/frontend/src/views/chat/index.vue +++ b/frontend/src/views/chat/index.vue @@ -421,8 +421,22 @@ const onChatScrollTop = () => { } } const debouncedScrollTop = debounce(onChatScrollTop, 500); +let lastScrollTop = 0; const handleScroll = () => { - userHasScrolledUp.value = !isNearBottom(); + const el = scrollContainer.value; + if (el) { + const currentTop = el.scrollTop; + // Only an actual upward scroll detaches from the live edge. Content that + // grows after a chunk (images, diagrams) keeps scrollTop fixed and would + // otherwise fire a stale scroll event that falsely marks the user as + // scrolled up, killing the auto-follow during streaming. + if (currentTop < lastScrollTop - 1) { + userHasScrolledUp.value = !isNearBottom(); + } else if (isNearBottom()) { + userHasScrolledUp.value = false; + } + lastScrollTop = currentTop; + } debouncedScrollTop(); };