fix: scrolling up in Firefox jumps when older messages load (#33998)

Scrolling up through a long chat in Firefox kept throwing the view back down while older messages loaded, sometimes by several screens. Firefox does not hold the view in place when messages above it settle to their real height, so it now shows them at full height from the start. When two loads fired back to back it also shifted the view a second time on top of the app's own adjustment, so in every browser the adjustment now follows where the first message sits instead of how much the page grew. Measured on a 150 message chat, scrolling up in 100 px steps: Firefox went from 74 steps where the content jumped (largest jump 1197 px) to 8 steps (largest 123 px); Chromium stays at 3 steps and 101 px.

Fixes #33994
This commit is contained in:
Classic298 authored and GitHub committed 2026-11-16 22:51:29 +09:00
1 parent 3a1a993981
commit 87bdec44c7
2 files changed
+8 -4

No files matched your search

+4 -3
View File
@@ -74,7 +74,8 @@
const loadMoreMessages = async () => {
const element = getMessagesContainer();
const previousScrollHeight = element?.scrollHeight ?? 0;
const firstMessage = element?.querySelector('.message-listitem');
const previousTop = firstMessage?.getBoundingClientRect().top ?? 0;
messagesLoading = true;
messagesCount += 8;
@@ -83,8 +84,8 @@
await tick();
if (element) {
element.scrollTop += element.scrollHeight - previousScrollHeight;
if (element && firstMessage) {
element.scrollTop += firstMessage.getBoundingClientRect().top - previousTop;
}
messagesLoading = false;
@@ -62,6 +62,9 @@
const isWebKit =
navigator.vendor === 'Apple Computer, Inc.' ||
/^((?!chrome|android).)*safari/i.test(navigator.userAgent);
// Firefox scroll anchoring ignores content-visibility height changes, so scrolling up jumps
const isFirefox = /firefox/i.test(navigator.userAgent);
</script>
<div
@@ -69,7 +72,7 @@
class="flex flex-col justify-between px-3.5 mb-3 w-full {($settings?.widescreenMode ?? null)
? 'max-w-full'
: 'max-w-[58rem]'} mx-auto rounded-lg group message-listitem"
class:message-virtualized={!isWebKit && !isCurrentTurn}
class:message-virtualized={!isWebKit && !isFirefox && !isCurrentTurn}
>
{#if history.messages[messageId]}
{#if history.messages[messageId].role === 'user'}