Skip to content

Revert "Fix BlazorWebView root component subscriptions on disconnect" - #39251

Merged
kubaflo merged 1 commit into
mainfrom
revert-39247-sheiksyedm-blazorwebview-activity-leak
Oct 8, 2026
Merged

kubaflo merged 1 commit into
mainfrom
revert-39247-sheiksyedm-blazorwebview-activity-leak

Conversation

@kubaflo

@kubaflo kubaflo commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

This should be merged to inflight/current

Copilot AI balanced review requested due to automatic review settings October 8, 2026 11:12
@kubaflo
kubaflo temporarily deployed to copilot-pat-pool October 8, 2026 11:12 — with GitHub Actions Inactive
@github-actions

github-actions Bot commented Oct 8, 2026

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

Or

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

@kubaflo

kubaflo commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

@dalexsoto stamp

@kubaflo
kubaflo temporarily deployed to copilot-pat-pool October 8, 2026 11:12 — with GitHub Actions Inactive
@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.

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

Reconnecting the same handler clears the application's configured root components.

1 open finding
What changed in this PR

Reverts BlazorWebView root-component subscription cleanup in .NET MAUI, intended for inflight/current.

Changes:

  • Removes shared cleanup logic and calls from platform disconnect handlers.
  • Deletes the lifecycle regression test.
File Description
src/​BlazorWebView/​tests/​DeviceTests/​Elements/​BlazorWebViewTests.Lifecycle.cs Deletes disconnect/reconnect coverage.
src/​BlazorWebView/​src/​Maui/​Windows/​BlazorWebViewHandler.Windows.cs Removes Windows cleanup call.
src/​BlazorWebView/​src/​Maui/​Tizen/​BlazorWebViewHandler.Tizen.cs Removes Tizen cleanup call.
src/​BlazorWebView/​src/​Maui/​iOS/​BlazorWebViewHandler.iOS.cs Removes iOS/MacCatalyst cleanup call.
src/​BlazorWebView/​src/​Maui/​BlazorWebViewHandler.cs Removes shared unsubscribe/reset helper.
src/​BlazorWebView/​src/​Maui/​Android/​BlazorWebViewHandler.Android.cs Removes Android cleanup call.

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

}
}

private RootComponentsCollection? RootComponents

@PureWeen PureWeen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Adversarial review

Reviewed exact head cc0adad31b00205b42f12b0386e875c3923673bf. Each independent reviewer assessed the changed lifecycle code and deleted test; three independent reviewers with adversarial consensus agreed on the two regressions below (3/3 each).

Conclusion: this exact rollback restores handler retention and destructive same-handler reconnection.

  1. Resource leak — disconnect leaves the old handler subscribed. Removing DisconnectRootComponents() from Android teardown, and the equivalent iOS/MacCatalyst, Windows, and Tizen paths, leaves the live view's RootComponents.CollectionChanged delegate targeting the disconnected handler. For the cached Window/page scenario in #39227, that collection remains rooted while handlers are replaced during Android Activity recreation. The retention chain is RootComponents -> delegate -> old handler -> MauiContext -> cached Android Context. Generic handler disconnect clears VirtualView/PlatformView, not MauiContext; creating the Android WebView evaluates the context's Lazy<Context> cache. This reintroduces the retention path addressed by #39247, not merely a collectible handler/view cycle. Preserve non-mutating unsubscription and reset the private collection field before platform teardown.

  2. Confirmed existing finding — reconnect clears application root components. After disconnect, _rootComponents still references the view's collection. Calling SetVirtualView on that handler and view reruns MapRootComponents; the existing setter calls _rootComponents.Clear() before assigning that same collection. The configured components are removed. This independently confirms the existing unresolved review thread; no duplicate inline comment was added. Resetting the field without clearing the app-owned collection prevents this path.

Checks and coverage: Verified the authoritative six-file diff, exact checkout, all-platform teardown changes, Core handler reconnect/mapping behavior, Android context retention, and prior feedback. The resulting tree exactly matches the tree before #39247. The deleted lifecycle test specifically checks unsubscription, component preservation, and one subscription after same-handler reconnect; retain that coverage with the teardown contract. The title accurately describes the revert, but the body supplies only a deployment destination, not the reason for accepting these restored behaviors.

Limits: This was source-level review. No build, device tests, Activity/GC experiment, or runtime reproduction was executed; no cross-platform runtime success is claimed. The existing thread remains unresolved and unchanged. This is a COMMENT assessment, not approval.

Scope: code review only. CI/check status and merge readiness were not evaluated; use the repository's CI-analysis workflow for that assessment.

@dalexsoto dalexsoto left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Stamping as requested by @kubaflo; no code review performed.

@kubaflo
kubaflo merged commit 87f811b into main Oct 8, 2026
40 checks passed
@kubaflo
kubaflo deleted the revert-39247-sheiksyedm-blazorwebview-activity-leak branch October 8, 2026 15:16
@github-actions github-actions Bot added this to the .NET 10 SR12 milestone Oct 8, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 8, 2026

This branch was previously deployed

1 inactive deployment
copilot-pat-pool — cc0adad3 Deployed Oct 8, 2026 by kubaflo via conclusion #2283
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants