Skip to content

virtualRow will contain one empty item when size is 0 (since v2.2.4) #52

@JReinhold

Description

@JReinhold

Bug Report

I'm experiencing a bug, where when having an empty list (ie. size parameter in useVirtual is 0), the returned virtualRow array still contains a single element. That single element is "empty", as it is an object that only contains a measureRef key, and none of the other keys (index, start, end, size).

Reproduction

I've created a minimal reproduction of the issue at https://codesandbox.io/s/amazing-glade-eo7vw?file=/src/index.js which is a fork of the "Dynamic Rows" example. It starts off with having an empty list, and then after 5 seconds, changes the list to have items. The console log (and the error) shows that we start with an empty virtualRow, and then get correct virtualRows after 5 seconds.
What should happen instead, is that no console logs are present in the beginning, because the virtualRows array should be empty.

Context

I believe this bug was introduced in version 2.2.4 by #48. Downgrading to version 2.2.3 "fixes" the issue. But as the changes in that PR are rather substantial, I haven't been able to pinpoint exactly where the problem is. Pinging @mogelbrod

This might be the same bug as #49.

Workaround

Current workarounds are:

  1. downgrade to version 2.2.3
  2. before mapping through the virtualRows, ensure that you have at least one raw item (and NOT just one virtualRow), eg.
<div>
  {items.length > 0 && rowVirtualizer.virtualItems.map((virtualRow) => {
    ...return rows
  })}
</div>

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions