Save key of the same item when prepending items in a list #377
shachar731945
started this conversation in
Ideas
Replies: 2 comments 3 replies
-
That's a good observation and indeed, the implementation you suggest would make more sense as a default one. However, it is, indeed, a breaking change. A very small one, but I am trying to stick to not releasing such (at least not intentionally), for the sake of not scaring people away. Can you open a PR? If I gather enough material (or sufficient time passes), I will merge it. Thanks! |
Beta Was this translation helpful? Give feedback.
3 replies
-
This is merged in v2 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
As i have been using the component i have come to notice that when i prepend items in Virtuoso (not grouped or grid mode) even when the same component stays on screen (even in the same place) the key prop of the item increases (by the amount of items that were prepended). This causes the component to un-mount and right then re-mount itself (not re-render). I double checked and the same happens on the example on the virtuoso documentation site about prepending items. This is not the case when appending items. Maybe I don't understand the rational properly, but shouldn't the list have the same key for the same item in the list? I have looked at the code and noticed that maybe the call to
const key = computeItemKey(index)
could be changed to something likeconst key = computeItemKey(index + firstItemIndex || 0)
to achieve this (plus since firstItemIndex should be negative), in the List.tsx and Grid.tsx files. I can make the pull request myself but I would like to know if this is a desirable result from the package? I assume this is a breaking change and may only come into effect in another major version so right now usingcomputeItemKey
may do the trick.Thanks from ahead for the consideration and long read :)
Beta Was this translation helpful? Give feedback.
All reactions