Repository navigation
Revert "Fix BlazorWebView root component subscriptions on disconnect" - #39251
Conversation
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 39251Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 39251" |
|
@dalexsoto stamp |
|
Azure Pipelines: Successfully started running 1 pipeline(s). There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
🟡 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
left a comment
There was a problem hiding this comment.
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.
-
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'sRootComponents.CollectionChangeddelegate 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 isRootComponents -> delegate -> old handler -> MauiContext -> cached Android Context. Generic handler disconnect clearsVirtualView/PlatformView, notMauiContext; creating the Android WebView evaluates the context'sLazy<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. -
Confirmed existing finding — reconnect clears application root components. After disconnect,
_rootComponentsstill references the view's collection. CallingSetVirtualViewon that handler and view rerunsMapRootComponents; 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.

This should be merged to inflight/current