Skip to content

[NavigationPage] Don't raise NavigatedTo early for a page pushed during the initial navigation - #40795

Merged
kubaflo merged 1 commit into
net11from
fix-net11-navigationpage-initial-navigated
Nov 29, 2026
Merged

kubaflo merged 1 commit into
net11from
fix-net11-navigationpage-initial-navigated

Conversation

@kubaflo

@kubaflo kubaflo commented Nov 29, 2026

Copy link
Copy Markdown
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!

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: d1f1c3803dfb83a81deaeedf0fcc19a3919871a0

Dimension Assessment Rationale
Change confidence 8/10 ↑ Red/green/revert/restore on macOS: the added unit test fails on net11 without the guard (Expected 0, Actual 1), passes with it, fails again when reverted, passes when restored.
↑ 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.
Diagnosis confidence 6/10 ↑ The race is real and reproduced deterministically by the unit test.
↑ 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.
Evidence fit 6/10 ↑ The crash reproduces on every net11 run (packaged and unpackaged, two heads) and not on main, where only this guard differs in the navigation path.
↓ Not confirmed until maui-pr-uitests runs on this PR; if NavigationPage still crashes the diagnosis is wrong.

Target Branch

  • I selected the applicable base branch (net11, .NET 11 fix, for review).

Description of Change

Backports the NavigationPage.cs hunk and its unit test from #40537 (already on main).

When the handler connects, NavigationPage starts an initial navigation whose completion callback called SendNavigated(null, ...), which reads CurrentPage. If a page is pushed right after the handler connects, CurrentPage is already the pushed page by the time the callback runs, so its NavigatedTo is raised before its own navigation has run. The callback now only sends the initial Navigated when CurrentPage is still the page that navigation was for; the pushed page gets its NavigatedTo from its own navigation.

This is the scenario of the Windows device test SettingTitleIconImageSourceDoesntCrash, which pushes a NavigationPage right after the window handler is created. That test crashes the test host (exit 7, no managed stack) on every net11 run of maui-pr-uitests (build 1703903, packaged and unpackaged) and passes on main, where this guard is present.

Validation (macOS, Controls.Core.UnitTests, net11.0):

  • Baseline, test only: APushMadeBeforeTheInitialNavigationFinishesGetsNavigatedToOnlyFromItsOwnNavigation fails (Expected 0, Actual 1).
  • With the guard: passes; NavigationPageLifecycleTests 10/10.
  • Guard reverted: fails again (Actual 1).
  • Guard restored: passes; navigation tests 317/317.

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.

…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>
@kubaflo

kubaflo commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

@dalexsoto stamp

@kubaflo
kubaflo temporarily deployed to copilot-pat-pool November 29, 2026 09:28 — with GitHub Actions Inactive
@github-actions

This comment has been minimized.

@kubaflo
kubaflo temporarily deployed to copilot-pat-pool November 29, 2026 09:28 — with GitHub Actions Inactive
@azure-pipelines

This comment has been minimized.

@kubaflo

This comment has been minimized.

@azure-pipelines

This comment has been minimized.

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>
@kubaflo
kubaflo merged commit 0c2cd24 into net11 Nov 29, 2026
181 of 182 checks passed
@kubaflo
kubaflo deleted the fix-net11-navigationpage-initial-navigated branch November 29, 2026 16:45

This branch was previously deployed

1 inactive deployment
copilot-pat-pool — d1f1c380 Deployed Nov 29, 2026 by kubaflo via conclusion #3465
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant