Skip to content

[.Net 11] Fix Windows TitleBar crash when navigating to a modal page - #39026

Merged
kubaflo merged 2 commits into
dotnet:net11.0from
SyedAbdulAzeemSF4852:fix-38949
Oct 15, 2026
Merged

kubaflo merged 2 commits into
dotnet:net11.0from
SyedAbdulAzeemSF4852:fix-38949

Conversation

@SyedAbdulAzeemSF4852

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!

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 Add ViewHandler.SetContainerView so external platform backends can manage ContainerView #37854 introduced container cleanup during handler disconnection.

Description of Change

  • Added logic to detect when the current TitleBar is associated with a different MauiContext. Before disconnecting its handlers, the TitleBar is cleared from the previous WindowRootView when that root owns the same instance. This allows the TitleBar to be safely recreated for the new context without conflicting native ownership.

Issues Fixed

Fixes #38949

Validated the behaviour in the following platforms

  • Windows
  • Android
  • iOS
  • Mac

Output

Before Fix After Fix
After.mov

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 39026

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 39026"

@dotnet-policy-service dotnet-policy-service Bot added the community ✨ Community Contribution label Sep 30, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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.

@dotnet-policy-service dotnet-policy-service Bot added the partner/syncfusion Issues / PR's with Syncfusion collaboration label Sep 30, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
There may be pipelines that require an authorized user to comment /azp run to run.

@kubaflo

This comment has been minimized.

@kubaflo

kubaflo commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

/azp run

@github-actions github-actions Bot added the s/agent-review-in-progress AI review is currently running for this PR label Sep 30, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Note

🔍 /review started

AzDO build 15523174 is running for windows.

The s/agent-review-in-progress label stays on this PR while the run is active. The final recommendation and outcome labels are posted only after Gate, expert review, and Deep UI tests finish.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

MauiBot

This comment was marked as outdated.

@MauiBot MauiBot added s/agent-changes-requested AI agent recommends changes - found a better alternative or issues s/agent-fix-pr-picked AI could not beat the PR fix - PR is the best among all candidates s/agent-reviewed PR was reviewed by AI agent workflow (full 4-phase review) and removed s/agent-review-in-progress AI review is currently running for this PR labels Sep 30, 2026
@kubaflo

kubaflo commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

/review tests

@SyedAbdulAzeemSF4852 SyedAbdulAzeemSF4852 changed the title [WIP][.Net 11] Fix Windows TitleBar crash when navigating to a modal page [.Net 11] Fix Windows TitleBar crash when navigating to a modal page Oct 1, 2026
@kubaflo

This comment has been minimized.

@kubaflo

kubaflo commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

@github-actions github-actions Bot added the s/agent-review-in-progress AI review is currently running for this PR label Oct 1, 2026
@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Note

🔍 /review started

AzDO build 15532460 is running for windows.

The s/agent-review-in-progress label stays on this PR while the run is active. The final recommendation and outcome labels are posted only after Gate, expert review, and Deep UI tests finish.

MauiBot

This comment was marked as outdated.

@MauiBot MauiBot added s/agent-gate-passed AI verified tests catch the bug (fail without fix, pass with fix) and removed s/agent-review-in-progress AI review is currently running for this PR labels Oct 1, 2026
@kubaflo

kubaflo commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

/review tests

@kubaflo kubaflo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this one ready?

@sheiksyedm
sheiksyedm marked this pull request as ready for review October 15, 2026 12:06
Copilot AI balanced review requested due to automatic review settings October 15, 2026 12:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 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

@kubaflo

This comment has been minimized.

@github-actions github-actions Bot added the s/agent-review-in-progress AI review is currently running for this PR label Oct 15, 2026
@kubaflo

This comment has been minimized.

@kubaflo
kubaflo merged commit 1653689 into dotnet:net11.0 Oct 15, 2026
154 of 169 checks passed
@github-actions github-actions Bot added this to the .NET 11.0-rc2 milestone Oct 15, 2026

@MauiBot MauiBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

AI Review Summary

@SyedAbdulAzeemSF4852 — new AI review results are available based on commit f7703cc.

Gate Inconclusive Confidence Low Platform Windows


🗂️ 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 MauiContext different 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 existing ToHandler call.
  • 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 --required was 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 ⚠️ SKIPPED 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.

@MauiBot MauiBot removed s/agent-gate-passed AI verified tests catch the bug (fail without fix, pass with fix) s/agent-fix-pr-picked AI could not beat the PR fix - PR is the best among all candidates s/agent-review-in-progress AI review is currently running for this PR labels Oct 15, 2026
@github-actions github-actions Bot modified the milestones: .NET 11.0-rc2, .NET 11.0 GA Nov 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-controls-titlebar community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration platform/windows s/agent-changes-requested AI agent recommends changes - found a better alternative or issues s/agent-reviewed PR was reviewed by AI agent workflow (full 4-phase review)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[MAUI][NET11] J2 - Clicking "Push Modal Page" would cause an exception

4 participants