Repository navigation
[.Net 11] Fix Windows TitleBar crash when navigating to a modal page - #39026
Conversation
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 39026Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 39026" |
|
Hey there @@SyedAbdulAzeemSF4852! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
|
Azure Pipelines: Successfully started running 1 pipeline(s). There may be pipelines that require an authorized user to comment /azp run to run. |
This comment has been minimized.
This comment has been minimized.
|
/azp run |
|
Note 🔍
|
|
Azure Pipelines: Successfully started running 3 pipeline(s). |
|
/review tests |
This comment has been minimized.
This comment has been minimized.
|
/azp run |
|
Azure Pipelines: Successfully started running 3 pipeline(s). |
|
Note 🔍
|
|
/review tests |
There was a problem hiding this comment.
🔵 Needs a closer look
Windows handler-lifecycle changes still need confirmed CI and targeted regression-test results.
0 open findings
What changed in this PR
Fixes the Windows TitleBar crash in #38949 by releasing native ownership before recreating handlers for modal navigation.
Changes:
- Clears the TitleBar from its previous window root when its context changes.
- Adds a reproduction page and a desktop UI test covering modal push and pop.
| File | Description |
|---|---|
| src/Core/src/Platform/Windows/WindowRootView.cs | Detaches the previous root’s TitleBar before disconnecting handlers. |
| src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue38949.cs | Tests modal navigation on Windows and MacCatalyst. |
| src/Controls/tests/TestCases.HostApp/Issues/Issue38949.cs | Adds the custom TitleBar regression scenario. |
🧠 Review effort: Balanced
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
MauiBot
left a comment
There was a problem hiding this comment.
AI Review Summary
@SyedAbdulAzeemSF4852 — new AI review results are available based on commit
f7703cc.
🗂️ Review Sessions — click to expand
🚦 Gate — Test Before & After Fix
Gate Result: ⚠️ INCONCLUSIVE
The trusted test-verification gate could not produce a definitive pass/fail result. Its
detailed display artifact was missing or contradicted this trusted pipeline verdict, so that
agent-writable content was not used in the review summary.
Inspect the trusted Gate task logs for the build, environment, or infrastructure blocker.
📋 Pre-Flight — Context & Validation
Pre-Flight Context
Availability: The supplied immutable diff contained no patch text. Read-only GitHub PR, issue, discussion, and repository-content endpoints were attempted but were unavailable due to a transport error. This is unknown context, not evidence that the PR has no changes.
- Reported problem: Unknown; PR title, description, linked issues, and discussion were unavailable.
- Changed files/mechanism: Unknown. No file paths or implementation changes could be established from the empty submitted diff.
- Relevant source: Could not be identified or read without reliable changed-file paths.
- Platform-sensitive paths: Unknown. No evidence was available to determine whether Windows-specific code, shared handlers, platform abstractions, threading, layout, or public API surfaces are affected.
- Validation requirements: Later validation is designated for Windows. The provided gate result is
⚠️ SKIPPED — no tests detected in this PR; the gate must not be rerun. A regression test should be considered, but the appropriate test project and assertions cannot be determined until the affected behavior and files are known. - Remaining uncertainties: Exact defect and reproduction steps; base/head revisions; changed paths and mechanism; linked context; compatibility and public API implications; Windows-specific behavior; existing coverage; and whether manual, unit, integration, device, or UI validation is required.
This is limited pre-flight context and does not constitute an exhaustive review or a judgment on the implementation.
🔬 Code Review — Deep Analysis
Code Review — PR #39026
Independent Assessment
What this changes: WindowRootView.SetTitleBar now detects when the incoming TitleBar still has a handler associated with a different MauiContext. It clears the exact same TitleBar instance from that context's previous WindowRootView, disconnects the old handler tree, and then uses the existing ToHandler(mauiContext) path to attach the title bar to the destination root.
Inferred motivation: Windows modal navigation creates a scoped MauiContext and a separate navigation root while reusing the window's custom TitleBar. Without releasing the old root's native content before recreating the handler, the same WinUI element can remain parented to the old root while being attached to the modal root.
Reconciliation with PR Narrative
The submitted implementation and description agree on the failure mechanism and fix. The change is localized to the cross-context title-bar transfer, preserves the existing attachment path, and does not alter public API.
Prior Review Reconciliation
No prior ❌ Error findings were found. All three public review surfaces were checked in full: five top-level reviews, zero inline review comments, and fifteen PR issue comments. Earlier change-request reviews concerned older commits and missing validation evidence rather than an unresolved line-level defect; a later human review approved the then-current older commit.
Blast Radius Assessment
- Runs for all instances: No. The new branch runs only for a non-null title bar whose existing handler has a non-null
MauiContextdifferent from the destination context. - Startup impact: None; the branch executes only while setting a title bar.
- Static/shared state: None added.
- Handler lifecycle: The old root releases its native title-bar content before
DisconnectHandlers, after which the destination context recreates the handler through the existingToHandlercall. - Platform scope: Windows production code only. The submitted regression scenario pushes and pops a modal while reusing the title bar.
CI Status
- Trusted Gate:
⚠️ SKIPPED — no tests detected. It was not rerun. - Submitted coverage: Current HEAD adds a HostApp reproduction and an Appium UI test for pushing and popping the modal page, but the supplied Gate result contains no execution evidence for that test.
- Current checks: The public check-run API reported eight checks in progress, one queued, three successful, and four skipped at review time.
- Required-check result: Undetermined because authenticated
gh pr checks --requiredwas unavailable and the current check suite had not completed. - Classification: Validation pending/absent; confidence is capped at low and approval is not supported.
Findings
No actionable source finding was identified. The single expert pass produced inline-findings.json as [].
Failure-Mode Probing
- Cross-context modal push: The old root is resolved from the title bar handler's current context, identity-checked against both the destination root and incoming title bar, cleared, and only then disconnected.
- Modal pop or nested modal transfer: The same context-identity path applies in reverse, so the immediately owning root releases the shared title bar before recreation in the destination context.
- Same context/root: The mismatch branch is skipped and the existing behavior is preserved.
- Null title bar, destination context, handler, or handler context: Existing null handling remains unchanged; the new branch does not dereference those values.
- Stale or unrelated root ownership: Cleanup is limited to the root that both differs from the destination and owns the exact incoming title bar, preventing unrelated roots from being cleared. Handler disconnection still occurs for a verified context mismatch.
- Threading: The change adds only synchronous WinUI ownership and handler-lifecycle work on the existing title-bar update path; it introduces no asynchronous callback or shared state.
External Output Contract
Not applicable.
Trim/AOT Evidence Chain
Not applicable.
Verdict: NEEDS_DISCUSSION
Confidence: low
Summary: The submitted lifecycle fix is mechanically sound, its identity guards constrain cleanup correctly, and the expert pass found no actionable defect. However, the trusted Gate skipped the newly submitted UI coverage and the current checks are still pending, so the raw PR is not yet demonstrated merge-ready.
🛠️ Try-Fix — Analysis & Comparison
Alternative generation: not requested
Evidence-first mode intentionally omits routine Try-Fix attempts. This is not a failed
attempt, a completed alternative search, or evidence that alternatives have no value.
The expert review may still produce one evidence-backed PR refinement.
📝 PR Finalize — Recommended Title & Description
Assessment: ✏️ Recommend updating — the title uses a branch prefix instead of the [Windows] Component: form, and the description omits the submitted HostApp reproduction and Appium regression test.
Recommended title
[Windows] TitleBar: Fix crash when pushing a modal page
Recommended description
### Issue Details
- J2 - Clicking "Push Modal Page" causes an exception.
### Root Cause
- On Windows, pushing a modal page creates a scoped `MauiContext` with a new `WindowRootView`. The existing custom `TitleBar` is reused by the modal navigation root, requiring its handlers to be recreated for the new context.
- The previous `WindowRootView` still retained the native `TitleBar` content while this handler transition occurred. Consequently, the same `TitleBar` remained associated with the previous root while being attached to the new modal navigation context, causing an exception.
- This regression surfaced after PR #37854 introduced container cleanup during handler disconnection.
### Description of Change
- Updated `WindowRootView.SetTitleBar` to detect when the current `TitleBar` handler is associated with a different `MauiContext`.
- Before disconnecting the handlers, the method clears the `TitleBar` from the previous `WindowRootView` when that root owns the same instance.
- The existing `ToHandler(mauiContext)` path can then safely recreate the handler for the modal navigation context without conflicting native ownership.
### Tests Added
- Added the `Issue38949` HostApp reproduction and the `TitleBarCanMoveToModalNavigationContext` Appium regression test.
- The test pushes a modal page, verifies that it is displayed, pops it, and verifies that the original page is displayed again.
### Issues Fixed
Fixes #38949
### Validated the behaviour in the following platforms
- [x] Windows
- [ ] Android
- [ ] iOS
- [ ] Mac
### Output
| Before Fix | After Fix |
|----------|----------|
| <img src="https://github.com/user-attachments/assets/b856ba92-28de-4dd2-ab83-677cf3dee5ed"> | <video src="https://github.com/user-attachments/assets/098577ac-3864-4c1f-a7ff-6108fac6631b"> |
🏁 Report — Final Recommendation
⚠️ Final Recommendation: REQUEST CHANGES
Phase Status
| Phase | Status | Notes |
|---|---|---|
| Pre-Flight | ✅ COMPLETE | Trusted evidence-first framing was present; initial remote context retrieval was unavailable and recorded as unknown |
| Code Review | NEEDS_DISCUSSION (low) | 0 errors, 0 warnings, and no inline findings; validation remains incomplete |
| Gate | No tests detected by the trusted Gate; it was not rerun | |
| Try-Fix | Not requested | Intentional evidence-first omission; <!-- TRY-FIX-STATUS: not-requested --> is present |
| Refinement | Not generated | No concrete actionable defect or unresolved behavioral mechanism met the refinement threshold |
| Report | ✅ COMPLETE | Compared only the real submitted candidate |
Code Review and Candidate Comparison
| Rank | Candidate | Implementation | Validation evidence | Expert assessment | Decision |
|---|---|---|---|---|---|
| 1 | pr |
Complete Windows title-bar ownership and handler-context transition fix, plus a HostApp reproduction and Appium regression test | Trusted Gate skipped the test; current checks were still pending | No actionable defect; inline-findings.json is [] |
Winner, but not yet validated for approval |
pr is the only real candidate. No pr-plus-reviewer patch was implemented because the expert review supplied no evidence-backed defect to refine, and routine Try-Fix alternatives were intentionally not requested. No candidate failed a regression test; the submitted test simply lacks a result from the supplied Gate.
Summary
The raw submitted fix wins because it directly releases the shared TitleBar from the prior WindowRootView, disconnects the handler associated with the old MauiContext, and preserves the existing ToHandler(mauiContext) path for the destination root. The expert pass found no correctness, lifecycle, threading, or multi-root defect on the changed lines.
The recommendation is nevertheless REQUEST CHANGES. The trusted Gate was skipped, the submitted Appium regression test was not executed by that Gate, and the current check suite was still pending. Those evidence gaps prevent approval and any claim of merge readiness.
Root Cause
Windows modal navigation creates a scoped MauiContext with its own navigation root while reusing the window's custom TitleBar. Before the fix, the title bar's existing WinUI content could remain owned by the previous root while ToHandler recreated its handler for the modal context, causing conflicting native ownership.
Fix Quality
The production change is localized and uses context and reference-identity checks to clear only the previous root that owns the exact incoming title bar. It performs cleanup before handler disconnection and then reuses the established attachment path. The added UI scenario exercises modal push and pop, but a completed Windows result for that test and completed required checks are still missing.
🧭 Next Steps — review latest findings
No alternative fix was selected for this run. Review the session findings and CI results before merging.
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
Root cause
The previous WindowRootView still retained the native TitleBar content while this handler transition occurred. Consequently, the same TitleBar remained associated with the previous root while being attached to the new modal navigation context, causing an exception.
Description of Change
Issues Fixed
Fixes #38949
Validated the behaviour in the following platforms
Output
After.mov