Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/Core/src/Platform/Android/Navigation/NavigationRootManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,20 @@ void ClearPlatformParts()
_pendingFragment?.Dispose();
_pendingFragment = null;
if (_rootView is ContainerView containerView)
{
// Clearing CurrentView below synchronously detaches the DrawerLayout that hosts
// navigationlayout_content. Flush pending fragment transactions first so a queued
// FlyoutView detail Replace doesn't run against a missing container and crash.
var fragmentManager = _mauiContext?.GetFragmentManager();
if (fragmentManager is not null &&
!fragmentManager.IsDestroyed(_mauiContext?.Context) &&
!fragmentManager.IsStateSaved)
{
fragmentManager.ExecutePendingTransactionsEx();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Android fragment correctness / Reliability — two concerns flagged by all three reviewers on this ExecutePendingTransactionsEx() call:

1. Re-entrancy crash. executePendingTransactions() throws IllegalStateException: Recursive entry to executePendingTransactions if the FragmentManager is already executing transactions — a hazard this repo already tracks (Bugzilla40333). ClearPlatformParts() runs from both Connect() and Disconnect(), which are reachable from fragment-driven teardown (e.g. a ModalNavigationManager dismiss whose modal content is a FlyoutPage). The IsDestroyed/IsStateSaved guards do not protect against this. If you keep the drain here, guard it:

try
{
    fragmentManager.ExecutePendingTransactionsEx();
}
catch (Java.Lang.IllegalStateException)
{
    // Already executing transactions on this FragmentManager;
    // the pending detail Replace will complete on its own.
}

2. Global blast radius. _mauiContext.GetFragmentManager() resolves to the activity-level SupportFragmentManager, which is shared with StackNavigationManager, modal, and tabbed navigation. ExecutePendingTransactions() synchronously flushes every pending transaction app-wide — not just this FlyoutView's detail Replace — forcing unrelated fragment lifecycle work (e.g. an in-flight animated navigation) to run mid-teardown.

The lower-risk, root-cause-aligned alternative is to settle the detail transaction in its owner (FlyoutViewHandler), scoped to that one transaction, rather than a global drain from NavigationRootManager.

Flagged by: 3/3 reviewers (one rated the re-entrancy must-fix).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PureWeen

  1. Re-entrancy: I tried to reproduce the recursive ExecutePendingTransactions crash across multiple paths — modal FlyoutPage open/swap/dismiss, nested modals, and FlyoutPage → FlyoutPage root swaps (instrumented with a drain-depth counter). The drain was never re-entered, and I could not reproduce the crash. Based on this, no additional handling is being added for now.

  2. Global blast radius: Verified through FragmentManager identity logging that the modal path uses a scoped child FragmentManager, while StackNavigationManager uses its own. In all tested scenarios, the drain never flushed unrelated navigation and only settled the FlyoutPage’s own pending detail Replace, so the effective scope remains limited.

Based on the above validation, both concerns are currently considered low risk and are not being addressed in this fix.

}

containerView.CurrentView = null;
}

DrawerLayout = null;
_rootView = null;
Expand Down
Loading