ra1028 / DiffableDataSources

💾 A library for backporting UITableView/UICollectionViewDiffableDataSource.
https://ra1028.github.io/DiffableDataSources
Apache License 2.0
849 stars 68 forks source link

Incorrect items applied on a collection view after data filtering #41

Closed rafaelnobrekz closed 1 year ago

rafaelnobrekz commented 1 year ago

Checklist

Expected Behavior

Applying two sets of trivial data to a collectionview, I expect the UI to match it in all cases - or at least understand which exceptional cases I should guard against and work them around as needed.

Current Behavior

Filtering a simple model array to a particular state makes the collection view fail to display them correctly, whereas the apple implementation does it.

Steps to Reproduce

  1. Create a snapshot from an array of Hashable models that combines the state from an array of model objects (simple id/title strings) and a isFavorite boolean value)
  2. Given a state0 (full list), filter it into state1 (filtered by some criteria)
  3. Filter it again into state1 (different, non-exclusive criteria)
  4. Toggle applying state1 and state2 to the table view. Going from state1 -> state2 yield different changesets every time you run it, most of the time resulting in wrong state

The collection view shows more items after snapshot from state2 being applied, than the actual array/snapshot has. The indexes get mixed up between what you tap and what is in the source array

Detailed Description (Include Screenshots)

I don't understand the cause exactly.

Reproducible Demo Project

https://github.com/rafaelnobrekz/DiffableBugRepro

Environments

rafaelnobrekz commented 1 year ago

Actually the bug can be fixed by using the diffable item provided by the data source provider handler instead of looking up the source array from the index 🤦‍♂️