Skip to content

[net11.0][Windows] Preserve wrapper identity when handlers reconnect - #39577

Closed
kubaflo wants to merge 3 commits into
net11.0from
kubaflo-windows-wrapper-reconnect
Closed

kubaflo wants to merge 3 commits into
net11.0from
kubaflo-windows-wrapper-reconnect

Conversation

@kubaflo

@kubaflo kubaflo commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Description of Change

Fix the three pre-existing Windows Label wrapper-reconnect failures on net11.0, independently of #39536's GC fixture change. Base: 7b0ea7800db3f3faccbaecb665d32b7c61eaf932. Validated head: 17b66a97f4aef6dfc513086c6e3b2aef6876a136.

Root cause: generic ViewHandler.OnDisconnecting tears down every container before the old platform view is nulled. On Windows this disposes/removes the existing wrapper and reparents the old native child into the external parent. The newly created native child has no connection to that visual-tree slot. This contradicts the existing Windows ReconnectContainer contract and the three correct identity/parent-preservation tests added by #37392.

Fix: preserve a Windows WrapperView as the visual-tree placeholder, while detaching its old native child. Existing mapper replay connects the new unparented child to that same wrapper, without re-entering virtual SetupContainer or rebuilding an external layout. Non-Windows and external/non-wrapper container teardown remains unchanged.

Also correct WrapperView.Child = null: it previously removed the child/callbacks but retained the old _child reference. Clear that backing reference, remove the old child's composition clip before replacement, and make clip disposal tolerate an empty wrapper. Normal container removal remains supported.

The existing three reconnect tests retain their identity, parent, hit-testing, sizing/alignment and connection assertions, with additional old-child detachment checks. Two new native cases verify that the old native child collects while the handler and attached wrapper stay alive, and that reconnecting without a container restores the new native view to the wrapper's original slot.

Scope: three files, 98 insertions / 12 deletions. No public API, dependency, pipeline, MSIX shutdown flag, Android HybridWebView, GC helper/fixture, retry, sleep, skip or tolerance changes. Open and recently merged PRs, including main/inflight/net11 lifecycle history, were checked for an equivalent fix; none was found.

Hosted native causal proof — Windows unpackaged, actual Label category XML

Arm / XML Build Original three cases Label passed / failed / skipped
Exact-base baseline XML 1643729 All three Assert.Same failures 39 / 3 / 2
Fixed XML 1645793, 62be5373 All pass 44 / 0 / 2
Product-only reverted XML 1645893, d836a95a Same three Assert.Same failures return 39 / 5 / 2
Restored XML 1645933, 17b66a97 All pass 44 / 0 / 2

The baseline failures also occur in original device build 1644557. The relevant lifecycle/test sources are unchanged between that exact base and this PR's pinned base. Each new arm is one full Windows execution, not a stress/flake-elimination claim.

The negative control changes only the two product files back to the pinned base; the test source is unchanged. Both new lifecycle cases also fail for their intended cleanup assertions: the old child remains parented to a Grid, and the removed wrapper still exposes its old TextBlock. The restored commit's entire tree is identical to the first green candidate. Normal revert/restore commits retain this provenance; no rebase, amendment or force-push was used.

Final hosted build 1645933 additionally produced real packaged Controls XML: Label has 44 passed / 0 failed / 2 existing skips, including all three original and both new cases. Full packaged Controls and full unpackaged Controls each have 976 passed / 0 failed / 33 skipped execution records. Full unpackaged Core has 2,033 passed / 0 failed / 111 skipped. XML declarations, physical records and assembly errors were reconciled; these results are not inferred from launcher exit zero.

Commands and results

DOTNET denotes the private copy of pinned SDK 11.0.100-rtm.26514.118 (product 11.0.100); no global SDK/workload configuration was changed.

"$DOTNET" test src/Core/tests/UnitTests/Core.UnitTests.csproj -c Release --no-restore \
  -p:IncludeAndroidTargetFrameworks=false -p:IncludeIosTargetFrameworks=false \
  -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeMacOSTargetFrameworks=false \
  -p:IncludeWindowsTargetFrameworks=false -p:IncludeTizenTargetFrameworks=false \
  -p:TreatWarningsAsErrors=false \
  --filter 'FullyQualifiedName~ExternalBackendContainerViewTests|FullyQualifiedName~AbstractViewHandlerTests' \
  --nologo -v:q
# Passed: 24 passed / 0 failed / 0 skipped.

"$DOTNET" format Microsoft.Maui.sln --no-restore --verify-no-changes \
  --exclude Templates/src --exclude-diagnostics CA1822 \
  --include src/Core/src/Handlers/View/ViewHandler.cs \
    src/Core/src/Platform/Windows/WrapperView.cs \
    src/Controls/tests/DeviceTests/Elements/Label/LabelTests.Windows.cs \
  --verbosity quiet
# Passed; formatting was also applied before the initial candidate commit.

git diff --check
# Passed.

az devops invoke --org https://dev.azure.com/dnceng-public \
  --area pipelines --resource runs --route-parameters project=public pipelineId=314 \
  --api-version 7.1 --http-method POST --in-file "$E/windows-restored-request.json" \
  --out-file "$E/windows-restored-run.json" --only-show-errors -o none
# Accepted run 1645933 at exact head 17b66a97; native results above.

E is the session evidence directory. Each actual queue request contains only resources.repositories.self (branch and exact commit) and stagesToSkip for the seven non-Windows stages. Default-pipeline previews verified net11 targeting; actual timelines confirmed those seven stages completed/skipped. Only the Windows build/run stages executed. No pipeline source or template-parameter override was introduced.

Limits: the full restored pipeline is not green. Four other packaged apps (Core, Essentials, Graphics and BlazorWebView) fail before test execution with Add-AppxPackage 0x80073D02 / WebExperience resources in use and no XML. Their coverage is not claimed; the separate MSIX deployment port is not included. The first candidate also had packaged pre-test deployment failures, so its green coverage is unpackaged only. No local Windows/Mac desktop automation, XCTest or screen takeover was used. Other platforms were not exercised for this Windows-specific correction. pr-finalize found no blocking code findings and checked the title/description against the final diff and evidence.

Issues Fixed

Resolves the three pre-existing Windows Label reconnect failures discovered while investigating #39536. Restores the Windows wrapper-reconnect contract from #37392; this is not a change to either PR's GC or input-transparency scope. No separate issue was filed.

Retain Windows-owned wrappers for the existing reconnect mapper, detach their old native children, and clear the child backing reference and clip. Keep generic and external-container teardown unchanged. Strengthen reconnect coverage and add native-release and container-removal controls.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 3fbc658d-03e3-43ae-af5c-f3584e3b45d7
Keep the regression tests unchanged and revert only the two product files to the pinned net11 baseline. This temporary control must fail the original three Windows reconnect cases before the product fix is restored.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 3fbc658d-03e3-43ae-af5c-f3584e3b45d7
The hosted product-only negative control reproduced all three original wrapper identity assertions and both new lifecycle failures. Restore the exact green product/tree for the final hosted native control.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 3fbc658d-03e3-43ae-af5c-f3584e3b45d7
Copilot AI balanced review requested due to automatic review settings October 22, 2026 21:45
@kubaflo
kubaflo temporarily deployed to copilot-pat-pool October 22, 2026 21:45 — with GitHub Actions Inactive
@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 -- 39577

Or

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

@azure-pipelines

This comment has been minimized.

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

A retained wrapper can remain collapsed when a Label changes from hidden to visible while its handler is disconnected.

1 open issue
What changed in this PR

Restores Windows wrapper identity and visual-tree position when handlers reconnect, addressing the Label lifecycle failures discovered during #39536 and preserving the contract introduced by #37392.

Changes:

  • Retains Windows wrappers during disconnect while detaching their old native children.
  • Clears stale child references and composition clips safely.
  • Strengthens reconnect assertions and adds native-child collection and wrapper-removal tests.
File Description
src/​Core/​src/​Platform/​Windows/​WrapperView.cs Clears child references and safely removes composition clips.
src/​Core/​src/​Handlers/​View/​ViewHandler.cs Preserves Windows wrappers across handler disconnects.
src/​Controls/​tests/​DeviceTests/​Elements/​Label/​LabelTests.Windows.cs Extends reconnect, detachment, and collection coverage.

Review effort: Balanced

Comment on lines +280 to +283
if (HasContainer && ContainerView is Platform.WrapperView wrapper)
{
HasContainer = false;
// Keep the wrapper's visual-tree slot for ReconnectContainer, not the disconnected native view.
wrapper.Child = null;

@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 — 1 finding

Reviewed commit 17b66a9.

See inline comments for details.

{
HasContainer = false;
// Keep the wrapper's visual-tree slot for ReconnectContainer, not the disconnected native view.
wrapper.Child = null;

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.

[major] Handler Mapper and Property Patterns - Restore opacity on the retained wrapper when reconnecting. On Windows, attach a visible Button with a non-null Clip and Opacity = 0, disconnect its handler, set Opacity = 1 while disconnected, then reconnect the same handler with SetVirtualView. The clip keeps HasContainer true, so MapContainerView replaces the child without requesting an opacity refresh. SetVirtualView enters Connecting for the new native view, causing the inherited MapOpacity to skip the default value 1; MapVisibility also skips Visible. The retained wrapper therefore stays at opacity 0 and the Button remains invisible. Replay opacity through the mapper for retained wrappers and add this disconnected zero-to-one transition using a non-Label control: the current Label tests cannot catch it because LabelHandler overrides MapOpacity without the default-value skip.

@github-actions

Copy link
Copy Markdown
Contributor

/review gate was not started: another review or Gate is already running for this PR.

This command is not queued. Submit it again after the current run finishes.

@kubaflo

This comment has been minimized.

@azure-pipelines

This comment has been minimized.

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

This comment has been minimized.

@MauiBot MauiBot removed the s/agent-review-in-progress AI review is currently running for this PR label Oct 23, 2026
@kubaflo

kubaflo commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

/review expert-review

@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 23, 2026
@MauiBot

MauiBot commented Oct 23, 2026

Copy link
Copy Markdown
Collaborator

PR Test Gate

@kubaflo — existing-test verification for commit 17b66a97.

Result SKIPPED Platform Android Commit 17b66a97


🧪 Gate analysis — click to expand

⚠ Skipped. No runnable PR tests were selected. The fix has not been verified by this gate.

No interpretable test-group summary was produced. No additional test execution is inferred.

PR head: 17b66a97.

Without-fix baseline: 4ef2769e.

This branch was previously deployed

1 inactive deployment
copilot-pat-pool — 17b66a97 Deployed Oct 22, 2026 by kubaflo via conclusion #2476
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants