Repository navigation
fix: Subscribe to Command.CanExecuteChanged weakly (backport #25965) - #26004
Closed
mergify[bot] wants to merge 3 commits into
Closed
mergify[bot] wants to merge 3 commits into
mergify[bot] wants to merge 3 commits into
Conversation
A control that never enters the live tree is kept alive by a long-lived command through its CanExecuteChanged subscription. Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit fc1ef84)
ButtonBase and MenuFlyoutItem now hold their CanExecuteChanged subscription weakly, as WinUI does (WeakEventPtr), so a long-lived command no longer keeps alive a control that never entered the live tree, e.g. an item of a MenuFlyout that is never opened. The command only references a small subscription that holds the control through a weak reference. The control keeps a handle whose finalizer removes that subscription from the command, on the UI thread. Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit eff7885)
Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit e6e4535)
2 of 5 tasks
Contributor
|
🤖 Your WebAssembly Sample App stage site is ready! Visit it here: |
Xiaoy312
approved these changes
Nov 3, 2026
Contributor
|
The build 243446 did not find any UI Test snapshots differences. |
Xiaoy312
enabled auto-merge
November 4, 2026 01:52
Contributor
Author
|
Queued — the merge queue status continues in this comment ↓. |
Contributor
Author
🚫 Left the queue · pull request dequeuedLess than a minute in the queue, with no time running CI. So far
Reason Pull request #26004 has been dequeued GitHub refused to merge the pull request. Repository rule violations found
To get back in the queue
Tick the box to put this pull request back in the merge queue (same as
2 merge conditions met
Times in UTC · dashboard · how the merge queue works |
MartinZikmund
disabled auto-merge
November 4, 2026 13:46
Member
|
Covered in sync PR: #26026 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
GitHub Issue: closes #25969, closes unoplatform/kahua-private#562
PR Type:
🐞 Bugfix
What changed? 🚀
ButtonBaseandMenuFlyoutItemsubscribed toCommand.CanExecuteChangedwith a strong handler. They only removed it when the command changed or inLeaveImpl. So a control that never entered the live tree stayed alive for as long as its command, for example:MenuFlyoutthat is never opened, which in turn keep the whole screen alive throughDataContextand their parents;WinUI holds this subscription weakly (
ctl::WeakEventPtr).This PR does the same with a new internal helper,
WeakCanExecuteChangedSubscription:ICommandisn't required to be thread-safe.LeaveImpl, removes the subscription right away and skips the finalizer.AppBarButton,ToggleMenuFlyoutItem,RadioMenuFlyoutItemand the other subclasses get the fix through their base class. No otherCanExecuteChangedsubscription remains inUno.UI.Behaviour change: if a command's
removeaccessor throws, the exception is now logged at Error level. Previously it propagated from theCommandsetter or fromLeaveImpl.Not changed: subscribing only while the control is in the live tree would avoid the finalizer. However, WinUI keeps a never-loaded control's
IsEnabledin sync withCanExecute; the new tests confirm this on native WinUI. Doing so would therefore break WinUI parity.Validation
Given_CommandCanExecuteChanged: 18/18 pass. Before the fix, the leak tests fail.Uno.UIbuild, the WinAppSDK head, anddotnet format whitespaceare clean.Task.Yieldcollection loop, ignored on NativeAOT); CI will confirm.PR Checklist ✅
Screenshots Compare Test Runresults.🤖 Generated with Claude Code
This is an automatic backport of pull request #25965 done by [Mergify](https://mergify.com).