Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions packages/ui/src/__tests__/transcript-scroll-authority.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,25 @@ test('a scroll event that arrives late is still this authority\'s own write', ()
});
});

test('growth a late echo already sees still explains the offset move after it', () => {
withObservers((resize) => {
const root = fakeRoot({ scrollHeight: 3_523, clientHeight: 860 });
const authority = createTranscriptScrollAuthority();
authority.attach(root as unknown as HTMLElement);

// Content grew before the write's echo landed, then the offset moved by
// less than that growth: content, not the reader.
root.grow(600);
root.emitScroll();
root.scrollTop += 91;
root.emitScroll();
assert.equal(authority.getSnapshot().pinned, true);

resize();
assert.equal(root.scrollTop, 3_263);
});
});

test('growth that outruns the write does not read as the reader scrolling up', () => {
withObservers((resize) => {
const root = fakeRoot();
Expand Down
4 changes: 1 addition & 3 deletions packages/ui/src/transcript-scroll-authority.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,8 @@ export function createTranscriptScrollAuthority(): TranscriptScrollAuthority {
// scrollers (a tool output box, a terminal) never reach here at all:
// `scroll` does not bubble, and there is no `wheel` listener to catch
// instead.
// Growth this echo already sees has not reached the observer yet.
if (lastWrittenTop !== undefined && Math.abs(target.scrollTop - lastWrittenTop) < 1) {
lastScrollHeight = target.scrollHeight;
lastClientHeight = target.clientHeight;
lastScrollTop = target.scrollTop;
return;
}
// Content moves the offset too, and only ever by how much the end of
Expand Down
Loading