-
Couldn't load subscription status.
- Fork 1.9k
[iOS] Fix App crash with NullReferenceException in ShellSectionRenderer #32109
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
base: main
Are you sure you want to change the base?
[iOS] Fix App crash with NullReferenceException in ShellSectionRenderer #32109
Conversation
| args.NavigationType == NavigationType.PopToRoot) | ||
| { | ||
| // Don't dispose Handlers too early on iOS! | ||
| // iOS aggressively cleans up page Handlers during navigation, but if the page |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is only required on iOS? Because this is a cross platform code that will run same on other platforms.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jsuarezruiz , I've added the fix only for iOS platform
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes an iOS-specific NullReferenceException crash in ShellSectionRenderer that occurs during modal navigation. The root cause was premature Handler disposal when iOS's OnUnloaded mechanism triggered during navigation transitions, disposing Handlers for pages still accessible via back navigation in the Shell stack.
Key Changes:
- Added Shell navigation stack validation before Handler disposal on iOS to prevent premature cleanup
- Added comprehensive UI tests demonstrating the crash scenario and validating the fix
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/Controls/src/Core/Page/Page.cs | Adds iOS-specific check to prevent Handler disposal when page remains in Shell navigation stack |
| src/Controls/tests/TestCases.HostApp/Issues/Issue31961.cs | Implements UI test page demonstrating modal + Shell navigation interaction |
| src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue31961.cs | Implements Appium test validating the fix through automated UI interaction |
| } | ||
| } | ||
| #endif | ||
|
|
Copilot
AI
Oct 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing whitespace should be removed from the blank line.
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!
Issue Details
In the ShellSectionRenderer class, the ElementForViewController method is used to find the corresponding .NET MAUI page for a given ViewController.
While traversing the entire ShellSection stack to locate the respective page, a push and pop modal operation causes Page1’s handler to become null.
Root Cause
iOS OnUnloaded mechanism fires immediately during navigation transitions, triggering premature Handler disposal before checking if the page is still accessible for back navigation.
Description of Change
In Page.cs, added Shell navigation stack check in SendNavigatedFrom() to prevent Handler disposal when page is still in stack
Issues Fixed
Fixes #31961
Tested the behavior in the following platforms.
Output Screenshot
Before.mov
After.mov