Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VariableSizeList can call itemSize getter with an invalid index #62

Closed
chrisnojima opened this issue Sep 27, 2018 · 4 comments
Closed

Comments

@chrisnojima
Copy link

Hey,

I recently ported a list over to react-window and I noticed that under certain circumstances the itemSize callback can be called with an invalid index.

My code is basically

                <VariableSizeList
                  height={height}
                  width={width}
                  ref={this._setRef}
                  onItemsRendered={this._onItemsRendered}
                  itemCount={this.props.rows.length}
                  itemSize={this._itemSizeGetter}
                  estimatedItemSize={56}
                >
...
  _itemSizeGetter = index => {
    if (this.props.filter.length) {
      return 56
    }
    const row = this.props.rows[index]

so itemCount is based on this.props.rows so that should always be synced up.

From what I've seen itemCount is 0 and since (https://github.com/bvaughn/react-window/blob/master/src/VariableSizeList.js#L42)

    for (let i = lastMeasuredIndex + 1; i <= index; i++) {
      let size = ((itemSize: any): itemSizeGetter)(i);

the i <= index allows this to be out of bounds

@bvaughn
Copy link
Owner

bvaughn commented Oct 1, 2018

Hi. Can you provide a full repro case please? Either a test or a Code Sandbox would do. This issue doesn't have enough info to be actionable as is.

@chrisnojima
Copy link
Author

@bvaughn
Copy link
Owner

bvaughn commented Oct 3, 2018

Ah, so the specific problem is when you pass an itemCount of zero.

Fixed in c560b18. Will be released in a bugfix shortly.

@bvaughn bvaughn closed this as completed Oct 3, 2018
@bvaughn
Copy link
Owner

bvaughn commented Oct 3, 2018

Published in 1.2.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants