Skip to content

Commit f14dd9f

Browse files
committed
Comment why layoutIsNeeded is called
1 parent 8f0d651 commit f14dd9f

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

Sources/ComposedUI/CollectionView/CollectionCoordinator.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,13 @@ extension CollectionCoordinator: SectionProviderMappingDelegate {
217217
public func mappingWillBeginUpdating(_ mapping: SectionProviderMapping) {
218218
reset()
219219
defersUpdate = true
220+
221+
// This is called here to ensure that the collection view's internal state is in-sync with the state of the
222+
// data in hierarchy of sections. If this is not done it can cause various crashes when `performBatchUpdates` is called
223+
// due to the collection view requesting data for sections that no longer exist, or crashes because the collection view is
224+
// told to delete/insert from/into sections that it does not yet think exist.
225+
//
226+
// For more information on this see https://github.com/composed-swift/ComposedUI/pull/14
220227
collectionView.layoutIfNeeded()
221228
}
222229

0 commit comments

Comments
 (0)