fix: Add row ids to the virtualizer #6481
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
How does this PR change the system?
We were getting a component grid bug when changing the groupby criteria, where the rows would always have the position of the first group criteria selected. This happened because when changing criteria in a way that retained the same count of items, tanstack virtualizer would not recompute sizes.
The trigger for recomputing display data is either the size of the list (that would not change in this case) and a couple of options including the key. Since the key is by default the id of the row, nothing would be done. Adding code to make sure different row types have different keys fixed the issue, after an hour of suffering.
This was not spelled out explicitly in the documentation, so thank god for js libraries being open source. This is where the library spells out its reactivity triggers: https://github.com/TanStack/virtual/blob/2c703821d6f80295fc4da948716c514e9a92c43f/packages/virtual-core/src/index.ts#L614-L638
In short: 🔗