Skip to content

Commit 62be2a2

Browse files
committed
fix(ui): keep forced chat scroll above follow lock
1 parent 749d3e8 commit 62be2a2

2 files changed

Lines changed: 22 additions & 6 deletions

File tree

ui/src/ui/app-scroll.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,24 @@ describe("scheduleChatScroll", () => {
232232
expect(container.scrollTop).toBe(container.scrollHeight);
233233
});
234234

235+
it("uses force=true on initial load even after a previous follow lock", async () => {
236+
const { host, container } = createScrollHost({
237+
scrollHeight: 2000,
238+
scrollTop: 500,
239+
clientHeight: 400,
240+
});
241+
host.chatUserNearBottom = false;
242+
host.chatFollowLocked = true;
243+
host.chatHasAutoScrolled = false;
244+
245+
scheduleChatScroll(host, true);
246+
await host.updateComplete;
247+
248+
expect(container.scrollTop).toBe(container.scrollHeight);
249+
expect(host.chatFollowLocked).toBe(false);
250+
expect(host.chatNewMessagesBelow).toBe(false);
251+
});
252+
235253
it("sets chatNewMessagesBelow when not scrolling due to user position", async () => {
236254
const { host } = createScrollHost({
237255
scrollHeight: 2000,

ui/src/ui/app-scroll.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,9 @@ export function scheduleChatScroll(
8686
manualScroll ||
8787
autoScrollMode === "always" ||
8888
(autoScrollMode === "near-bottom" &&
89-
!host.chatFollowLocked &&
9089
(effectiveForce ||
91-
host.chatUserNearBottom ||
92-
distanceFromBottom < NEAR_BOTTOM_THRESHOLD));
90+
(!host.chatFollowLocked &&
91+
(host.chatUserNearBottom || distanceFromBottom < NEAR_BOTTOM_THRESHOLD))));
9392

9493
if (!shouldStick) {
9594
// User is scrolled up — flag that new content arrived below.
@@ -132,10 +131,9 @@ export function scheduleChatScroll(
132131
manualScroll ||
133132
autoScrollMode === "always" ||
134133
(autoScrollMode === "near-bottom" &&
135-
!host.chatFollowLocked &&
136134
(effectiveForce ||
137-
host.chatUserNearBottom ||
138-
latestDistanceFromBottom < NEAR_BOTTOM_THRESHOLD));
135+
(!host.chatFollowLocked &&
136+
(host.chatUserNearBottom || latestDistanceFromBottom < NEAR_BOTTOM_THRESHOLD))));
139137
if (!shouldStickRetry) {
140138
return;
141139
}

0 commit comments

Comments
 (0)