Skip to content

Commit e6fa3a4

Browse files
authored
Fix assertion failure regression in iOS < 26 (#1282)
1 parent d658086 commit e6fa3a4

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

Zotero/Scenes/Detail/ItemDetail/Views/ItemDetailCollectionViewHandler.swift

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ final class ItemDetailCollectionViewHandler: NSObject {
463463
let animated = false
464464
dataSource.apply(snapshot, animatingDifferences: animated) { [weak self] in
465465
// Per-section applications are chained sequentially. After the final application isEditing is set and completion is called.
466-
self?.applySectionSnapshots(at: 0, in: sections, state: state, animated: animated, completion: completion)
466+
self?.continueApplyingSectionSnapshots(at: 0, in: sections, state: state, animated: animated, completion: completion)
467467
}
468468

469469
/// Creates array of visible sections for current state data.
@@ -646,6 +646,18 @@ final class ItemDetailCollectionViewHandler: NSObject {
646646
dataSource.apply(snapshot, animatingDifferences: false)
647647
}
648648

649+
private func continueApplyingSectionSnapshots(at index: Int, in sections: [SectionType], state: ItemDetailState, animated: Bool, completion: (() -> Void)?) {
650+
if #available(iOS 26.0, *) {
651+
applySectionSnapshots(at: index, in: sections, state: state, animated: animated, completion: completion)
652+
} else {
653+
// Older iOS versions crash with assertion failure in -[__UIDiffableDataSource _performOnApplyQueue:]
654+
// with reason: 'Deadlock detected: calling this method on the main queue with outstanding async updates is not permitted and will deadlock.'
655+
DispatchQueue.main.async { [weak self] in
656+
self?.applySectionSnapshots(at: index, in: sections, state: state, animated: animated, completion: completion)
657+
}
658+
}
659+
}
660+
649661
private func applySectionSnapshots(at index: Int, in sections: [SectionType], state: ItemDetailState, animated: Bool, completion: (() -> Void)?) {
650662
guard index < sections.count else {
651663
collectionView.isEditing = state.isEditing
@@ -655,7 +667,7 @@ final class ItemDetailCollectionViewHandler: NSObject {
655667
let section = sections[index]
656668
let snapshot = sectionSnapshot(for: section.section, state: state)
657669
dataSource.apply(snapshot, to: section, animatingDifferences: animated) { [weak self] in
658-
self?.applySectionSnapshots(at: index + 1, in: sections, state: state, animated: animated, completion: completion)
670+
self?.continueApplyingSectionSnapshots(at: index + 1, in: sections, state: state, animated: animated, completion: completion)
659671
}
660672
}
661673

0 commit comments

Comments
 (0)