Count the far end of the list in rows, not events
Scrolling back stopped dead at the top of what was loaded, and no older page ever arrived. Bryan spotted the cause from the outside: it had to do with tool calls being collapsed. The trigger compared an index into the list being drawn against `items.size`, the number of transcript events. Those were the same number when it was written. They stopped being the same when adjacent tool calls started folding into one row, and the queued bubble and the working indicator are two more rows with no event behind them. In this session 645 rows stood in for 720 events, so the last visible index could reach 646 and the threshold it needed was 717. It was not close; it was unreachable, and the further a session went the worse it got. Both numbers now come from the list itself, which is the only place they are commensurable, and `totalItemsCount` counts whatever gets added to it next. Checked on the emulator against the case it was breaking on rather than a clean one: five collapsed "Called 8 tools" groups in front of a 720-event transcript, scrolled from the bottom to seq 1, which is the beginning of the session. It stops there because that is the top, and holds position while each page arrives.
This commit is contained in:
1 parent
fc71cb4403
commit
f18639e4b1
1 file changed
+16
-5
@@ -449,11 +449,22 @@ fun SessionScreen(
|
||||
}
|
||||
// Reaching the far end of what is loaded -- the oldest item, which in
|
||||
// this layout is the last index -- fetches the page before it.
|
||||
LaunchedEffect(listState, items.size, moreHistory) {
|
||||
snapshotFlow { listState.layoutInfo.visibleItemsInfo.lastOrNull()?.index ?: 0 }
|
||||
.collect { last ->
|
||||
if (!moreHistory || loadingHistory || items.isEmpty()) return@collect
|
||||
if (last < items.size - 3) return@collect
|
||||
//
|
||||
// Both numbers come from the list itself, and that is the point: an index into what is drawn
|
||||
// can only be compared against how much is drawn. Three things already make that differ from
|
||||
// the event count -- a run of adjacent tool calls is one row, and the queued bubble and the
|
||||
// working indicator are rows with no event behind them at all -- so measuring the far end in
|
||||
// events meant the threshold could not be reached, and a session with tool calls in it simply
|
||||
// stopped scrolling back. Anything added to this list later is a fourth, and totalItemsCount
|
||||
// already counts it.
|
||||
LaunchedEffect(listState, rows.size, moreHistory) {
|
||||
snapshotFlow {
|
||||
val layout = listState.layoutInfo
|
||||
Pair(layout.visibleItemsInfo.lastOrNull()?.index ?: 0, layout.totalItemsCount)
|
||||
}
|
||||
.collect { (last, total) ->
|
||||
if (!moreHistory || loadingHistory || total == 0) return@collect
|
||||
if (last < total - 3) return@collect
|
||||
loadingHistory = true
|
||||
try {
|
||||
val older =
|
||||
|
||||
Reference in new issue
Block a user