Skip to content

Commit 9a0a461

Browse files
authored
fix: Updating selection and contents at the same time can leads to hangs (#17)
I've noticed that it's possible to cause a hang when updating the contents and selection at the same time. This works around that by asynchronously dispatching the selection set back to the main queue to break the (assumed) dependency loop.
1 parent 9ef34bb commit 9a0a461

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

Sources/SelectableCollectionView/Views/CollectionViewContainer.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,12 @@ public class CollectionViewContainer<Element: Hashable, Content: View>: NSView,
175175
let indexPaths = selection.compactMap { element in
176176
return dataSource?.indexPath(for: element)
177177
}
178-
collectionView.selectionIndexPaths = Set(indexPaths)
178+
179+
// Updating the selection at the same time as the items seems to cause some form of loop or deadlock, so we
180+
// break that by dispatching back to the main queue.
181+
DispatchQueue.main.async {
182+
self.collectionView.selectionIndexPaths = Set(indexPaths)
183+
}
179184

180185
}
181186

0 commit comments

Comments
 (0)