Skip to content

Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.

feat(frontend): enhance chat scroll handling for improved user experience

wizardchenc6b5d2e77bd5
diff --git a/frontend/src/composables/useEmbedChatSession.ts b/frontend/src/composables/useEmbedChatSession.ts
index 4734abc33..3ebff793c 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 21653a20c..89c293783 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();
};