Repository navigation
[NavigationPage] Don't raise NavigatedTo early for a page pushed during the initial navigation - #40795
Merged
Conversation
…ng the initial navigation The initial navigation's completion callback read CurrentPage, so a push made right after the handler connected had its NavigatedTo raised before its own navigation ran. Only send the initial Navigated for the page that navigation was for. Backports the NavigationPage.cs hunk and its unit test from #40537. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
Author
|
@dalexsoto stamp |
kubaflo
temporarily deployed
to
copilot-pat-pool
November 29, 2026 09:28 — with
GitHub Actions
Inactive
This comment has been minimized.
This comment has been minimized.
kubaflo
temporarily deployed
to
copilot-pat-pool
November 29, 2026 09:28 — with
GitHub Actions
Inactive
This comment has been minimized.
This comment has been minimized.
kubaflo
had a problem deploying
to
copilot-pat-pool
November 29, 2026 09:29 — with
GitHub Actions
Failure
kubaflo
temporarily deployed
to
copilot-pat-pool
November 29, 2026 09:30 — with
GitHub Actions
Inactive
kubaflo
temporarily deployed
to
copilot-pat-pool
November 29, 2026 09:31 — with
GitHub Actions
Inactive
kubaflo
temporarily deployed
to
copilot-pat-pool
November 29, 2026 09:31 — with
GitHub Actions
Inactive
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
1 of 2 tasks
kubaflo
added a commit
that referenced
this pull request
Nov 29, 2026
…40802) <!-- copilot-assessment:v1 --> ### Agent assessment Self-reported assessment, not an independent review. Assessed revision: `e9964a9acf9cfa240b69eba1155898bc524dcc6b` | Dimension | Assessment | Rationale | |---|---|---| | Change confidence | 8/10 | ↑ Deferral is compiled only for Windows; other platforms retain main's completion behavior.<br>↑ 350 navigation unit tests pass, including the non-Windows ordering regression test.<br>↑ Build 1704240 validates iOS General and Windows NavigationPage in both packaging modes at this exact head.<br>↓ The first scoped-head run still had iOS failures; an unchanged-head retry passed, so native environment variability remains relevant. | | Diagnosis confidence | 7/10 | ↑ WinUI completes navigation inside Loaded, where inline callers can immediately close the window.<br>↑ The Windows-only change retains success of the original crash test in both packaging modes.<br>↑ Non-Windows callback ordering is restored and unit-tested.<br>↓ The original Windows native faulting module is unknown; the 17 iOS failures cannot all be causally attributed to deferral, since they also occurred once with this scoped head. | | Evidence fit | 8/10 | ↑ Build 1704240 genuine TRX: iOS General 1479 passed/0 failed/14 existing skips, including all 17 previously failing cases.<br>↑ Both Windows NavigationPage categories: 16 passed/0 failed/3 existing skips, and the original test explicitly Passed (242 ms packaged, 240 ms unpackaged).<br>↓ Build 1704232's first scoped-head iOS result was red; the green validation is the unchanged-head retry 1704240, not that earlier run. | <!-- /copilot-assessment --> <!-- Please let the below note in for people that find this PR --> > [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- Open .NET 11 fix PRs against net11 for review; target main for next-major features. After approval, a maintainer manually retargets the fix PR to the active inflight branch and merges it directly there. Do not merge individual fixes into net11. Bots must not retarget or merge. Candidate integration into net11 and release/* changes are separate, explicitly coordinated release work. --> ### Target Branch | This PR is for | Initial base | | --- | --- | | New features, API changes, or .NET 12 work (including .NET 12 fixes) | `main` | | .NET 11 servicing fixes | `net11`, for review | | Older servicing, release integration, infrastructure, or documentation | The branch designated for that work | - [x] I selected the applicable base branch using the [contribution guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting): `main`, explicitly requested for the .NET 12 Windows CI failure. For .NET 11 fixes, only a maintainer retargets the approved PR to the active inflight lane and merges it after CI validates that final base. Do not merge individual fixes directly into `net11`; agents must not retarget or merge. ### Description of Change <!-- Enter description of the fix in this section --> On **Windows only**, create the active `NavigationPage` request completion source with `RunContinuationsAsynchronously`. Other platforms retain the original completion source and native callback ordering. On Windows, `StackNavigationManager.OnNavigated` completes the request from WinUI's `Loaded` callback. Previously, `SetResult` could synchronously run the entire navigation continuation and its caller while that native callback was still on the stack. In `SettingTitleIconImageSourceDoesntCrash`, this includes updating the toolbar image and immediately closing/destroying the window through `CreateHandlerAndAddToWindow`. Queueing continuations lets the native completion callback unwind first. The updated portable unit test uses a manually completed handler and verifies that non-Windows `NavigatedTo` retains its original synchronous native callback ordering. It fails against this PR's earlier unscoped deferral and passes with the Windows-only correction. The existing Windows device test is unchanged: no skip, delay, image substitution, or reduced coverage. Baseline: [build 1704198](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1704198), Windows Controls packaged [log 760](https://dev.azure.com/dnceng-public/public/_apis/build/builds/1704198/logs/760?api-version=7.1), 11:38:15–11:38:38 UTC. The recovered TRX contains one passed test; the sequence starts `SettingTitleIconImageSourceDoesntCrash` without an end event. The process exits 57005 (0xDEAD), MTP exits 7. The artifact contains no `.dmp`, and `windows-application-events.json` is empty. No faulting module or native exception is known. The supplied additional baseline builds are 1704155, 1703964 and 1704185. Duplicate search covered open and recently merged PRs across main, net11, release, candidate and inflight branches for this test, title icons, PageControl, StackNavigationManager, teardown, and navigation continuations. This is not #40795's initial-navigation event guard (already on main), nor #39911's stale image-result guard (also already on main). Validation (latest revision, configured SDK `12.0.100-alpha.1.26523.103`, macOS): ```sh dotnet test src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj \ -p:IncludeAndroidTargetFrameworks=false -p:IncludeIosTargetFrameworks=false \ -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeMacOSTargetFrameworks=false \ -p:IncludeWindowsTargetFrameworks=false \ --filter-method '*NonWindowsNavigationCompletionPreservesNativeCallbackOrdering' --verbosity quiet ``` - Before scoping the fix: **failed**, `Assert.True`, actual `False` (1 test), proving the unscoped PR changes non-Windows ordering. - After scoping, same command with `--filter-method '*Navigation*'`: **passed**, 350/350. - `dotnet format whitespace --folder --include src/Controls/src/Core/NavigationPage/NavigationPage.cs src/Controls/tests/Core.UnitTests/NavigationPageLifecycleTests.cs --verbosity quiet`: **passed**. - `git diff --check`: **passed**. - Latest-head native iOS/Windows CI: **validated in build 1704240** below; not run locally. #### Native CI history and regression correction [Build 1704212](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1704212) tested the **previous** head `c4da77aa65cbec06d93b41a8c4b0b6ae69f219e6` (merge `6da2433c9f8cde06366718a44c461b11bc97caf7`): - Windows NavigationPage passed in both modes: 16 passed, 0 failed, 3 existing skips each. Both genuine TRX files explicitly mark `SettingTitleIconImageSourceDoesntCrash` Passed (148 ms packaged, 189 ms unpackaged). [Packaged log 760](https://dev.azure.com/dnceng-public/public/_apis/build/builds/1704212/logs/760?api-version=7.1); [unpackaged log 739](https://dev.azure.com/dnceng-public/public/_apis/build/builds/1704212/logs/739?api-version=7.1). - **Observed failures:** iOS Controls CoreCLR General [log 727](https://dev.azure.com/dnceng-public/public/_apis/build/builds/1704212/logs/727?api-version=7.1) failed 17/1493 tests: TabbedPage background transitions, NavigationPage back-button observation, More-tab PageTransitions, and ScrollView horizontal options. The unscoped deferral changed non-Windows callback ordering (confirmed by the unit test); this revision restores main's behavior outside Windows. The 17 native failures are not conclusively all caused by that ordering change: they also recurred in the first Windows-only run before passing on the unchanged-head retry. - The reported Windows unpackaged Shell crash and Windows BlazorWebView initialization failure also occur on main / are known flakes; they are outside this fix and are not modified or hidden. - Build 1704210 was canceled before execution and is not validation evidence. #### Latest-head native validation: build 1704240 [Build 1704240](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1704240) validates head `e9964a9acf9cfa240b69eba1155898bc524dcc6b` through merge `4edb3a18f4e96fe3be0f866b887b506e1a42a221`. | Selected coverage | Actual result | Raw task log | | --- | --- | --- | | iOS Controls CoreCLR General | 1479 passed, 0 failed, 14 existing skips; job succeeded | [736](https://dev.azure.com/dnceng-public/public/_apis/build/builds/1704240/logs/736?api-version=7.1) | | Windows Controls packaged NavigationPage | 16 passed, 0 failed, 3 existing skips; category exit 0 | [745](https://dev.azure.com/dnceng-public/public/_apis/build/builds/1704240/logs/745?api-version=7.1) | | Windows Controls unpackaged NavigationPage | 16 passed, 0 failed, 3 existing skips; category exit 0 | [739](https://dev.azure.com/dnceng-public/public/_apis/build/builds/1704240/logs/739?api-version=7.1) | The genuine iOS `native/testResults.trx` confirms all 17 previously failing cases individually **Passed**. Both Windows `categories/NavigationPage/Controls-NavigationPage.trx` files explicitly record `SettingTitleIconImageSourceDoesntCrash` **Passed** (242 ms packaged, 240 ms unpackaged). No native device tests were changed or newly skipped. **First-run caveat:** build 1704232 tested the same scoped head and still had the same 17 iOS failures (log 736), despite compiling IOS rather than WINDOWS and retaining main's non-Windows code. Compared with green main 1704155, its simulator log records a different iOS 27.2 runtime build (`SimulatorRuntime-v24.2.91016.19` versus `v24.2.8117.0`), and provisioning ends with `Data Migration Failed`. These differences support native environment variability, not a proven root cause of every failure. The subsequent 1704240 run was an **unchanged-head retry**, not another product fix. The packaged Windows job in 1704240 still fails in the separate Shell category (exit 7); NavigationPage passes. The known Shell/BlazorWebView failures are not fixed or hidden here. This is validation of the requested iOS General and Windows NavigationPage coverage, not a full-CI-green claim. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Addresses the Windows Controls `SettingTitleIconImageSourceDoesntCrash` CI host crash described above; no separate issue was supplied. Related investigation: #40795, not a replacement or duplicate of its net11 fix. ### Let AI finish this PR - [ ] **Let the MAUI agent address review feedback and fix remaining issues on this PR.** Maintainers still decide whether it is merged. For PRs from forks, the agent opens a follow-up PR that keeps your commits. <!-- Verify the target branch follows the release workflow in docs/ReleaseBranchWorkflow.md. Infrastructure and documentation changes should target the branch where they apply. --> --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This branch was previously deployed
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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!
Agent assessment
Self-reported assessment, not an independent review.
Assessed revision:
d1f1c3803dfb83a81deaeedf0fcc19a3919871a0↑ 317 Controls.Core.UnitTests navigation tests pass with the guard.
↑ Same 8-line guard that is already on main, where the Windows NavigationPage category passes.
↓ Windows device tests not run locally (macOS host); CI is the validation.
↑ The failing Windows test (SettingTitleIconImageSourceDoesntCrash) pushes a NavigationPage right after the handler connects, the exact scenario.
↓ The Windows host crash has no managed stack or dump, so the link between this race and the crash is inferred from main passing and net11 not, not observed directly.
↓ Not confirmed until maui-pr-uitests runs on this PR; if NavigationPage still crashes the diagnosis is wrong.
Target Branch
net11, .NET 11 fix, for review).Description of Change
Backports the
NavigationPage.cshunk and its unit test from #40537 (already onmain).When the handler connects,
NavigationPagestarts an initial navigation whose completion callback calledSendNavigated(null, ...), which readsCurrentPage. If a page is pushed right after the handler connects,CurrentPageis already the pushed page by the time the callback runs, so itsNavigatedTois raised before its own navigation has run. The callback now only sends the initialNavigatedwhenCurrentPageis still the page that navigation was for; the pushed page gets itsNavigatedTofrom its own navigation.This is the scenario of the Windows device test
SettingTitleIconImageSourceDoesntCrash, which pushes aNavigationPageright after the window handler is created. That test crashes the test host (exit 7, no managed stack) on everynet11run of maui-pr-uitests (build 1703903, packaged and unpackaged) and passes onmain, where this guard is present.Validation (macOS,
Controls.Core.UnitTests, net11.0):APushMadeBeforeTheInitialNavigationFinishesGetsNavigatedToOnlyFromItsOwnNavigationfails (Expected 0, Actual 1).NavigationPageLifecycleTests10/10.Not run locally: the Windows device test (Windows-only); maui-pr-uitests on this PR is the validation.
Issues Fixed
Fixes the NavigationPage host crash in maui-pr-uitests on
net11.