Repository navigation
Conversation
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 40124Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 40124" |
This comment has been minimized.
This comment has been minimized.
|
Hey there @@MykhailoDav! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
|
Hey there @MykhailoDav! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| int platformCount = 0; | ||
| NavController.IterateBackStack(_ => platformCount++); | ||
|
|
||
| if (platformCount == 0 || platformCount >= NavigationStack.Count) |
There was a problem hiding this comment.
[major] Logic and Correctness Verification - Host recreation can produce this depth mismatch without a pop. For an initialized [A, B] stack, CheckForFragmentChange installs the graph on the replacement NavController with SetGraph(NavGraph, null), then constructs Callbacks. Registering the destination listener immediately reports the start destination, outside ApplyNavigationRequest and with IsInitialNavigation false. This code therefore truncates the stack to [A], and NavigationPage.NavigationFinished removes B from InternalChildren before the replacement fragment reads CurrentPage. Exclude graph restoration/listener initialization from external-pop reconciliation so recreating a host does not discard navigation history.
There was a problem hiding this comment.
Confirmed: AddOnDestinationChangedListener reports the current destination to a freshly registered listener, so the Callbacks constructed in CheckForFragmentChange after SetGraph on a replacement NavController would hit the reconciliation with a one-entry platform stack and truncate real history.
Two changes in 8a45d3f close this path:
- Reconciliation now only runs while a navigation request is actually in flight (IsNavigating); a settled stack never reconciles, so listener registration on a recreated host is a no-op.
- CheckForFragmentChange installs the graph and the Callbacks under the same guard flag ApplyNavigationRequest uses, covering the remaining case where a host is replaced while a request is still pending.
| newStack.Add(NavigationStack[i]); | ||
|
|
||
| UpdateNavigationStack(newStack); | ||
| NavigationFinished(NavigationView); |
There was a problem hiding this comment.
[major] Logic and Correctness Verification - The Shell consumer does not synchronize its managed stack from this completion argument. ShellContentStackNavigationView.NavigationFinished delegates to ShellContentNavigationFragment.OnNavigationFinished, which completes the task and updates toolbar/tabs but never updates ShellSection.Stack. If a native pop interrupts a Shell push to B, this code shortens the manager’s stack to [root] and completes the push while ShellSection still contains B, added before the request by OnPushAsync. Subsequent pushes use the shortened manager stack while Shell navigation/back handling uses the unchanged section stack. Reconcile the ShellSection too, or limit this path to consumers that support shortened completion stacks.
There was a problem hiding this comment.
Confirmed: ShellContentNavigationFragment.OnNavigationFinished completes the pending task and updates the toolbar, but never syncs ShellSection.Stack from the completion stack, so a shortened completion would leave the section stack and the manager stack disagreeing.
Took the second option you list: the path is now limited to consumers that rebuild their state from the completion stack. StackNavigationManager gets ReconcilesExternallyPoppedStacks (default true, used by NavigationPage whose NavigationFinished does a full SyncToNavigationStack), and ShellStackNavigationManager opts out, keeping today's Shell behavior unchanged. The issue being fixed (#39456) is a NavigationPage scenario. The full Shell device-test category passes with the change (184/184 on the same emulator).
| newStack.Add(NavigationStack[i]); | ||
|
|
||
| UpdateNavigationStack(newStack); | ||
| NavigationFinished(NavigationView); |
There was a problem hiding this comment.
[major] Async and Threading Safety - Reconciliation can complete a different navigation started synchronously by an Appearing handler. With a settled [A, B] stack, natively pop B and have A’s one-shot Appearing handler push C. NavigationPage.NavigationFinished sets CurrentPage to A before capturing _currentNavigationCompletionSource; that setter synchronously raises Appearing. Since no request holds the semaphore, pushing C installs C’s completion source and starts its native transaction. The outer completion then captures and resolves C’s source, so PushAsync(C) completes while C is still the manager’s active request. Preserve the completion identity across stack-sync callbacks, including when reconciliation began with no pending request.
There was a problem hiding this comment.
Confirmed for the settled-stack case: with no request holding the semaphore, the CurrentPage setter inside NavigationFinished can run an Appearing handler that synchronously installs a new completion source before line "_currentNavigationCompletionSource" is captured.
That window no longer exists: reconciliation is now gated on IsNavigating, so it only ever completes the request that is actually in flight — and while that request is pending, NavigationPage's semaphore is held, so a push from an Appearing handler queues on the semaphore instead of installing a new completion source. The settled-stack entry point the scenario needs is gone (see the first thread).
| return; | ||
|
|
||
| int platformCount = 0; | ||
| NavController.IterateBackStack(_ => platformCount++); |
There was a problem hiding this comment.
[moderate] Regression Prevention and Test Coverage - This native-pop path reintroduces the caught Java exceptions fixed by #39183 (#31368/#35276). After PopBackStack, the popped destination remains in NavGraph. IterateBackStack walks that graph and calls GetBackStackEntry for the missing destination, throwing IllegalArgumentException before catching it; debuggers and FirstChanceException subscribers still observe it. Unlike ApplyNavigationRequestCore, reconciliation never removes the stale destination. The existing PoppingPagesDoesntThrowJavaExceptions test exercises only MAUI-requested pops, and the added native-pop test checks only task completion and stack state. Preserve the earlier fix on this path and extend the native-pop test with its first-chance exception assertion.
There was a problem hiding this comment.
Confirmed: the popped destination stayed in the NavGraph, so every later IterateBackStack probed it and raised a caught IllegalArgumentException — the regression #39183 removed for requested pops.
Reconciliation now removes the natively popped destinations from the graph in the same pass that detects them, mirroring what ApplyNavigationRequestCore does after PopBackStack. One caught probe is still raised by the detection pass itself (that is how IterateBackStack establishes back-stack membership, the pre-existing pattern), but the graph is clean from then on. The device test now asserts it: after the reconciled push completes, a follow-up push+pop runs under a FirstChanceException handler and must observe zero IllegalArgumentExceptions. That assertion fails on the previous head and passes with the fix.
kubaflo
left a comment
There was a problem hiding this comment.
Could you check the ai's suggestions and failing tests?
PR Test Gate
🧪 Gate analysis — click to expand✅ Passed. The selected verification satisfied the gate's passing conditions. Unmatched, skipped, or inconclusive groups are not passing evidence. 📱 Device tests
Execution log excerptsWithout fix With fix PR head: 83bfaacb. Without-fix baseline: 13832fce. |
This comment has been minimized.
This comment has been minimized.
Tests Failure Analysis
🧪 CI Analysis — click to expand📊 maui-prNo failures found. 🧪 maui-pr-devicetests
**Insufficient (redacted) the linked Android work item is flagged incomplete, without a confirmed crash diagnostic. All five target samples have incomplete device coverage. PowerShell errors wrap these work-item failures, not compilation failures. 🧪 maui-pr-uitests
**Insufficient (redacted) current failed-result collection is truncated; additional failures remain unassessed. 🧭 Follow-up — actions and refreshNext action: collect complete results; compare device failures against the target with identical runtime/parameters.
|
b5db893
into
dotnet:candidate/11.0.1xx-sr2
…request (#40124) ### Description of Change On Android, pressing the system back button while an animated `NavigationPage.PushAsync` is still running pops the page natively without MAUI being notified: during an in-flight fragment transaction the back press is consumed by an AndroidX callback registered later than MAUI's (`OnBackPressedDispatcher` invokes the most recently added enabled callback). After that: - the `Task` returned by `PushAsync` never completes — `StackNavigationManager` finishes a navigation when the outgoing fragment's view is destroyed, and a cancelled transition never destroys it, - `NavigationStack`/`CurrentPage` still contain the pushed page while the screen shows the previous one, and the next back press is delivered to the invisible page, - anything awaiting that `PushAsync` hangs, so the app looks frozen. **Fix** `StackNavigationManager` now reconciles when the platform back stack pops without a MAUI request. On every `OnDestinationChanged` that was not produced by `ApplyNavigationRequest` itself (guarded by a flag around the request processing), it compares the platform back-stack depth with the cross-platform stack; when the platform has fewer entries, it trims the stack to what is actually on screen and completes the pending navigation through the existing `NavigationFinished` path — the same reconciliation `IStackNavigation.NavigationFinished` already performs on the Controls side (stack sync, `CurrentPage`, toolbar, task completion). This is the outcome the issue asks for: the interrupted push is treated as cancelled, the `PushAsync` task completes, and the cross-platform stack matches what is displayed. **Tests** `NavigationPageTests.PushCompletesWhenThePlatformPopsDuringTheTransition` (Android device test): starts an animated push and immediately pops the platform back stack — what the stolen back press does — then checks the push task completes, the stack has a single page and `CurrentPage` is the root again. | | Without fix | With fix | |---|---|---| | Android emulator (API 37) | Fails: `PushAsync never completed after the platform popped the page` | Passes. NavigationPage category 25 passed / 1 failed / 1 skipped — the one failure (`BarBackgroundColor respects Android system chrome opt-out`) fails identically on unmodified `main` on the same emulator | ### Issues Fixed Fixes #39456 Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
|
Addressed both parts of the review: AI suggestions — all four were valid; each thread has a detailed reply. The short version, all in 8a45d3f:
Failing tests — on the previous run, the |
…request (#40124) ### Description of Change On Android, pressing the system back button while an animated `NavigationPage.PushAsync` is still running pops the page natively without MAUI being notified: during an in-flight fragment transaction the back press is consumed by an AndroidX callback registered later than MAUI's (`OnBackPressedDispatcher` invokes the most recently added enabled callback). After that: - the `Task` returned by `PushAsync` never completes — `StackNavigationManager` finishes a navigation when the outgoing fragment's view is destroyed, and a cancelled transition never destroys it, - `NavigationStack`/`CurrentPage` still contain the pushed page while the screen shows the previous one, and the next back press is delivered to the invisible page, - anything awaiting that `PushAsync` hangs, so the app looks frozen. **Fix** `StackNavigationManager` now reconciles when the platform back stack pops without a MAUI request. On every `OnDestinationChanged` that was not produced by `ApplyNavigationRequest` itself (guarded by a flag around the request processing), it compares the platform back-stack depth with the cross-platform stack; when the platform has fewer entries, it trims the stack to what is actually on screen and completes the pending navigation through the existing `NavigationFinished` path — the same reconciliation `IStackNavigation.NavigationFinished` already performs on the Controls side (stack sync, `CurrentPage`, toolbar, task completion). This is the outcome the issue asks for: the interrupted push is treated as cancelled, the `PushAsync` task completes, and the cross-platform stack matches what is displayed. **Tests** `NavigationPageTests.PushCompletesWhenThePlatformPopsDuringTheTransition` (Android device test): starts an animated push and immediately pops the platform back stack — what the stolen back press does — then checks the push task completes, the stack has a single page and `CurrentPage` is the root again. | | Without fix | With fix | |---|---|---| | Android emulator (API 37) | Fails: `PushAsync never completed after the platform popped the page` | Passes. NavigationPage category 25 passed / 1 failed / 1 skipped — the one failure (`BarBackgroundColor respects Android system chrome opt-out`) fails identically on unmodified `main` on the same emulator | ### Issues Fixed Fixes #39456 Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
…request (#40124) ### Description of Change On Android, pressing the system back button while an animated `NavigationPage.PushAsync` is still running pops the page natively without MAUI being notified: during an in-flight fragment transaction the back press is consumed by an AndroidX callback registered later than MAUI's (`OnBackPressedDispatcher` invokes the most recently added enabled callback). After that: - the `Task` returned by `PushAsync` never completes — `StackNavigationManager` finishes a navigation when the outgoing fragment's view is destroyed, and a cancelled transition never destroys it, - `NavigationStack`/`CurrentPage` still contain the pushed page while the screen shows the previous one, and the next back press is delivered to the invisible page, - anything awaiting that `PushAsync` hangs, so the app looks frozen. **Fix** `StackNavigationManager` now reconciles when the platform back stack pops without a MAUI request. On every `OnDestinationChanged` that was not produced by `ApplyNavigationRequest` itself (guarded by a flag around the request processing), it compares the platform back-stack depth with the cross-platform stack; when the platform has fewer entries, it trims the stack to what is actually on screen and completes the pending navigation through the existing `NavigationFinished` path — the same reconciliation `IStackNavigation.NavigationFinished` already performs on the Controls side (stack sync, `CurrentPage`, toolbar, task completion). This is the outcome the issue asks for: the interrupted push is treated as cancelled, the `PushAsync` task completes, and the cross-platform stack matches what is displayed. **Tests** `NavigationPageTests.PushCompletesWhenThePlatformPopsDuringTheTransition` (Android device test): starts an animated push and immediately pops the platform back stack — what the stolen back press does — then checks the push task completes, the stack has a single page and `CurrentPage` is the root again. | | Without fix | With fix | |---|---|---| | Android emulator (API 37) | Fails: `PushAsync never completed after the platform popped the page` | Passes. NavigationPage category 25 passed / 1 failed / 1 skipped — the one failure (`BarBackgroundColor respects Android system chrome opt-out`) fails identically on unmodified `main` on the same emulator | ### Issues Fixed Fixes #39456 Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
…request (#40124) ### Description of Change On Android, pressing the system back button while an animated `NavigationPage.PushAsync` is still running pops the page natively without MAUI being notified: during an in-flight fragment transaction the back press is consumed by an AndroidX callback registered later than MAUI's (`OnBackPressedDispatcher` invokes the most recently added enabled callback). After that: - the `Task` returned by `PushAsync` never completes — `StackNavigationManager` finishes a navigation when the outgoing fragment's view is destroyed, and a cancelled transition never destroys it, - `NavigationStack`/`CurrentPage` still contain the pushed page while the screen shows the previous one, and the next back press is delivered to the invisible page, - anything awaiting that `PushAsync` hangs, so the app looks frozen. **Fix** `StackNavigationManager` now reconciles when the platform back stack pops without a MAUI request. On every `OnDestinationChanged` that was not produced by `ApplyNavigationRequest` itself (guarded by a flag around the request processing), it compares the platform back-stack depth with the cross-platform stack; when the platform has fewer entries, it trims the stack to what is actually on screen and completes the pending navigation through the existing `NavigationFinished` path — the same reconciliation `IStackNavigation.NavigationFinished` already performs on the Controls side (stack sync, `CurrentPage`, toolbar, task completion). This is the outcome the issue asks for: the interrupted push is treated as cancelled, the `PushAsync` task completes, and the cross-platform stack matches what is displayed. **Tests** `NavigationPageTests.PushCompletesWhenThePlatformPopsDuringTheTransition` (Android device test): starts an animated push and immediately pops the platform back stack — what the stolen back press does — then checks the push task completes, the stack has a single page and `CurrentPage` is the root again. | | Without fix | With fix | |---|---|---| | Android emulator (API 37) | Fails: `PushAsync never completed after the platform popped the page` | Passes. NavigationPage category 25 passed / 1 failed / 1 skipped — the one failure (`BarBackgroundColor respects Android system chrome opt-out`) fails identically on unmodified `main` on the same emulator | ### Issues Fixed Fixes #39456 Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
…request (#40124) ### Description of Change On Android, pressing the system back button while an animated `NavigationPage.PushAsync` is still running pops the page natively without MAUI being notified: during an in-flight fragment transaction the back press is consumed by an AndroidX callback registered later than MAUI's (`OnBackPressedDispatcher` invokes the most recently added enabled callback). After that: - the `Task` returned by `PushAsync` never completes — `StackNavigationManager` finishes a navigation when the outgoing fragment's view is destroyed, and a cancelled transition never destroys it, - `NavigationStack`/`CurrentPage` still contain the pushed page while the screen shows the previous one, and the next back press is delivered to the invisible page, - anything awaiting that `PushAsync` hangs, so the app looks frozen. **Fix** `StackNavigationManager` now reconciles when the platform back stack pops without a MAUI request. On every `OnDestinationChanged` that was not produced by `ApplyNavigationRequest` itself (guarded by a flag around the request processing), it compares the platform back-stack depth with the cross-platform stack; when the platform has fewer entries, it trims the stack to what is actually on screen and completes the pending navigation through the existing `NavigationFinished` path — the same reconciliation `IStackNavigation.NavigationFinished` already performs on the Controls side (stack sync, `CurrentPage`, toolbar, task completion). This is the outcome the issue asks for: the interrupted push is treated as cancelled, the `PushAsync` task completes, and the cross-platform stack matches what is displayed. **Tests** `NavigationPageTests.PushCompletesWhenThePlatformPopsDuringTheTransition` (Android device test): starts an animated push and immediately pops the platform back stack — what the stolen back press does — then checks the push task completes, the stack has a single page and `CurrentPage` is the root again. | | Without fix | With fix | |---|---|---| | Android emulator (API 37) | Fails: `PushAsync never completed after the platform popped the page` | Passes. NavigationPage category 25 passed / 1 failed / 1 skipped — the one failure (`BarBackgroundColor respects Android system chrome opt-out`) fails identically on unmodified `main` on the same emulator | ### Issues Fixed Fixes #39456 Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
…request (#40124) ### Description of Change On Android, pressing the system back button while an animated `NavigationPage.PushAsync` is still running pops the page natively without MAUI being notified: during an in-flight fragment transaction the back press is consumed by an AndroidX callback registered later than MAUI's (`OnBackPressedDispatcher` invokes the most recently added enabled callback). After that: - the `Task` returned by `PushAsync` never completes — `StackNavigationManager` finishes a navigation when the outgoing fragment's view is destroyed, and a cancelled transition never destroys it, - `NavigationStack`/`CurrentPage` still contain the pushed page while the screen shows the previous one, and the next back press is delivered to the invisible page, - anything awaiting that `PushAsync` hangs, so the app looks frozen. **Fix** `StackNavigationManager` now reconciles when the platform back stack pops without a MAUI request. On every `OnDestinationChanged` that was not produced by `ApplyNavigationRequest` itself (guarded by a flag around the request processing), it compares the platform back-stack depth with the cross-platform stack; when the platform has fewer entries, it trims the stack to what is actually on screen and completes the pending navigation through the existing `NavigationFinished` path — the same reconciliation `IStackNavigation.NavigationFinished` already performs on the Controls side (stack sync, `CurrentPage`, toolbar, task completion). This is the outcome the issue asks for: the interrupted push is treated as cancelled, the `PushAsync` task completes, and the cross-platform stack matches what is displayed. **Tests** `NavigationPageTests.PushCompletesWhenThePlatformPopsDuringTheTransition` (Android device test): starts an animated push and immediately pops the platform back stack — what the stolen back press does — then checks the push task completes, the stack has a single page and `CurrentPage` is the root again. | | Without fix | With fix | |---|---|---| | Android emulator (API 37) | Fails: `PushAsync never completed after the platform popped the page` | Passes. NavigationPage category 25 passed / 1 failed / 1 skipped — the one failure (`BarBackgroundColor respects Android system chrome opt-out`) fails identically on unmodified `main` on the same emulator | ### Issues Fixed Fixes #39456 Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
…request (#40124) ### Description of Change On Android, pressing the system back button while an animated `NavigationPage.PushAsync` is still running pops the page natively without MAUI being notified: during an in-flight fragment transaction the back press is consumed by an AndroidX callback registered later than MAUI's (`OnBackPressedDispatcher` invokes the most recently added enabled callback). After that: - the `Task` returned by `PushAsync` never completes — `StackNavigationManager` finishes a navigation when the outgoing fragment's view is destroyed, and a cancelled transition never destroys it, - `NavigationStack`/`CurrentPage` still contain the pushed page while the screen shows the previous one, and the next back press is delivered to the invisible page, - anything awaiting that `PushAsync` hangs, so the app looks frozen. **Fix** `StackNavigationManager` now reconciles when the platform back stack pops without a MAUI request. On every `OnDestinationChanged` that was not produced by `ApplyNavigationRequest` itself (guarded by a flag around the request processing), it compares the platform back-stack depth with the cross-platform stack; when the platform has fewer entries, it trims the stack to what is actually on screen and completes the pending navigation through the existing `NavigationFinished` path — the same reconciliation `IStackNavigation.NavigationFinished` already performs on the Controls side (stack sync, `CurrentPage`, toolbar, task completion). This is the outcome the issue asks for: the interrupted push is treated as cancelled, the `PushAsync` task completes, and the cross-platform stack matches what is displayed. **Tests** `NavigationPageTests.PushCompletesWhenThePlatformPopsDuringTheTransition` (Android device test): starts an animated push and immediately pops the platform back stack — what the stolen back press does — then checks the push task completes, the stack has a single page and `CurrentPage` is the root again. | | Without fix | With fix | |---|---|---| | Android emulator (API 37) | Fails: `PushAsync never completed after the platform popped the page` | Passes. NavigationPage category 25 passed / 1 failed / 1 skipped — the one failure (`BarBackgroundColor respects Android system chrome opt-out`) fails identically on unmodified `main` on the same emulator | ### Issues Fixed Fixes #39456 Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
…request (#40124) ### Description of Change On Android, pressing the system back button while an animated `NavigationPage.PushAsync` is still running pops the page natively without MAUI being notified: during an in-flight fragment transaction the back press is consumed by an AndroidX callback registered later than MAUI's (`OnBackPressedDispatcher` invokes the most recently added enabled callback). After that: - the `Task` returned by `PushAsync` never completes — `StackNavigationManager` finishes a navigation when the outgoing fragment's view is destroyed, and a cancelled transition never destroys it, - `NavigationStack`/`CurrentPage` still contain the pushed page while the screen shows the previous one, and the next back press is delivered to the invisible page, - anything awaiting that `PushAsync` hangs, so the app looks frozen. **Fix** `StackNavigationManager` now reconciles when the platform back stack pops without a MAUI request. On every `OnDestinationChanged` that was not produced by `ApplyNavigationRequest` itself (guarded by a flag around the request processing), it compares the platform back-stack depth with the cross-platform stack; when the platform has fewer entries, it trims the stack to what is actually on screen and completes the pending navigation through the existing `NavigationFinished` path — the same reconciliation `IStackNavigation.NavigationFinished` already performs on the Controls side (stack sync, `CurrentPage`, toolbar, task completion). This is the outcome the issue asks for: the interrupted push is treated as cancelled, the `PushAsync` task completes, and the cross-platform stack matches what is displayed. **Tests** `NavigationPageTests.PushCompletesWhenThePlatformPopsDuringTheTransition` (Android device test): starts an animated push and immediately pops the platform back stack — what the stolen back press does — then checks the push task completes, the stack has a single page and `CurrentPage` is the root again. | | Without fix | With fix | |---|---|---| | Android emulator (API 37) | Fails: `PushAsync never completed after the platform popped the page` | Passes. NavigationPage category 25 passed / 1 failed / 1 skipped — the one failure (`BarBackgroundColor respects Android system chrome opt-out`) fails identically on unmodified `main` on the same emulator | ### Issues Fixed Fixes #39456 Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
…request (#40124) ### Description of Change On Android, pressing the system back button while an animated `NavigationPage.PushAsync` is still running pops the page natively without MAUI being notified: during an in-flight fragment transaction the back press is consumed by an AndroidX callback registered later than MAUI's (`OnBackPressedDispatcher` invokes the most recently added enabled callback). After that: - the `Task` returned by `PushAsync` never completes — `StackNavigationManager` finishes a navigation when the outgoing fragment's view is destroyed, and a cancelled transition never destroys it, - `NavigationStack`/`CurrentPage` still contain the pushed page while the screen shows the previous one, and the next back press is delivered to the invisible page, - anything awaiting that `PushAsync` hangs, so the app looks frozen. **Fix** `StackNavigationManager` now reconciles when the platform back stack pops without a MAUI request. On every `OnDestinationChanged` that was not produced by `ApplyNavigationRequest` itself (guarded by a flag around the request processing), it compares the platform back-stack depth with the cross-platform stack; when the platform has fewer entries, it trims the stack to what is actually on screen and completes the pending navigation through the existing `NavigationFinished` path — the same reconciliation `IStackNavigation.NavigationFinished` already performs on the Controls side (stack sync, `CurrentPage`, toolbar, task completion). This is the outcome the issue asks for: the interrupted push is treated as cancelled, the `PushAsync` task completes, and the cross-platform stack matches what is displayed. **Tests** `NavigationPageTests.PushCompletesWhenThePlatformPopsDuringTheTransition` (Android device test): starts an animated push and immediately pops the platform back stack — what the stolen back press does — then checks the push task completes, the stack has a single page and `CurrentPage` is the root again. | | Without fix | With fix | |---|---|---| | Android emulator (API 37) | Fails: `PushAsync never completed after the platform popped the page` | Passes. NavigationPage category 25 passed / 1 failed / 1 skipped — the one failure (`BarBackgroundColor respects Android system chrome opt-out`) fails identically on unmodified `main` on the same emulator | ### Issues Fixed Fixes #39456 Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
…request (#40124) ### Description of Change On Android, pressing the system back button while an animated `NavigationPage.PushAsync` is still running pops the page natively without MAUI being notified: during an in-flight fragment transaction the back press is consumed by an AndroidX callback registered later than MAUI's (`OnBackPressedDispatcher` invokes the most recently added enabled callback). After that: - the `Task` returned by `PushAsync` never completes — `StackNavigationManager` finishes a navigation when the outgoing fragment's view is destroyed, and a cancelled transition never destroys it, - `NavigationStack`/`CurrentPage` still contain the pushed page while the screen shows the previous one, and the next back press is delivered to the invisible page, - anything awaiting that `PushAsync` hangs, so the app looks frozen. **Fix** `StackNavigationManager` now reconciles when the platform back stack pops without a MAUI request. On every `OnDestinationChanged` that was not produced by `ApplyNavigationRequest` itself (guarded by a flag around the request processing), it compares the platform back-stack depth with the cross-platform stack; when the platform has fewer entries, it trims the stack to what is actually on screen and completes the pending navigation through the existing `NavigationFinished` path — the same reconciliation `IStackNavigation.NavigationFinished` already performs on the Controls side (stack sync, `CurrentPage`, toolbar, task completion). This is the outcome the issue asks for: the interrupted push is treated as cancelled, the `PushAsync` task completes, and the cross-platform stack matches what is displayed. **Tests** `NavigationPageTests.PushCompletesWhenThePlatformPopsDuringTheTransition` (Android device test): starts an animated push and immediately pops the platform back stack — what the stolen back press does — then checks the push task completes, the stack has a single page and `CurrentPage` is the root again. | | Without fix | With fix | |---|---|---| | Android emulator (API 37) | Fails: `PushAsync never completed after the platform popped the page` | Passes. NavigationPage category 25 passed / 1 failed / 1 skipped — the one failure (`BarBackgroundColor respects Android system chrome opt-out`) fails identically on unmodified `main` on the same emulator | ### Issues Fixed Fixes #39456 Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
…request (#40124) ### Description of Change On Android, pressing the system back button while an animated `NavigationPage.PushAsync` is still running pops the page natively without MAUI being notified: during an in-flight fragment transaction the back press is consumed by an AndroidX callback registered later than MAUI's (`OnBackPressedDispatcher` invokes the most recently added enabled callback). After that: - the `Task` returned by `PushAsync` never completes — `StackNavigationManager` finishes a navigation when the outgoing fragment's view is destroyed, and a cancelled transition never destroys it, - `NavigationStack`/`CurrentPage` still contain the pushed page while the screen shows the previous one, and the next back press is delivered to the invisible page, - anything awaiting that `PushAsync` hangs, so the app looks frozen. **Fix** `StackNavigationManager` now reconciles when the platform back stack pops without a MAUI request. On every `OnDestinationChanged` that was not produced by `ApplyNavigationRequest` itself (guarded by a flag around the request processing), it compares the platform back-stack depth with the cross-platform stack; when the platform has fewer entries, it trims the stack to what is actually on screen and completes the pending navigation through the existing `NavigationFinished` path — the same reconciliation `IStackNavigation.NavigationFinished` already performs on the Controls side (stack sync, `CurrentPage`, toolbar, task completion). This is the outcome the issue asks for: the interrupted push is treated as cancelled, the `PushAsync` task completes, and the cross-platform stack matches what is displayed. **Tests** `NavigationPageTests.PushCompletesWhenThePlatformPopsDuringTheTransition` (Android device test): starts an animated push and immediately pops the platform back stack — what the stolen back press does — then checks the push task completes, the stack has a single page and `CurrentPage` is the root again. | | Without fix | With fix | |---|---|---| | Android emulator (API 37) | Fails: `PushAsync never completed after the platform popped the page` | Passes. NavigationPage category 25 passed / 1 failed / 1 skipped — the one failure (`BarBackgroundColor respects Android system chrome opt-out`) fails identically on unmodified `main` on the same emulator | ### Issues Fixed Fixes #39456 Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
…request (dotnet#40124) ### Description of Change On Android, pressing the system back button while an animated `NavigationPage.PushAsync` is still running pops the page natively without MAUI being notified: during an in-flight fragment transaction the back press is consumed by an AndroidX callback registered later than MAUI's (`OnBackPressedDispatcher` invokes the most recently added enabled callback). After that: - the `Task` returned by `PushAsync` never completes — `StackNavigationManager` finishes a navigation when the outgoing fragment's view is destroyed, and a cancelled transition never destroys it, - `NavigationStack`/`CurrentPage` still contain the pushed page while the screen shows the previous one, and the next back press is delivered to the invisible page, - anything awaiting that `PushAsync` hangs, so the app looks frozen. **Fix** `StackNavigationManager` now reconciles when the platform back stack pops without a MAUI request. On every `OnDestinationChanged` that was not produced by `ApplyNavigationRequest` itself (guarded by a flag around the request processing), it compares the platform back-stack depth with the cross-platform stack; when the platform has fewer entries, it trims the stack to what is actually on screen and completes the pending navigation through the existing `NavigationFinished` path — the same reconciliation `IStackNavigation.NavigationFinished` already performs on the Controls side (stack sync, `CurrentPage`, toolbar, task completion). This is the outcome the issue asks for: the interrupted push is treated as cancelled, the `PushAsync` task completes, and the cross-platform stack matches what is displayed. **Tests** `NavigationPageTests.PushCompletesWhenThePlatformPopsDuringTheTransition` (Android device test): starts an animated push and immediately pops the platform back stack — what the stolen back press does — then checks the push task completes, the stack has a single page and `CurrentPage` is the root again. | | Without fix | With fix | |---|---|---| | Android emulator (API 37) | Fails: `PushAsync never completed after the platform popped the page` | Passes. NavigationPage category 25 passed / 1 failed / 1 skipped — the one failure (`BarBackgroundColor respects Android system chrome opt-out`) fails identically on unmodified `main` on the same emulator | ### Issues Fixed Fixes dotnet#39456 Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
|
Thanks for the fix! Could this be backported to the 10.0.x servicing branch? We hit the same hang on 10.0.80 in production (Android 16/17, |
Description of Change
On Android, pressing the system back button while an animated
NavigationPage.PushAsyncis still running pops the page natively without MAUI being notified: during an in-flight fragment transaction the back press is consumed by an AndroidX callback registered later than MAUI's (OnBackPressedDispatcherinvokes the most recently added enabled callback). After that:Taskreturned byPushAsyncnever completes —StackNavigationManagerfinishes a navigation when the outgoing fragment's view is destroyed, and a cancelled transition never destroys it,NavigationStack/CurrentPagestill contain the pushed page while the screen shows the previous one, and the next back press is delivered to the invisible page,PushAsynchangs, so the app looks frozen.Fix
StackNavigationManagernow reconciles when the platform back stack pops out from under an in-flight MAUI request. On anOnDestinationChangedthat was not produced byApplyNavigationRequestitself (guarded by a flag around the request processing), while a request is pending (IsNavigating), it compares the platform back-stack depth with the cross-platform stack; when the platform has fewer entries, it trims the stack to what is actually on screen, removes the natively popped destinations from theNavGraph(the same cleanupApplyNavigationRequestCoredoes for requested pops, keeping the no-caught-Java-exceptions guarantee of #39183), and completes the pending navigation through the existingNavigationFinishedpath — the same reconciliationIStackNavigation.NavigationFinishedalready performs on the Controls side (stack sync,CurrentPage, toolbar, task completion).The path is deliberately narrow:
CheckForFragmentChangerebuilds the nav host after a recreation — and on a settled stack that report must not rewrite history; graph installation inCheckForFragmentChangeis additionally guarded by the same flagApplyNavigationRequestuses. Gating on an in-flight request also means the completion can only ever resolve the request that is actually pending:NavigationPage's navigation semaphore is held for that request, so a push started synchronously from anAppearinghandler queues instead of installing a new completion source.ShellStackNavigationManageroverridesReconcilesExternallyPoppedStacks): Shell completes navigation throughShellContentNavigationFragment.OnNavigationFinished, which does not rebuildShellSection.Stackfrom the completion stack, so reconciling there would leave the section stack and the manager stack disagreeing. Shell behavior is unchanged by this PR; the issue scenario isNavigationPage.This is the outcome the issue asks for: the interrupted push is treated as cancelled, the
PushAsynctask completes, and the cross-platform stack matches what is displayed.Tests
NavigationPageTests.PushCompletesWhenThePlatformPopsDuringTheTransition(Android device test): starts an animated push and immediately pops the platform back stack — what the stolen back press does — then checks the push task completes, the stack has a single page andCurrentPageis the root again. After that it runs a follow-up push+pop under anAppDomain.FirstChanceExceptionhandler and asserts noJava.Lang.IllegalArgumentExceptionis raised, which fails if the natively popped destination is left in theNavGraph.PushAsync never completed after the platform popped the page; with only the completion fix, the exception assertion still fails with 4×No destination with ID … is on the NavControllerBarBackgroundColor respects Android system chrome opt-out) fails identically on unmodifiedmainon the same emulator. Shell category: 184 passed / 0 failedIssues Fixed
Fixes #39456