React-window: [DynamicSizeList] Wrong positions after adding/removing items from the list

Created on 12 Jul 2019  Â·  10Comments  Â·  Source: bvaughn/react-window

I’m experimenting with the branch #102.

Almost everything works well.

I’m facing a problem when the list items change:

  1. Render list with initial items (ok)
  2. Remove the second item
  3. See some items get positioned wrong

See the blank space between items after filtering out the item that contains the word “progress”:

Kapture 2019-07-11 at 21 59 27

After I scroll past this blank space and go back, it get’s fixed.

I also noticed the items get wrong positions if new items are added to the list.

See wrong spacing after first item and cut off bottom buttons of the second item:

image

_I don’t have a small reproducible demo, but the gif above is from this branch_

I check and confirmed the props being passed to DynamicSizeList are being updated correctly (itemCount changes and this.getItemKey(2) get the the new id), so I believe it’s some react-window internal, probably related to the cache.

Most helpful comment

@nihgwu resetAfterIndex does not exist for DynamicSizeList
https://react-window-next.now.sh/#/api/DynamicSizeList

All 10 comments

did you call resetAfterIndex after removed item?

@nihgwu resetAfterIndex does not exist for DynamicSizeList
https://react-window-next.now.sh/#/api/DynamicSizeList

@brunolemos by any chance are your list items class components that override shouldComponentUpdate?

are your list items class components that override shouldComponentUpdate?

nope

@brunolemos
I think need install polyfill ResizeObserver
For information https://react-window-next.now.sh/#/examples/list/dynamic-size
https://caniuse.com/#search=ResizeObserver

I use the polyfill already

Hi there. Same problem, can i drop cache of items? Maybe add resetAfterIndex to DynamicSizeList?
Thanks
ps. i'm using ResizeObserver polyfill too

Just wanted to inform that I have the same issue.

In my case, the dimensions of a list item change due to the filtering. I think the itemSize calculation should re-triggered somehow.

How about adding key={Math.random()} to your DynamicSizeList? It forces to initialize the component at every rendering.

How about adding key={Math.random()} to your DynamicSizeList? It forces to initialize the component at every rendering.

This actually works but with one flaw. If you are adding items to the list and you are scrolled down (not on top of the list) then each addition/change to the list will rerender the List and reset the position to top. So unusable for my use case where I am sequentially fetching data from an API while the user should be able to scroll in the list and use filters for the list.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

davalapar picture davalapar  Â·  3Comments

marian-c picture marian-c  Â·  3Comments

maynir picture maynir  Â·  4Comments

ashishgupta1989 picture ashishgupta1989  Â·  4Comments

Kizmar picture Kizmar  Â·  3Comments