Skip to content

Commit

Permalink
Gate the preferItemReloadsForSectionReloads only to use when there is…
Browse files Browse the repository at this point in the history
… no change to the number of sections

Summary:
There are some crashes related to this path when the number of sections are changed when using the `preferItemReloadsForSectionReloads` optimization for item reloads.

For now, this change would just limit the flag only useable when the section count is unchanged. The proper fix would be finding a repro-case for the unsafe trace.
The follow-up here is adding more logging to capture the crash reason and investigate any variable that leads to this crash.

Reviewed By: calimarkus

Differential Revision: D12828061

fbshipit-source-id: 040e66c051c54f889ee9fbc3e4a48ab6bf93e162
  • Loading branch information
lorixx authored and facebook-github-bot committed Oct 29, 2018
1 parent 0efb259 commit c1bf5f1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
5 changes: 3 additions & 2 deletions Source/IGListAdapterUpdater.m
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,9 @@ - (IGListBatchUpdateData *)_flushCollectionView:(UICollectionView *)collectionVi
moves = [NSSet new];
}

// Item reloads are not safe, if any section moves happened
if (moves.count == 0 && self.preferItemReloadsForSectionReloads) {
// Item reloads are not safe, if any section moves happened or there are inserts/deletes.
if (self.preferItemReloadsForSectionReloads
&& moves.count == 0 && inserts.count == 0 && deletes.count == 0 && reloads.count > 0) {
[reloads enumerateIndexesUsingBlock:^(NSUInteger sectionIndex, BOOL * _Nonnull stop) {
NSMutableIndexSet *localIndexSet = [NSMutableIndexSet indexSetWithIndex:sectionIndex];
if (sectionIndex < [collectionView numberOfSections]
Expand Down
8 changes: 4 additions & 4 deletions Tests/IGListAdapterUpdaterTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -869,15 +869,15 @@ - (void)test_whenReloadIsCalledWithSectionMoveAndUpdate_withThreeSections_delete
[mockDelegate verify];
}

- (void)test_whenReloadIsCalledWithSectionInsertAndUpdate_andPreferItemReload_orderHappened {
- (void)test_whenReloadIsCalledWithSectionInsertAndUpdate_andPreferItemReload_noItemReloads {
self.updater.preferItemReloadsForSectionReloads = YES;

IGListBatchUpdateData *expectedBatchUpdateData = [[IGListBatchUpdateData alloc] initWithInsertSections:[NSIndexSet indexSetWithIndex:1]
deleteSections:[NSIndexSet new]
IGListBatchUpdateData *expectedBatchUpdateData = [[IGListBatchUpdateData alloc] initWithInsertSections:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 2)]
deleteSections:[NSIndexSet indexSetWithIndex:0]
moveSections:[NSSet new]
insertIndexPaths:@[]
deleteIndexPaths:@[]
updateIndexPaths:@[[NSIndexPath indexPathForItem:0 inSection:0]]
updateIndexPaths:@[]
moveIndexPaths:@[]];
NSArray<IGSectionObject *> *from = @[[IGSectionObject sectionWithObjects:@[@1] identifier:@"id1"]];
NSArray<IGSectionObject *> *to = @[[IGSectionObject sectionWithObjects:@[@2] identifier:@"id1"],
Expand Down

0 comments on commit c1bf5f1

Please sign in to comment.