Repository navigation
fix: Subscribe to Command.CanExecuteChanged weakly - #25965
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]>
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]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🤖 Your WebAssembly Sample App stage site is ready! Visit it here: |
|
The build 243119 found UI Test snapshots differences: Details
|
|
@Mergifyio backport release/stable/6.7 servicing/6.8 release/stable/7.0 |
✅ Backports have been createdDetails
Cherry-pick of fc1ef84 has failed: To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally
Cherry-pick of fc1ef84 has failed: To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally
|
…r-25965 fix: Subscribe to Command.CanExecuteChanged weakly (backport #25965)
…6.7/pr-25965 fix: Subscribe to Command.CanExecuteChanged weakly (backport #25965)
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