From fef95b9e56855707cc13e5dc1220193352bc4bc1 Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Fri, 13 Mar 2026 03:05:09 -0700 Subject: [PATCH] UI: Fix an autoscroll race condition during chat streaming --- js/main.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/js/main.js b/js/main.js index 0bc76b2a..135aa948 100644 --- a/js/main.js +++ b/js/main.js @@ -145,6 +145,7 @@ targetElement.classList.add("pretty_scrollbar"); targetElement.classList.add("chat-parent"); window.isScrolled = false; let scrollTimeout; +let isProgrammaticScroll = false; targetElement.addEventListener("scroll", function() { let diff = targetElement.scrollHeight - targetElement.clientHeight; @@ -157,9 +158,10 @@ targetElement.addEventListener("scroll", function() { if(isAtBottomNow) { window.isScrolled = false; - } else { + } else if (!isProgrammaticScroll) { window.isScrolled = true; } + isProgrammaticScroll = false; // Clear previous timeout and set new one clearTimeout(scrollTimeout); @@ -193,6 +195,7 @@ const observer = new MutationObserver(function(mutations) { if (!window.isScrolled && !isScrollingClassOnly) { const maxScroll = targetElement.scrollHeight - targetElement.clientHeight; if (maxScroll > 0 && targetElement.scrollTop < maxScroll - 1) { + isProgrammaticScroll = true; targetElement.scrollTop = maxScroll; } } @@ -1091,6 +1094,7 @@ document.fonts.addEventListener("loadingdone", (event) => { if (!window.isScrolled) { const maxScroll = targetElement.scrollHeight - targetElement.clientHeight; if (targetElement.scrollTop < maxScroll - 5) { + isProgrammaticScroll = true; targetElement.scrollTop = maxScroll; } }