Skip to content

[Inflight/Candidate][Android] Fix for Android page disconnection during Loaded root replacement - #39279

Merged
kubaflo merged 2 commits into
dotnet:inflight/candidatefrom
BagavathiPerumal:fix-39278
Oct 14, 2026
Merged

kubaflo merged 2 commits into
dotnet:inflight/candidatefrom
BagavathiPerumal:fix-39278

Conversation

@BagavathiPerumal

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!

Root cause

The issue occurs because (#38784) restored synchronous Android Loaded dispatch. In the two tests added by (#38214), the Shell or FlyoutPage child can raise Loaded while the Android device-test host is still creating its initial WindowTestFragment. The Loaded handler then replaces Window.Page during fragment initialization.

In the captured run, the root replacement completed, but the test delegate was never reached because the host was still waiting for its fragment setup to complete. This resulted in the test appearing to hang.

Separately, when a loaded outgoing page is disconnected through the Android Window, its handler may not have a usable platform view. Disconnecting it at that point can result in a Handler is not set on element failure.

Solution description

The fix involves using the outgoing page’s native unload event to defer handler disconnection on Android, where the standard Window handler wraps an Activity rather than a platform View. If the outgoing page has no usable native view, its handlers are disconnected directly. Before performing deferred cleanup, the fix checks that the page has not been reparented or reloaded and still has its outgoing handler, ensuring that a reused page is not disconnected. Synchronous Android Loaded behavior remains unchanged.

The Shell and FlyoutPage tests now start with a placeholder page and install the root page after the test host is ready. They still replace the root page from the child’s Loaded callback and verify that the replacement is attached successfully.

Regression PR

PR #38784

Validated the behavior in the following platforms

  • Android
  • Mac
  • Window
  • iOS

Issues Fixed

Fixes #39278

Output

Platform Before After
Android
Loaded-BeforeFix.mov
Loaded-AfterFix.mov

@BagavathiPerumal BagavathiPerumal changed the title [Inflight/Candidate][Android] Fix for Android page disconnection during Loaded root replacement [WIP][Inflight/Candidate][Android] Fix for Android page disconnection during Loaded root replacement Oct 9, 2026
@dotnet-policy-service dotnet-policy-service Bot added the partner/syncfusion Issues / PR's with Syncfusion collaboration label Oct 9, 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.

@vishnumenon2684

Copy link
Copy Markdown
Contributor

/azp run maui-pr-uitests , maui-pr-devicetests

@azure-pipelines

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

@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 9, 2026
@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Note

🔍 /review started

AzDO build 15629009 is running for android.

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 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

@BagavathiPerumal — new AI review results are available based on commit 301a2b4.

Gate Inconclusive Confidence Low Platform Android


🗂️ Review Sessions — click to expand
🚦 Gate — Test Before & After Fix

Gate Result: ⚠️ INCONCLUSIVE

Platform: ANDROID · Base: inflight/candidate · Merge base: 29eb037a

🩺 Could not verify — environment/infrastructure error. The gate ran the tests but hit an environment error (an emulator/simulator/Appium/XHarness flake, a device that would not boot, or an empty/invalid result file), so it could not record a real pass/fail. The ⚠️ ENV ERROR marks below are infrastructure, not test failures — this is not a problem with your PR. Comment /review to retry on a fresh agent.

XHarness did not produce the expected fresh result 'testResults-175c704fd9724d309e1e0354d897a531.xml' for requested class(es) 'Microsoft.Maui.DeviceTests.WindowTests' (the target tests did not run).

Test Without Fix (expect FAIL) With Fix (expect PASS)
📱 WindowTests (ReplacingShellRootFromPageLoadedDoesNotCrash, ReplacingFlyoutRootFromDetailLoadedDoesNotCrash) Category=Window ⚠️ ENV ERROR ✅ PASS — 421s
🔴 Without fix — 📱 WindowTests (ReplacingShellRootFromPageLoadedDoesNotCrash, ReplacingFlyoutRootFromDetailLoadedDoesNotCrash): ⚠️ ENV ERROR · 480s

No log file found

🟢 With fix — 📱 WindowTests (ReplacingShellRootFromPageLoadedDoesNotCrash, ReplacingFlyoutRootFromDetailLoadedDoesNotCrash): PASS ✅ · 421s

(no coded error found; showing last 1200 chars)

            "totalMemoryBytes": 8322998272
          },
          "target": {
            "kind": "emulator",
            "name": "sdk_gphone_x86_64",
            "identifier": "emulator-5554",
            "operatingSystem": "Android",
            "operatingSystemVersion": "11",
            "apiLevel": 30,
            "architecture": "x86_64",
            "supportedArchitectures": [
              "x86_64",
              "x86",
              "arm64-v8a",
              "armeabi-v7a",
              "armeabi"
            ],
            "manufacturer": "Google",
            "model": "sdk_gphone_x86_64",
            "productName": "sdk_gphone_x86_64",
            "buildFingerprint": "google/sdk_gphone_x86_64/generic_x86_64_arm64:11/RSR1.201211.001/7027799:user/release-keys",
            "cpuModel": "0",
            "cpuMaxFrequencyHertz": 2000,
            "totalMemoryBytes": 2077544448
          }
        }
      }
      <<XHARNESS_RESULT_END>>
info: Attempting to remove apk 'com.microsoft.maui.controls.devicetests'..
info: Successfully uninstalled com.microsoft.maui.controls.devicetests
XHarness exit code: 0
  Passed: 2
  Failed: 0
  Skipped: 0
  Total: 2
  Tests completed successfully

⚠️ Failure Details

  • ⚠️ WindowTests (ReplacingShellRootFromPageLoadedDoesNotCrash, ReplacingFlyoutRootFromDetailLoadedDoesNotCrash) without fix: XHarness did not produce the expected fresh result 'testResults-175c704fd9724d309e1e0354d897a531.xml' for requested class(es) 'Microsoft.Maui.DeviceTests.WindowTests' (the target tests did not run).
📁 Fix files reverted (2 files)
  • src/Controls/src/Core/Window/Window.Android.cs
  • src/Controls/src/Core/Window/Window.cs

📋 Pre-Flight — Context & Validation

Pre-Flight Context

Scope: Evidence-only context for draft PR #39279. This is not an exhaustive review, recommendation, or comparison of solutions.

PR and reported problem

  • Target: inflight/candidate at 29eb037ad1cac21acdc052bc7a1211a8bb37d3c9
  • Submitted head: 301a2b42bfe6b8eebacb765887ae098dab3afe33
  • Size: 3 files, +50/-7
  • Linked issue: #39278, an Android-only regression reported against the candidate branch.
  • The issue describes the Android device-test run as crashing after #38784, but provides no reproduction steps, platform version, textual logs, or stack trace.
  • The PR description characterizes the observed behavior more specifically as a stall/hang: after #38784 restored synchronous Android Loaded dispatch, Shell and FlyoutPage child pages can raise Loaded while the device-test host is still creating its initial fragment. Their handlers replace Window.Page reentrantly, and the host allegedly never reaches the test delegate even though root replacement completes.
  • The PR also reports a distinct cleanup failure: invoking OnUnloaded through an Android Window can throw "Handler is not set on element" because the standard Android WindowHandler wraps an Activity, whereas the lifecycle helper expects an IPlatformViewHandler backed by an Android View.
  • #38784 changed Android OnLoaded from a posted callback to immediate execution. Its own description says device/UI tests were not run.
  • The affected replacement tests originated in #38214, whose Android root-management changes address asynchronous Shell/Flyout fragment transactions and root replacement.

Submitted mechanism

File Change
src/Controls/src/Core/Window/Window.cs For a loaded outgoing page, calls a new partial HandleLoadedPageDisconnect hook before using the existing Window.OnUnloaded fallback. Unloaded outgoing pages still disconnect immediately.
src/Controls/src/Core/Window/Window.Android.cs Implements Android-specific cleanup selection.
src/Controls/tests/DeviceTests/Elements/Window/WindowTests.cs Adjusts the existing Shell and FlyoutPage root-replacement tests to install their real roots only after the host callback starts.

The Android partial follows three paths:

  1. If the Window handler itself is an IPlatformViewHandler with a platform view, it leaves disconnectHandled false, preserving the common Window.OnUnloaded fallback.
  2. Otherwise, if the outgoing page has an IPlatformViewHandler with a platform view, it captures the current handler and registers cleanup on that page’s native unload event. At callback time it disconnects only when:
    • the page still has the captured outgoing handler;
    • the page has no visual parent; and
    • page.IsLoaded is false.
  3. If the outgoing page lacks a usable platform view, it disconnects immediately.

For paths 2 and 3, it marks cleanup as handled so the common window-based unload callback is not registered.

Relevant source contracts confirm:

  • Android WindowHandler is an ElementHandler<IWindow, Activity>.
  • Android IPlatformViewHandler represents handlers backed by Android.Views.View, so the standard window handler does not provide the view lifecycle expected by IElement.OnUnloaded.
  • IElement.OnUnloaded requires a non-null IPlatformViewHandler.PlatformView; otherwise it throws "Handler is not set on element".
  • DisconnectHandlers builds a stable visual-tree list and disconnects each handler, while stopping traversal at elements using manual disconnect policy.

The two modified tests now:

  • construct the Window with a placeholder ContentPage;
  • enter CreateHandlerAndAddToWindow;
  • subscribe to the Shell child or Flyout detail page’s Loaded event;
  • assign the Shell/Flyout root;
  • replace Window.Page from that child’s synchronous Loaded callback; and
  • wait for the replacement page and assert it is attached to the navigation root.

Platform-sensitive paths

  • Android: The functional specialization is Android-only and depends on Android native view attach/detach lifecycle, synchronous Loaded timing, and Shell/Flyout AndroidX fragment transactions.
  • Shared Controls: Window.cs changes for every target, but targets without an implementation of the partial method retain the existing window-unload fallback.
  • Shell/Flyout: The modified device scenarios exercise reentrant root replacement from child Loaded, with fragment-backed navigation roots.
  • Handler lifetime: Correctness depends on distinguishing an Activity-backed window handler from a View-backed page handler and on avoiding disconnection after a page has been reparented, reloaded, or assigned a different handler.
  • Prior regression surface: #36673 also modified Window.cs, but for Shell/native-window title semantics. Its ShellToolbarTests cross-reference is therefore mandatory despite not directly exercising the new Android unload path.

Required later validation

Testing is required on Android. No commands or tests were executed during this context-gathering step.

Primary validation should exercise at least:

  • ReplacingShellRootFromPageLoadedDoesNotCrash
  • ReplacingFlyoutRootFromDetailLoadedDoesNotCrash
  • completion without a host stall, process crash, missing fragment-container error, or "Handler is not set on element" exception;
  • successful attachment of the replacement page;
  • deferred disconnection only after the outgoing page’s native view unloads;
  • preservation of a page that is reparented, reloaded, or assigned a new handler before deferred cleanup;
  • immediate cleanup when the outgoing page has no usable native view.

After the primary validation succeeds, the mandated regression test is:

dotnet test src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj --filter "ShellToolbarTests"

A failure of that regression test makes a later candidate fail. The supplied Gate result is inconclusive because tests could not be built or run due to a build/environment error; it is not evidence that the fix failed, must not independently cause a change request, and must not be rerun here.

Available and unavailable evidence

  • The PR description marks Android as validated and supplies before/after video attachments, but those attachments were not independently assessed here.
  • PR comments show that maui-pr-uitests, maui-pr-devicetests, and a review build were started. No completed pipeline or test result was available in the read-only PR discussion examined.
  • No reviews had been submitted at the time of retrieval.
  • The exact Gate build/environment failure is unknown.
  • The issue’s referenced Azure build details, textual failure output, exception stack, affected Android API level, and deterministic reproduction sequence are unknown.
  • It remains uncertain whether “crash,” “hang,” and the reported handler exception are manifestations of one sequence or separate failures.
  • The tests now perform replacement after the host callback begins, while the PR says the observed stall occurred during initial fragment creation. They preserve replacement from child Loaded, but how closely the revised setup represents the original failing timing remains for dedicated validation.
  • The submitted test changes assert replacement attachment, but do not directly assert outgoing-handler disconnection timing or each reuse guard.
  • Buildability and behavior on non-Android targets remain unverified.

🔬 Code Review — Deep Analysis

Code Review — PR #39279

Independent Assessment

What this changes: Loaded outgoing pages now pass through a platform hook before the shared Window.OnUnloaded cleanup path. On Android, an outgoing page with a usable native view defers handler disconnection until that view unloads; the callback disconnects only if the page still has the captured handler, remains detached, and is no longer loaded. Pages without a usable native view disconnect immediately. The Shell and FlyoutPage device tests now install their real root after the host callback begins while retaining replacement from a child Loaded callback.

Inferred motivation: Android's standard WindowHandler is backed by an Activity, not an Android View, so it cannot provide the native view lifecycle required by the generic unload helper. Page-level native unload provides the appropriate deferred cleanup point without disconnecting a page that was reused before the callback.

Reconciliation with PR Narrative

Author claims: Synchronous Android Loaded dispatch can reenter root replacement during host fragment initialization, and window-based unload cleanup can fail when the window handler has no usable platform view.

Agreement/disagreement: The submitted implementation and test changes match those claims. The tests preserve replacement from a Shell/Flyout child Loaded callback while moving initial root installation past host setup. The diff does not directly assert deferred-disconnection timing or each page-reuse guard, so those behaviors remain reasoned from source rather than independently validated.

Prior Review Reconciliation

No prior error-level findings were found on the top-level review, inline-review, or PR issue-comment surfaces examined by the expert reviewer.

Blast Radius Assessment

  • Runs for all instances: No. The shared hook is reached only when replacing a loaded Window.Page; the specialized behavior is Android-only.
  • Startup impact: Limited to root replacement that occurs during page/window setup; there is no unconditional startup path.
  • Static/shared state: None introduced.

CI Status

  • Required-check result: Undetermined; authenticated required-check retrieval was unavailable.
  • Gate: ⚠️ INCONCLUSIVE because the supplied Gate could not build or run the tests.
  • Classification: Missing validation evidence, not a demonstrated test failure.
  • Action taken: Gate was not rerun. Confidence is capped at low.

Findings

No concrete actionable defects were validated on modified right-side lines. inline-findings.json contains an empty JSON array.

Failure-Mode Probing

  • Activity-backed window handler: The normal Android window handler does not satisfy the view-backed unload contract, so the Android hook proceeds to page-level cleanup rather than registering generic unload against the Activity.
  • Page with a usable native view: Cleanup waits for the page's native unload and verifies the captured handler, detached parent state, and unloaded state before disconnecting.
  • Reparented, reloaded, or rehandled page: Any failed guard makes the deferred callback a no-op, avoiding disconnection of a reused page.
  • Page without a usable native view: The implementation disconnects immediately because no native unload can be observed.
  • Duplicate cleanup/subscription lifetime: The Android path marks cleanup handled, so the shared window fallback is not also registered. No persistent or static subscription state is added.
  • Reentrant Shell/Flyout replacement: Both modified tests retain Window.Page replacement inside the child page's synchronous Loaded callback after the host callback has begun.

External Output Contract

Not applicable.

Test Fidelity

The modified Android device tests retain the core reentrant root-replacement action and assert that the replacement page attaches. They do not directly cover deferred disconnect timing, the immediate-disconnect fallback, or each reuse guard. Gate and required regression validation remain unavailable.

Verdict: NEEDS_DISCUSSION

Confidence: low

Summary: Source review found no blocking defect or evidence-backed mechanism requiring a reviewer refinement. Approval is not supported because the submitted candidate remains unvalidated: Gate was inconclusive and required-check status could not be established.


🛠️ 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 description is detailed and accurate, but the title contains workflow noise ([WIP][Inflight/Candidate]) instead of the repository's [Platform] Component: What changed form.

Recommended title

[Android] Window: Defer outgoing page disconnection during Loaded root replacement

Recommended description

### Root cause

The issue occurs because https://github.com/dotnet/maui/pull/38784 restored synchronous Android `Loaded` dispatch. In the two tests added by https://github.com/dotnet/maui/pull/38214, the Shell or FlyoutPage child can raise `Loaded` while the Android device-test host is still creating its initial `WindowTestFragment`. The `Loaded` handler then replaces `Window.Page` during fragment initialization.

In the captured run, the root replacement completed, but the test delegate was never reached because the host was still waiting for its fragment setup to complete. This resulted in the test appearing to hang.

Separately, when a loaded outgoing page is disconnected through the Android `Window`, its handler may not have a usable platform view. Disconnecting it at that point can result in a "Handler is not set on element" failure.

### Solution description

The fix uses the outgoing page's native unload event to defer handler disconnection on Android, where the standard `WindowHandler` wraps an `Activity` rather than a platform `View`. If the outgoing page has no usable native view, its handlers are disconnected directly. Before performing deferred cleanup, the fix checks that the page has not been reparented or reloaded and still has its outgoing handler, ensuring that a reused page is not disconnected. Synchronous Android `Loaded` behavior remains unchanged.

The implementation:

- adds a platform hook in `Window.cs` while preserving the existing shared window-unload fallback;
- implements Android page-level deferred or immediate cleanup in `Window.Android.cs`; and
- updates the Shell and FlyoutPage scenarios in `WindowTests.cs`.

The Shell and FlyoutPage tests now start with a placeholder page and install the root page after the test host is ready. They still replace the root page from the child's `Loaded` callback and verify that the replacement is attached successfully.

### Regression PR

https://github.com/dotnet/maui/pull/38784

### Platforms validated

- [x] Android
- [ ] Mac
- [ ] Windows
- [ ] iOS

### Issues Fixed

Fixes https://github.com/dotnet/maui/issues/39278

### Output

| Platform | Before | After |
|---|---|---|
| Android | <video src="https://github.com/user-attachments/assets/12fb957d-c709-412b-824a-8bbea5efc152"> | <video src="https://github.com/user-attachments/assets/ff404e4a-2aa9-4e01-a385-6a05415383df"> |

🏁 Report — Final Recommendation

⚠️ Final Recommendation: REQUEST CHANGES

Phase Status

Phase Status Notes
Pre-Flight ✅ COMPLETE Trusted evidence-first context consumed
Code Review NEEDS_DISCUSSION (low) 0 errors, 0 warnings; validation evidence is incomplete
Gate ⚠️ INCONCLUSIVE Android tests could not be built or run; this is not a demonstrated fix failure
Try-Fix not requested Evidence-first mode intentionally omitted alternative generation
Refinement Not generated No concrete actionable defect or unresolved mechanism met the refinement threshold
Report ✅ COMPLETE Raw PR assessed as the sole real candidate

Code Review and Candidate Comparison

Candidate Expert Findings Addressed Validation Rank
pr No concrete defect was found on modified lines Unverified: Gate was inconclusive, required-check status was unavailable, and the mandatory regression test was not reached 1

The raw submitted PR is the only implemented candidate. The expert review found no source-backed defect that would justify a pr-plus-reviewer refinement, and routine Try-Fix alternatives were intentionally not requested. Selecting pr therefore records the best available implementation; it does not establish merge readiness.

Summary

The Android lifecycle approach is coherent: it avoids using an Activity-backed window handler as a view unload source, defers cleanup to the outgoing page's native unload when possible, and guards against disconnecting a page that was reparented, reloaded, or assigned a new handler. The revised Shell and FlyoutPage tests retain root replacement from a child Loaded callback after moving initial root installation beyond host setup.

The recommendation remains REQUEST CHANGES because approval requires validated evidence and an expert verdict without blocking discussion. Gate was inconclusive rather than failing, so this report does not conclude that the fix is incorrect; it records that Android primary validation and the required ShellToolbarTests regression check remain unproven.

Root Cause

Synchronous Android Loaded dispatch can reenter Window.Page replacement while the host is still initializing fragment-backed Shell or FlyoutPage content. Cleanup through the shared window unload path is also unsuitable for the normal Android WindowHandler, whose platform object is an Activity rather than the Android View required by the element unload helper.

Fix Quality

The submitted fix is localized, introduces no shared/static state, preserves the existing shared fallback for view-backed window handlers, and has explicit page-reuse guards around deferred disconnection. Its device-test changes exercise the reported reentrant replacement and final attachment, but do not directly assert deferred cleanup timing, immediate fallback behavior, or each reuse guard. With no successful isolated validation, the candidate must remain unapproved despite the absence of a validated code defect.


🔗 Regression Cross-Reference

🔍 Regression Cross-Reference

⚠ Overlaps with prior bug-fix PRs — same files modified, but no exact line revert detected.

File Fix PR Fixed issue(s)
src/Controls/src/Core/Window/Window.cs #36673 #36562

🧪 Regression Tests to Verify

These tests were added by the overlapping fix PRs. Running them to verify no side-effect regressions:

Fix PR Type Test Filter
#36673 UnitTest ShellToolbarTests ShellToolbarTests

🧪 Regression Test Results

✅ PASSED — 1 passed, 0 failed, 0 skipped

Fix PR Test Type Result
#36673 ShellToolbarTests UnitTest ✅ PASSED

📱 UI Tests — Window

Detected UI test categories: Window

⚠️ Deep UI tests — 0 passed, 0 failed across 1 category on platform-pool agent (replaces in-process counts above). 1 category reported 0 tests.

🧪 UI Test Execution Results (deep, platform pool)

Category Tests Snapshot diffs
Window 0 tests —
📎 Download drop-deep-uitests artifact (TRX + snapshot diffs)

🧭 Next Steps — review latest findings

No alternative fix was selected for this run. Review the session findings and CI results before merging.

@MauiBot MauiBot added 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) and removed s/agent-review-in-progress AI review is currently running for this PR labels Oct 9, 2026
@kubaflo

This comment has been minimized.

@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Tests Failure Analysis

@BagavathiPerumal — test-failure analysis for commit 301a2b4.

Scope CI failures Commit 301a2b4


🧪 CI Analysis — click to expand
📊 maui-pr

No failures found.


🧪 maui-pr-devicetests

🧪 maui-pr-uitests

🧭 Follow-up — actions and refresh

Next action: Restore complete results/crash stacks; compare unresolved cases at base/head with identical setup.

Maintainers: comment /review tests to refresh this report.

@BagavathiPerumal BagavathiPerumal changed the title [WIP][Inflight/Candidate][Android] Fix for Android page disconnection during Loaded root replacement [Inflight/Candidate][Android] Fix for Android page disconnection during Loaded root replacement Oct 12, 2026
@kubaflo
kubaflo force-pushed the inflight/candidate branch from fc9cb78 to 302e289 Compare October 13, 2026 11:50
dependabot Bot and others added 2 commits October 13, 2026 18:49
Updated
[Microsoft.AspNetCore.Authentication.Facebook](https://github.com/dotnet/dotnet)
from 10.0.0 to 10.0.10.

<details>
<summary>Release notes</summary>

_Sourced from [Microsoft.AspNetCore.Authentication.Facebook's
releases](https://github.com/dotnet/dotnet/releases)._

No release notes found for this version range.

Commits viewable in [compare
view](https://github.com/dotnet/dotnet/commits).
</details>

Updated
[Microsoft.AspNetCore.Authentication.Google](https://github.com/dotnet/dotnet)
from 10.0.0 to 10.0.10.

<details>
<summary>Release notes</summary>

_Sourced from [Microsoft.AspNetCore.Authentication.Google's
releases](https://github.com/dotnet/dotnet/releases)._

No release notes found for this version range.

Commits viewable in [compare
view](https://github.com/dotnet/dotnet/commits).
</details>

Updated
[Microsoft.AspNetCore.Authentication.MicrosoftAccount](https://github.com/dotnet/dotnet)
from 10.0.0 to 10.0.10.

<details>
<summary>Release notes</summary>

_Sourced from [Microsoft.AspNetCore.Authentication.MicrosoftAccount's
releases](https://github.com/dotnet/dotnet/releases)._

No release notes found for this version range.

Commits viewable in [compare
view](https://github.com/dotnet/dotnet/commits).
</details>

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore <dependency name> major version` will close this
group update PR and stop Dependabot creating any more for the specific
dependency's major version (unless you unignore this specific
dependency's major version or upgrade to it yourself)
- `@dependabot ignore <dependency name> minor version` will close this
group update PR and stop Dependabot creating any more for the specific
dependency's minor version (unless you unignore this specific
dependency's minor version or upgrade to it yourself)
- `@dependabot ignore <dependency name>` will close this group update PR
and stop Dependabot creating any more for the specific dependency
(unless you unignore this specific dependency or upgrade to it yourself)
- `@dependabot unignore <dependency name>` will remove all of the ignore
conditions of the specified dependency
- `@dependabot unignore <dependency name> <ignore condition>` will
remove the ignore condition of the specified dependency and ignore
conditions


</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…es after native unload and preserve Loaded root-replacement coverage after test-host initialization
@BagavathiPerumal

Copy link
Copy Markdown
Contributor Author

Tests Failure Analysis

@BagavathiPerumal — test-failure analysis for commit 301a2b4.

Scope CI failures Commit 301a2b4

🧪 CI Analysis — click to expand

📊 maui-pr

No failures found.

🧪 maui-pr-devicetests

🧪 maui-pr-uitests

🧭 Follow-up — actions and refresh

The disposed- IApp setup failures in Shell_android_ui_tests_controls_30 also occur on inflight/candidate (links), and the five MauiWindowInsetListener tests, which cover inset gating that this PR doesn't touch, fail the same way there. The ImageWithUndefinedSizeAndWithBackgroundSetRenders / Swipe tests pass locally with the fix, so the test failures are not caused by this change.

@BagavathiPerumal

Copy link
Copy Markdown
Contributor Author

AI Review Summary

@BagavathiPerumal — new AI review results are available based on commit 301a2b4.

Gate Inconclusive Confidence Low Platform Android

🗂️ Review Sessions — click to expand

🚦 Gate — Test Before & After Fix

Gate Result: ⚠️ INCONCLUSIVE

Platform: ANDROID · Base: inflight/candidate · Merge base: 29eb037a

🩺 Could not verify — environment/infrastructure error. The gate ran the tests but hit an environment error (an emulator/simulator/Appium/XHarness flake, a device that would not boot, or an empty/invalid result file), so it could not record a real pass/fail. The ⚠️ ENV ERROR marks below are infrastructure, not test failures — this is not a problem with your PR. Comment /review to retry on a fresh agent.

XHarness did not produce the expected fresh result 'testResults-175c704fd9724d309e1e0354d897a531.xml' for requested class(es) 'Microsoft.Maui.DeviceTests.WindowTests' (the target tests did not run).

Test Without Fix (expect FAIL) With Fix (expect PASS)
📱 WindowTests (ReplacingShellRootFromPageLoadedDoesNotCrash, ReplacingFlyoutRootFromDetailLoadedDoesNotCrash) Category=Window ⚠️ ENV ERROR ✅ PASS — 421s
🔴 Without fix — 📱 WindowTests (ReplacingShellRootFromPageLoadedDoesNotCrash, ReplacingFlyoutRootFromDetailLoadedDoesNotCrash): ⚠️ ENV ERROR · 480s
No log file found

🟢 With fix — 📱 WindowTests (ReplacingShellRootFromPageLoadedDoesNotCrash, ReplacingFlyoutRootFromDetailLoadedDoesNotCrash): PASS ✅ · 421s
(no coded error found; showing last 1200 chars)

            "totalMemoryBytes": 8322998272
          },
          "target": {
            "kind": "emulator",
            "name": "sdk_gphone_x86_64",
            "identifier": "emulator-5554",
            "operatingSystem": "Android",
            "operatingSystemVersion": "11",
            "apiLevel": 30,
            "architecture": "x86_64",
            "supportedArchitectures": [
              "x86_64",
              "x86",
              "arm64-v8a",
              "armeabi-v7a",
              "armeabi"
            ],
            "manufacturer": "Google",
            "model": "sdk_gphone_x86_64",
            "productName": "sdk_gphone_x86_64",
            "buildFingerprint": "google/sdk_gphone_x86_64/generic_x86_64_arm64:11/RSR1.201211.001/7027799:user/release-keys",
            "cpuModel": "0",
            "cpuMaxFrequencyHertz": 2000,
            "totalMemoryBytes": 2077544448
          }
        }
      }
      <<XHARNESS_RESULT_END>>
info: Attempting to remove apk 'com.microsoft.maui.controls.devicetests'..
info: Successfully uninstalled com.microsoft.maui.controls.devicetests
XHarness exit code: 0
  Passed: 2
  Failed: 0
  Skipped: 0
  Total: 2
  Tests completed successfully

⚠️ Failure Details

  • ⚠️ WindowTests (ReplacingShellRootFromPageLoadedDoesNotCrash, ReplacingFlyoutRootFromDetailLoadedDoesNotCrash) without fix: XHarness did not produce the expected fresh result 'testResults-175c704fd9724d309e1e0354d897a531.xml' for requested class(es) 'Microsoft.Maui.DeviceTests.WindowTests' (the target tests did not run).

📁 Fix files reverted (2 files)

  • src/Controls/src/Core/Window/Window.Android.cs
  • src/Controls/src/Core/Window/Window.cs

📋 Pre-Flight — Context & Validation

Pre-Flight Context

Scope: Evidence-only context for draft PR #39279. This is not an exhaustive review, recommendation, or comparison of solutions.

PR and reported problem

Submitted mechanism

File Change
src/Controls/src/Core/Window/Window.cs For a loaded outgoing page, calls a new partial HandleLoadedPageDisconnect hook before using the existing Window.OnUnloaded fallback. Unloaded outgoing pages still disconnect immediately.
src/Controls/src/Core/Window/Window.Android.cs Implements Android-specific cleanup selection.
src/Controls/tests/DeviceTests/Elements/Window/WindowTests.cs Adjusts the existing Shell and FlyoutPage root-replacement tests to install their real roots only after the host callback starts.
The Android partial follows three paths:

  1. If the Window handler itself is an IPlatformViewHandler with a platform view, it leaves disconnectHandled false, preserving the common Window.OnUnloaded fallback.

  2. Otherwise, if the outgoing page has an IPlatformViewHandler with a platform view, it captures the current handler and registers cleanup on that page’s native unload event. At callback time it disconnects only when:

    • the page still has the captured outgoing handler;
    • the page has no visual parent; and
    • page.IsLoaded is false.
  3. If the outgoing page lacks a usable platform view, it disconnects immediately.

For paths 2 and 3, it marks cleanup as handled so the common window-based unload callback is not registered.

Relevant source contracts confirm:

  • Android WindowHandler is an ElementHandler<IWindow, Activity>.
  • Android IPlatformViewHandler represents handlers backed by Android.Views.View, so the standard window handler does not provide the view lifecycle expected by IElement.OnUnloaded.
  • IElement.OnUnloaded requires a non-null IPlatformViewHandler.PlatformView; otherwise it throws "Handler is not set on element".
  • DisconnectHandlers builds a stable visual-tree list and disconnects each handler, while stopping traversal at elements using manual disconnect policy.

The two modified tests now:

  • construct the Window with a placeholder ContentPage;
  • enter CreateHandlerAndAddToWindow;
  • subscribe to the Shell child or Flyout detail page’s Loaded event;
  • assign the Shell/Flyout root;
  • replace Window.Page from that child’s synchronous Loaded callback; and
  • wait for the replacement page and assert it is attached to the navigation root.

Platform-sensitive paths

  • Android: The functional specialization is Android-only and depends on Android native view attach/detach lifecycle, synchronous Loaded timing, and Shell/Flyout AndroidX fragment transactions.
  • Shared Controls: Window.cs changes for every target, but targets without an implementation of the partial method retain the existing window-unload fallback.
  • Shell/Flyout: The modified device scenarios exercise reentrant root replacement from child Loaded, with fragment-backed navigation roots.
  • Handler lifetime: Correctness depends on distinguishing an Activity-backed window handler from a View-backed page handler and on avoiding disconnection after a page has been reparented, reloaded, or assigned a different handler.
  • Prior regression surface: [inflight regression] Fix Shell UI tests are failing in Candidate PR #36673 also modified Window.cs, but for Shell/native-window title semantics. Its ShellToolbarTests cross-reference is therefore mandatory despite not directly exercising the new Android unload path.

Required later validation

Testing is required on Android. No commands or tests were executed during this context-gathering step.

Primary validation should exercise at least:

  • ReplacingShellRootFromPageLoadedDoesNotCrash
  • ReplacingFlyoutRootFromDetailLoadedDoesNotCrash
  • completion without a host stall, process crash, missing fragment-container error, or "Handler is not set on element" exception;
  • successful attachment of the replacement page;
  • deferred disconnection only after the outgoing page’s native view unloads;
  • preservation of a page that is reparented, reloaded, or assigned a new handler before deferred cleanup;
  • immediate cleanup when the outgoing page has no usable native view.

After the primary validation succeeds, the mandated regression test is:

dotnet test src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj --filter "ShellToolbarTests"

A failure of that regression test makes a later candidate fail. The supplied Gate result is inconclusive because tests could not be built or run due to a build/environment error; it is not evidence that the fix failed, must not independently cause a change request, and must not be rerun here.

Available and unavailable evidence

  • The PR description marks Android as validated and supplies before/after video attachments, but those attachments were not independently assessed here.
  • PR comments show that maui-pr-uitests, maui-pr-devicetests, and a review build were started. No completed pipeline or test result was available in the read-only PR discussion examined.
  • No reviews had been submitted at the time of retrieval.
  • The exact Gate build/environment failure is unknown.
  • The issue’s referenced Azure build details, textual failure output, exception stack, affected Android API level, and deterministic reproduction sequence are unknown.
  • It remains uncertain whether “crash,” “hang,” and the reported handler exception are manifestations of one sequence or separate failures.
  • The tests now perform replacement after the host callback begins, while the PR says the observed stall occurred during initial fragment creation. They preserve replacement from child Loaded, but how closely the revised setup represents the original failing timing remains for dedicated validation.
  • The submitted test changes assert replacement attachment, but do not directly assert outgoing-handler disconnection timing or each reuse guard.
  • Buildability and behavior on non-Android targets remain unverified.

🔬 Code Review — Deep Analysis

Code Review — PR #39279

Independent Assessment

What this changes: Loaded outgoing pages now pass through a platform hook before the shared Window.OnUnloaded cleanup path. On Android, an outgoing page with a usable native view defers handler disconnection until that view unloads; the callback disconnects only if the page still has the captured handler, remains detached, and is no longer loaded. Pages without a usable native view disconnect immediately. The Shell and FlyoutPage device tests now install their real root after the host callback begins while retaining replacement from a child Loaded callback.

Inferred motivation: Android's standard WindowHandler is backed by an Activity, not an Android View, so it cannot provide the native view lifecycle required by the generic unload helper. Page-level native unload provides the appropriate deferred cleanup point without disconnecting a page that was reused before the callback.

Reconciliation with PR Narrative

Author claims: Synchronous Android Loaded dispatch can reenter root replacement during host fragment initialization, and window-based unload cleanup can fail when the window handler has no usable platform view.

Agreement/disagreement: The submitted implementation and test changes match those claims. The tests preserve replacement from a Shell/Flyout child Loaded callback while moving initial root installation past host setup. The diff does not directly assert deferred-disconnection timing or each page-reuse guard, so those behaviors remain reasoned from source rather than independently validated.

Prior Review Reconciliation

No prior error-level findings were found on the top-level review, inline-review, or PR issue-comment surfaces examined by the expert reviewer.

Blast Radius Assessment

  • Runs for all instances: No. The shared hook is reached only when replacing a loaded Window.Page; the specialized behavior is Android-only.
  • Startup impact: Limited to root replacement that occurs during page/window setup; there is no unconditional startup path.
  • Static/shared state: None introduced.

CI Status

  • Required-check result: Undetermined; authenticated required-check retrieval was unavailable.
  • Gate: ⚠️ INCONCLUSIVE because the supplied Gate could not build or run the tests.
  • Classification: Missing validation evidence, not a demonstrated test failure.
  • Action taken: Gate was not rerun. Confidence is capped at low.

Findings

No concrete actionable defects were validated on modified right-side lines. inline-findings.json contains an empty JSON array.

Failure-Mode Probing

  • Activity-backed window handler: The normal Android window handler does not satisfy the view-backed unload contract, so the Android hook proceeds to page-level cleanup rather than registering generic unload against the Activity.
  • Page with a usable native view: Cleanup waits for the page's native unload and verifies the captured handler, detached parent state, and unloaded state before disconnecting.
  • Reparented, reloaded, or rehandled page: Any failed guard makes the deferred callback a no-op, avoiding disconnection of a reused page.
  • Page without a usable native view: The implementation disconnects immediately because no native unload can be observed.
  • Duplicate cleanup/subscription lifetime: The Android path marks cleanup handled, so the shared window fallback is not also registered. No persistent or static subscription state is added.
  • Reentrant Shell/Flyout replacement: Both modified tests retain Window.Page replacement inside the child page's synchronous Loaded callback after the host callback has begun.

External Output Contract

Not applicable.

Test Fidelity

The modified Android device tests retain the core reentrant root-replacement action and assert that the replacement page attaches. They do not directly cover deferred disconnect timing, the immediate-disconnect fallback, or each reuse guard. Gate and required regression validation remain unavailable.

Verdict: NEEDS_DISCUSSION

Confidence: low

Summary: Source review found no blocking defect or evidence-backed mechanism requiring a reviewer refinement. Approval is not supported because the submitted candidate remains unvalidated: Gate was inconclusive and required-check status could not be established.

🛠️ 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 description is detailed and accurate, but the title contains workflow noise ([WIP][Inflight/Candidate]) instead of the repository's [Platform] Component: What changed form.

Recommended title

[Android] Window: Defer outgoing page disconnection during Loaded root replacement

Recommended description

### Root cause

The issue occurs because https://github.com/dotnet/maui/pull/38784 restored synchronous Android `Loaded` dispatch. In the two tests added by https://github.com/dotnet/maui/pull/38214, the Shell or FlyoutPage child can raise `Loaded` while the Android device-test host is still creating its initial `WindowTestFragment`. The `Loaded` handler then replaces `Window.Page` during fragment initialization.

In the captured run, the root replacement completed, but the test delegate was never reached because the host was still waiting for its fragment setup to complete. This resulted in the test appearing to hang.

Separately, when a loaded outgoing page is disconnected through the Android `Window`, its handler may not have a usable platform view. Disconnecting it at that point can result in a "Handler is not set on element" failure.

### Solution description

The fix uses the outgoing page's native unload event to defer handler disconnection on Android, where the standard `WindowHandler` wraps an `Activity` rather than a platform `View`. If the outgoing page has no usable native view, its handlers are disconnected directly. Before performing deferred cleanup, the fix checks that the page has not been reparented or reloaded and still has its outgoing handler, ensuring that a reused page is not disconnected. Synchronous Android `Loaded` behavior remains unchanged.

The implementation:

- adds a platform hook in `Window.cs` while preserving the existing shared window-unload fallback;
- implements Android page-level deferred or immediate cleanup in `Window.Android.cs`; and
- updates the Shell and FlyoutPage scenarios in `WindowTests.cs`.

The Shell and FlyoutPage tests now start with a placeholder page and install the root page after the test host is ready. They still replace the root page from the child's `Loaded` callback and verify that the replacement is attached successfully.

### Regression PR

https://github.com/dotnet/maui/pull/38784

### Platforms validated

- [x] Android
- [ ] Mac
- [ ] Windows
- [ ] iOS

### Issues Fixed

Fixes https://github.com/dotnet/maui/issues/39278

### Output

| Platform | Before | After |
|---|---|---|
| Android | <video src="https://github.com/user-attachments/assets/12fb957d-c709-412b-824a-8bbea5efc152"> | <video src="https://github.com/user-attachments/assets/ff404e4a-2aa9-4e01-a385-6a05415383df"> |

🏁 Report — Final Recommendation

⚠️ Final Recommendation: REQUEST CHANGES

Phase Status

Phase Status Notes
Pre-Flight ✅ COMPLETE Trusted evidence-first context consumed
Code Review NEEDS_DISCUSSION (low) 0 errors, 0 warnings; validation evidence is incomplete
Gate ⚠️ INCONCLUSIVE Android tests could not be built or run; this is not a demonstrated fix failure
Try-Fix not requested Evidence-first mode intentionally omitted alternative generation
Refinement Not generated No concrete actionable defect or unresolved mechanism met the refinement threshold
Report ✅ COMPLETE Raw PR assessed as the sole real candidate

Code Review and Candidate Comparison

Candidate Expert Findings Addressed Validation Rank
pr No concrete defect was found on modified lines Unverified: Gate was inconclusive, required-check status was unavailable, and the mandatory regression test was not reached 1
The raw submitted PR is the only implemented candidate. The expert review found no source-backed defect that would justify a pr-plus-reviewer refinement, and routine Try-Fix alternatives were intentionally not requested. Selecting pr therefore records the best available implementation; it does not establish merge readiness.

Summary

The Android lifecycle approach is coherent: it avoids using an Activity-backed window handler as a view unload source, defers cleanup to the outgoing page's native unload when possible, and guards against disconnecting a page that was reparented, reloaded, or assigned a new handler. The revised Shell and FlyoutPage tests retain root replacement from a child Loaded callback after moving initial root installation beyond host setup.

The recommendation remains REQUEST CHANGES because approval requires validated evidence and an expert verdict without blocking discussion. Gate was inconclusive rather than failing, so this report does not conclude that the fix is incorrect; it records that Android primary validation and the required ShellToolbarTests regression check remain unproven.

Root Cause

Synchronous Android Loaded dispatch can reenter Window.Page replacement while the host is still initializing fragment-backed Shell or FlyoutPage content. Cleanup through the shared window unload path is also unsuitable for the normal Android WindowHandler, whose platform object is an Activity rather than the Android View required by the element unload helper.

Fix Quality

The submitted fix is localized, introduces no shared/static state, preserves the existing shared fallback for view-backed window handlers, and has explicit page-reuse guards around deferred disconnection. Its device-test changes exercise the reported reentrant replacement and final attachment, but do not directly assert deferred cleanup timing, immediate fallback behavior, or each reuse guard. With no successful isolated validation, the candidate must remain unapproved despite the absence of a validated code defect.

🔗 Regression Cross-Reference

🔍 Regression Cross-Reference

⚠ Overlaps with prior bug-fix PRs — same files modified, but no exact line revert detected.

File Fix PR Fixed issue(s)
src/Controls/src/Core/Window/Window.cs #36673 #36562

🧪 Regression Tests to Verify

These tests were added by the overlapping fix PRs. Running them to verify no side-effect regressions:

Fix PR Type Test Filter
#36673 UnitTest ShellToolbarTests ShellToolbarTests

🧪 Regression Test Results

✅ PASSED — 1 passed, 0 failed, 0 skipped

Fix PR Test Type Result
#36673 ShellToolbarTests UnitTest ✅ PASSED
📱 UI Tests — Window

Detected UI test categories: Window

⚠️ Deep UI tests — 0 passed, 0 failed across 1 category on platform-pool agent (replaces in-process counts above). 1 category reported 0 tests.

🧪 UI Test Execution Results (deep, platform pool)

Category Tests Snapshot diffs
Window 0 tests —
📎 Download drop-deep-uitests artifact (TRX + snapshot diffs)
🧭 Next Steps — review latest findings

The without-fix ENV ERROR is the expected symptom, since the device test hangs without the fix, so XHarness produces no result file, and with the fix both tests pass; no alternative was needed because Try-Fix wasn't requested and this is a localized Android-only fix with 0 review findings.

@sheiksyedm
sheiksyedm marked this pull request as ready for review October 14, 2026 06:01
@sheiksyedm
sheiksyedm requested a balanced review from Copilot October 14, 2026 06:01

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.

🟡 Changes recommended

The deferred cleanup and page-reuse safeguards lack direct regression coverage.

1 open finding
What changed in this PR

Fixes Android root-page replacement by deferring outgoing handler cleanup until native unload.

Changes:

  • Adds Android-specific safe disconnection.
  • Updates Shell and FlyoutPage regression tests.
File Description
Window.cs Adds platform-specific cleanup hook.
Window.Android.cs Defers and guards handler disconnection.
WindowTests.cs Stabilizes Loaded root-replacement tests.

🧠 Review effort: Balanced

Comment on lines +33 to +38
page.OnUnloaded(() =>
{
if (ReferenceEquals(page.Handler, outgoingHandler) &&
((IVisualTreeElement)page).GetVisualParent() is null &&
!page.IsLoaded)
page.DisconnectHandlers();

@github-actions github-actions Bot 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.

Expert Review

@BagavathiPerumal — expert review for commit 0e3b62f.

Scope source review Commit 0e3b62f

Status: Incomplete. 0 new inline findings; 0 review-body findings.


🔎 Expert Analysis — click to expand

AI-generated review using independent GPT dimension passes.

Coverage: 3 of 3 routed dimensions completed.

Finding validation: Completed.

Incomplete evidence

  • Historical regression cross-reference failed; do not infer CLEAN from missing evidence.

Source/history review only. No builds or tests were executed; this is not merge approval.

Expert execution: Inference and threat detection ran in kubaflo/maui; this separate trusted job performs native publication of the verified results.


🧭 Follow-up — actions and refresh

Next action: Account for the listed evidence gaps before treating this review as complete.

Maintainers: comment /review expert-review to refresh this report.

@kubaflo
kubaflo merged commit f3ce396 into dotnet:inflight/candidate Oct 14, 2026
36 checks passed
@github-actions github-actions Bot added this to the .NET 10 SR12 milestone Oct 14, 2026
kubaflo pushed a commit that referenced this pull request Oct 14, 2026
…ng Loaded root replacement (#39279)

<!-- 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!


<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Root cause

The issue occurs because (#38784)
restored synchronous Android Loaded dispatch. In the two tests added by
(#38214), the Shell or FlyoutPage
child can raise Loaded while the Android device-test host is still
creating its initial WindowTestFragment. The Loaded handler then
replaces Window.Page during fragment initialization.
 
In the captured run, the root replacement completed, but the test
delegate was never reached because the host was still waiting for its
fragment setup to complete. This resulted in the test appearing to hang.
 
Separately, when a loaded outgoing page is disconnected through the
Android Window, its handler may not have a usable platform view.
Disconnecting it at that point can result in a Handler is not set on
element failure.

### Solution description

The fix involves using the outgoing page’s native unload event to defer
handler disconnection on Android, where the standard Window handler
wraps an Activity rather than a platform View. If the outgoing page has
no usable native view, its handlers are disconnected directly. Before
performing deferred cleanup, the fix checks that the page has not been
reparented or reloaded and still has its outgoing handler, ensuring that
a reused page is not disconnected. Synchronous Android Loaded behavior
remains unchanged.

The Shell and FlyoutPage tests now start with a placeholder page and
install the root page after the test host is ready. They still replace
the root page from the child’s Loaded callback and verify that the
replacement is attached successfully.

### Regression PR

PR #38784

Validated the behavior in the following platforms
 
- [x] Android
- [ ] Mac
- [ ] Window
- [ ] iOS
 
### Issues Fixed
  
Fixes #39278

### Output

|Platform|Before|After|
|--|--|--|
|Android| <video
src="https://github.com/user-attachments/assets/12fb957d-c709-412b-824a-8bbea5efc152">|
<video
src="https://github.com/user-attachments/assets/ff404e4a-2aa9-4e01-a385-6a05415383df">|

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
kubaflo pushed a commit that referenced this pull request Oct 18, 2026
…ng Loaded root replacement (#39279)

<!-- 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!


<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Root cause

The issue occurs because (#38784)
restored synchronous Android Loaded dispatch. In the two tests added by
(#38214), the Shell or FlyoutPage
child can raise Loaded while the Android device-test host is still
creating its initial WindowTestFragment. The Loaded handler then
replaces Window.Page during fragment initialization.
 
In the captured run, the root replacement completed, but the test
delegate was never reached because the host was still waiting for its
fragment setup to complete. This resulted in the test appearing to hang.
 
Separately, when a loaded outgoing page is disconnected through the
Android Window, its handler may not have a usable platform view.
Disconnecting it at that point can result in a Handler is not set on
element failure.

### Solution description

The fix involves using the outgoing page’s native unload event to defer
handler disconnection on Android, where the standard Window handler
wraps an Activity rather than a platform View. If the outgoing page has
no usable native view, its handlers are disconnected directly. Before
performing deferred cleanup, the fix checks that the page has not been
reparented or reloaded and still has its outgoing handler, ensuring that
a reused page is not disconnected. Synchronous Android Loaded behavior
remains unchanged.

The Shell and FlyoutPage tests now start with a placeholder page and
install the root page after the test host is ready. They still replace
the root page from the child’s Loaded callback and verify that the
replacement is attached successfully.

### Regression PR

PR #38784

Validated the behavior in the following platforms
 
- [x] Android
- [ ] Mac
- [ ] Window
- [ ] iOS
 
### Issues Fixed
  
Fixes #39278

### Output

|Platform|Before|After|
|--|--|--|
|Android| <video
src="https://github.com/user-attachments/assets/12fb957d-c709-412b-824a-8bbea5efc152">|
<video
src="https://github.com/user-attachments/assets/ff404e4a-2aa9-4e01-a385-6a05415383df">|

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 14, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration 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.

[inflight regression] Android Device test crash on September 22nd Candidate

5 participants