Crash in UICollectionViewDiffableDataSource - SupplementaryView

I have a crash happening when applying a snapshot. 9/10 times its seems to work.

When we re-fetch backend data, and apply the snapshot sometimes we get the follow crash

Code Block
the view returned from -collectionView:viewForSupplementaryElementOfKind:atIndexPath (cover-edge-trailing-element-kind,<NSIndexPath: 0xf45fd089cda10b3f> {length = 2, path = 55 - 1}) was not retrieved by calling -dequeueReusableSupplementaryViewOfKind:withReuseIdentifier:forIndexPath: or is nil ((null))


We don't call this function, as it seems to be done by the diffable datasource.

Code Block
Fatal Exception: NSInternalInconsistencyException
0 CoreFoundation 0x1b75c2300 exceptionPreprocess
1 libobjc.A.dylib 0x1b72d6c1c objc_exception_throw
2 CoreFoundation 0x1b74bf1f8 +[_CFXNotificationTokenRegistration keyCallbacks]
3 Foundation 0x1b7903998 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:]
4 UIKitCore 0x1baf133dc -[UICollectionView _createPreparedSupplementaryViewForElementOfKind:atIndexPath:withLayoutAttributes:applyAttributes:]
5 UIKitCore 0x1baf2dc6c -[UICollectionView _viewAnimationsForCurrentUpdate]
6 UIKitCore 0x1baf31d68 71-[UICollectionView _updateWithItems:tentativelyForReordering:animator:]_block_invoke.2004
7 UIKitCore 0x1bbbcf5d8 +[UIView(Animation) performWithoutAnimation:]
8 UIKitCore 0x1baf30f2c -[UICollectionView _updateWithItems:tentativelyForReordering:animator:]
9 UIKitCore 0x1baf2b488 -[UICollectionView _endItemAnimationsWithInvalidationContext:tentativelyForReordering:animator:]
10 UIKitCore 0x1baf32f4c -[UICollectionView _endUpdatesWithInvalidationContext:tentativelyForReordering:animator:]
11 UIKitCore 0x1baf332d0 -[UICollectionView _performBatchUpdates:completion:invalidationContext:tentativelyForReordering:animator:]
12 UIKitCore 0x1baf33100 -[UICollectionView _performBatchUpdates:completion:invalidationContext:tentativelyForReordering:]
13 UIKitCore 0x1baf3307c -[UICollectionView _performBatchUpdates:completion:invalidationContext:]
14 UIKitCore 0x1baf32fa8 -[UICollectionView performBatchUpdates:completion:]
15 UIKitCore 0x1baf41268 -[UICollectionView _performDiffableUpdate:]
16 UIKitCore 0x1baee7e6c -[_UIDiffableDataSourceViewUpdater _performUpdateWithCollectionViewUpdateItems:dataSourceSnapshotter:updateHandler:completion:]
17 UIKitCore 0x1baee10f4 -[UIDiffableDataSource _commitNewDataSource:withViewUpdates:completion:]
18 UIKitCore 0x1baedc0c0 66-[UIDiffableDataSource applyDifferencesFromSnapshot:completion:]_block_invoke.154
19 UIKitCore 0x1baedc388 66-[UIDiffableDataSource applyDifferencesFromSnapshot:completion:]_block_invoke.183
20 libdispatch.dylib 0x1b726233c _dispatch_client_callout
21 libdispatch.dylib 0x1b726f1f4 _dispatch_lane_barrier_sync_invoke_and_complete
22 UIKitCore 0x1baedbba8 -[UIDiffableDataSource applyDifferencesFromSnapshot:completion:]
23 UIKitCore 0x1baedcc68 -[__UIDiffableDataSource applyDifferencesFromSnapshot:animatingDifferences:completion:]
24 libswiftUIKit.dylib 0x1edef8030 UICollectionViewDiffableDataSource.apply(_:animatingDifferences:completion:)
25 theathletic-ios 0x105048b60 closure #1 in RealTimeContentsViewController.fetchData(with:newWatcher:) + 137 (RealTimeContentsViewController.swift:137)
26 theathletic-ios 0x10504b48c RealTimeContentsViewController.updateDataSource(for:completion:) + 265 (RealTimeContentsViewController.swift:265)
27 theathletic-ios


Heres how we are registering, creating, and supplying the view

Code Block
static let coverEdgeTrailingIdentifier = "cover-edge-trailing-element-kind"
        collectionView.register(
            CoverEdgeCollectionReusableView.self,
            forSupplementaryViewOfKind: K.coverEdgeTrailingIdentifier,
            withReuseIdentifier: CoverEdgeCollectionReusableView.reuseIdentifier)


Code Block
dataSource.supplementaryViewProvider = { (
            collectionView: UICollectionView,
            kind: String,
            indexPath: IndexPath) -> UICollectionReusableView? {
return collectionView.dequeueReusableSupplementaryView(
            ofKind: kind,
            withReuseIdentifier: CoverEdgeCollectionReusableView.reuseIdentifier,
            for: indexPath) as! CoverEdgeCollectionReusableView
}

Crash in UICollectionViewDiffableDataSource - SupplementaryView
 
 
Q