Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when adding a section before view appears #8

Open
JosephDuffy opened this issue Sep 7, 2020 · 3 comments
Open

Crash when adding a section before view appears #8

JosephDuffy opened this issue Sep 7, 2020 · 3 comments
Labels
bug Something isn't working

Comments

@JosephDuffy
Copy link
Member

Describe the bug

When adding a section to a ComposedSectionProvider in a viewDidLoad after the CollectionCoordinator has been set as the delegate but before the view has appeared the coordinator will fatalError in elementsProvider(for:) with error Fatal error: No UI configuration available for section 2.

To Reproduce

  1. Checkout https://github.com/composed-swift/Composed-Demo/tree/ComposedSectionProvider-crash-example
  2. Uncomment https://github.com/composed-swift/Composed-Demo/blob/ComposedSectionProvider-crash-example/Composed-Demo/Collection/PeopleCollectionViewController.swift#L20

Expected behavior

Should not crash

Environment

  • OS Version: iOS 13.5, iOS 14 beta 7
  • Library Version: 1.0.2
  • Device: iPhone 8 Simulator

Additional context

The crash is triggered by collectionView.performBatchUpdates, but the closure is never executed so prepareSections never gets a chance to be called.

@JosephDuffy JosephDuffy added the bug Something isn't working label Sep 7, 2020
@shaps80
Copy link
Collaborator

shaps80 commented Sep 9, 2020

Any suggested fix? I kinda get the issue, but I'm not sure off-hand the most appropriate fix. Seems we'd need to know somehow that its 'detached'? Or perhaps I'm misunderstand the issue?

@shaps80
Copy link
Collaborator

shaps80 commented Sep 11, 2020

Is this resolved from the PR I just merged related to performBatchUpdates or is this a separate issue?

@JosephDuffy
Copy link
Member Author

Is this resolved from the PR I just merged related to performBatchUpdates or is this a separate issue?

I tried the change but it didn't fix this. It could be something similar though so worth thinking about.

JosephDuffy added a commit that referenced this issue Nov 3, 2020
As mentioned in #13 and #8 there are some scenarios where the collection view’s data is out-of-sync with the data in composed.

As mentioned in #13 calling `layoutIfNeeded` can trigger the data to be in sync again. In this I have added it to `mappingWillBeginUpdating(_:)` which _appears_ to solve the problem.

It might be needed in `replace(sectionProvider:)` (because `reloadData` is called) and/or `mappingDidInvalidate(_:)` (for the same reason) but I’m still investigating.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

2 participants