Fix CollectionView crash when setting SelectedItem then ItemsSource to null on iOS/MacCatalyst#30390
Closed
Fix CollectionView crash when setting SelectedItem then ItemsSource to null on iOS/MacCatalyst#30390
Conversation
…o null Co-authored-by: PureWeen <5375137+PureWeen@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] [iOS/MacCatalyst] Setting SelectedItem Programmatically and Then Immediately Setting ItemsSource to Null Causes a Crash
Fix CollectionView crash when setting SelectedItem then ItemsSource to null on iOS/MacCatalyst
Jul 2, 2025
Member
|
use your copilot instructions on reviewing already open PRs And review this other PR to fix the same issue Modify this PR based on what you learn from that PR |
…dling Co-authored-by: PureWeen <5375137+PureWeen@users.noreply.github.com>
Contributor
Author
I've reviewed PR #29940 and adopted their comprehensive solution instead of my simple null check approach. Their fix is significantly more robust, handling multiple race conditions including reference changes, disposal states, and collection modifications. Applied the same pattern to both SelectableItemsViewController files and updated tests accordingly. Changes committed in 31dafb7. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Description
This PR fixes a crash that occurs on iOS and MacCatalyst when programmatically setting the
SelectedItemproperty of aCollectionViewand then immediately setting theItemsSourceproperty tonull.Problem
The issue was caused by a race condition in the
SelectItemmethod ofSelectableItemsViewController:ItemsSourceis null at the beginningPerformBatchUpdateswith a callback to select the itemItemsSourcecan be set to nullSolution
Added a null check inside the
PerformBatchUpdatescallback to ensure we don't attempt to select an item when theItemsSourceis null:Testing
Issue29937that reproduces the crash scenarioImpact
ClearSelectionandUpdatePlatformSelectionFixes #29937.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.