Skip to content

v3.13.8 doesn't scroll all the way to the bottom correctly #1001

Closed
@iscekic

Description

@iscekic

Describe the bug

There seems to be a regression in v3.13.8 vs v3.13.7 - exact same code in both cases:

// somewhere above
const measureElement: Parameters<typeof useVirtualizer>[0]["measureElement"] = (
  element,
) => element.getBoundingClientRect().height;

const estimateSize = () => 72;

const virtualizer = useVirtualizer({
  count: messages?.length || 0,
  getScrollElement: () => parentRef.current,
  estimateSize,
  measureElement,
  getItemKey: (index: number) =>
    messages?.[index] ? idExtractor(messages[index]) : nanoid(),
});

// somewhere below
const lastBeforeDateIndex = messages.length - 1; // this is a bit more complicated in the actual code, but most often resolves to this

// some other irrelevant logic, including a getVirtualItemForOffset call

virtualizer.scrollToIndex(Math.max(lastBeforeDateIndex, 0), {
  align: "start",
  behavior: "smooth",
});

For context, I have an infinite list in which items (messages) are occasionally appended. The items themselves have a dynamic size. When an item is appended, the list should be scrolled all the way to the bottom, so that the last item is visible.

Your minimal, reproducible example

/

Steps to reproduce

/

Expected behavior

3.13.8 retains the same behavior as 3.13.7

How often does this bug happen?

Every time

Screenshots or Videos

3.13.7 - scrolls correctly, bottom of last item is visible

Image

3.13.8 - doesn't scroll correctly, last item is cut off

Image

Platform

Brave on Linux, though it seems to reproduce everywhere

tanstack-virtual version

v3.13.8

TypeScript version

v5.8.3

Additional context

No response

Terms & Code of Conduct

  • I agree to follow this project's Code of Conduct
  • I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions