NSInternalInconsistencyException - attempt to insert item 20 into section 3, but there are only 3 sections after the update

From recent days we are facing a serious random crash issue in our iOS app related to UICollectionView. We are having listing page where we have 4 sections with different data model. We have faced the below crash issue which happened all times when we update collection view.

NSInternalInconsistencyException - Invalid update: invalid number of items in section 3. The number of items contained in an existing section after the update (60) must be equal to the number of items contained in that section before the update (40), plus or minus the number of items inserted or deleted from that section (0 inserted, 0 deleted) and plus or minus the number of items moved into or out of that section (0 moved in, 0 moved out).

With below solution

if #available(iOS 15.0, *) {

                    if isPagination {
                        var paths = [IndexPath]()
                        for item in 0..<(localResult.products?.items ?? []).count {
                            let indexPath = IndexPath(row: item + self.productItemData.count, section: 3)
                            paths.append(indexPath)
                        }
                        self.productItemData.append(contentsOf: localResult.products?.items ?? [])
                        self.mainCollectionView?.insertItems(at: paths)
                    } else {
                        self.productItemData.append(contentsOf: localResult.products?.items ?? [])
                    }
                } else {
                    self.productItemData.append(contentsOf: localResult.products?.items ?? [])
                }

With the above solution, crash which happened all times when we update the collection view is resolved. But now, we are facing with another new issue as below and this is happening randomly based on different data set. This crash log is becoming the highest one and its affecting our app performance very seriously. And its happening with mostly above iOS 15. Is there any gap that we missed with latest iOS version update and why its happening without any much code change? Any better solution will be appreciated.

Latest crash details:

NSInternalInconsistencyException - attempt to insert item 20 into section 3, but there are only 3 sections after the update

NSInternalInconsistencyException - Invalid batch updates detected: the number of sections and/or items returned by the data source before and/or after performing the batch updates are inconsistent with the updates.

Data source before updates = { 4 sections with item counts: [1, 1, 1, 340] } Data source after updates = { 4 sections with item counts: [1, 1, 1, 340] } Updates = [ Insert item (3 - 320), Insert item (3 - 321), Insert item (3 - 322), Insert item (3 - 323), Insert item (3 - 324), Insert item (3 - 325), Insert item (3 - 326), Insert item (3 - 327), Insert item (3 - 328), Insert item (3 - 329), Insert item (3 - 330), Insert item (3 - 331), Insert item (3 - 332), Insert item (3 - 333), Insert item (3 - 334), Insert item (3 - 335), Insert item (3 - 336), Insert item (3 - 337), Insert item (3 - 338), Insert item (3 - 339) ]

Please see this answer, which provides more information about the "invalid batch updates detected" exceptions/crashes you are seeing: https://developer.apple.com/forums/thread/728797?answerId=751887022#751887022

NSInternalInconsistencyException - attempt to insert item 20 into section 3, but there are only 3 sections after the update
 
 
Q