scrollToIndex align:'end' to LAST lands mid-list when the last item is not yet measured
Summary
When scrolling to { index: 'LAST', align: 'end' } (the path used by followOutput and by initialTopMostItemIndex: 'LAST'), the target offset is computed from the measured size of the target item:
if (align === 'end') {
top += fixedHeaderHeight + findMaxKeyValue(sizes.sizeTree, index)[1]! - viewportHeight + fixedFooterHeight
...findMaxKeyValue(sizes.sizeTree, index)[1] returns the last item's size. If that item has not been measured yet (variable-height content such as images or long text in a chat/message list), the size falls back to the default item size, so top is computed too small and the list lands mid-list instead of at the bottom.
There is a retry on listRefresh (with a 1200ms cleanup) and initialTopMostItemIndexSystem waits skipFrames(4), which usually corrects the position — but in chat-style lists the wrong intermediate position is visible as a flash, and in some timing cases the list settles short of the true bottom.
Repro (sketch)
- Render a
Virtuoso/ message list withfollowOutput(orinitialTopMostItemIndex={{ index: 'LAST', align: 'end' }}). - Make the last few items tall and unmeasured at mount (e.g. images that load, or long text), with a default item size much smaller than the real size.
- On open, the list scrolls to roughly the default-size offset (mid-list), then jumps once the real sizes are measured.
Question
Would the maintainers be open to a fix here — e.g. when align === 'end' and the target item is unmeasured, defer the offset computation until the item's real size is known, or recompute top against the measured size in the retry rather than re-running the same default-based calculation? Happy to open a PR if there's a preferred direction.
This is a follow-up to the clamping work in #1442 / #1444 around the same scroll path.
Source: petyosi/react-virtuoso