Skip to content

Conversation

@devanathan-vaithiyanathan
Copy link
Contributor

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.

  • Android
  • Windows
  • iOS
  • Mac

Output Screenshot

Before After
iOS
Before.mov
iOS
After.mov

@dotnet-policy-service dotnet-policy-service bot added community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration labels Oct 21, 2025
@jsuarezruiz jsuarezruiz added the area-controls-shell Shell Navigation, Routes, Tabs, Flyout label Oct 22, 2025
args.NavigationType == NavigationType.PopToRoot)
{
// Don't dispose Handlers too early on iOS!
// iOS aggressively cleans up page Handlers during navigation, but if the page
Copy link
Contributor

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.

Copy link
Contributor Author

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

@sheiksyedm
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@devanathan-vaithiyanathan devanathan-vaithiyanathan marked this pull request as ready for review October 28, 2025 08:39
Copilot AI review requested due to automatic review settings October 28, 2025 08:39
Copy link
Contributor

Copilot AI left a 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

Copy link

Copilot AI Oct 28, 2025

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.

Suggested change

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-controls-shell Shell Navigation, Routes, Tabs, Flyout community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[iOS] App crash with NullReferenceException in ShellSectionRenderer

3 participants