How to refresh tree grid selection?

I am currently running into this bug:

After calling refreshAll(), selected items remain selected(as they should), but there is outdated data in the selection afterwards.

Now i want to write a workaround for that by manually updating the selection. I am using this:

grid.asMultiSelect().setValue(items);

Unfortunately, this does not work, because internally items already inside the selection are filtered before performing the actual update of the selection model.

So, is there an API to achieve this? Please consider this:

Deselect + Select is not an option, because that would trigger the selection event twice and update other SelectionGrids. SelectionGrid does not handle multiple updates at the same time very well. It would be fine if the selection event is not triggered at all.

There is no built-in support for that at the moment. All the selection state of the component tells you is which items are selected, based on their identity. It does not guarantee that the items data is up to date. Implementing that would also present some challenges when it comes to lazy loading data providers, as the component would need to fetch all data in order to map old to new items. Since that is a no-go, that would likely require additional API in data providers that would allow users to implement such a mapping function.

Which is basically what you can do right now as a workaround. Take the selected items from the grid and match them against your current data based on their identity to get a “live selection” with up-to-date data. If you need to call that function often, and matching items is a slow operation, consider caching the live selection data and invalidate the cache on selection change events.