Repository navigation
Keep StatesChanged subscriptions in step in the VisualStateGroupList indexer - #38411
wbv-profile wants to merge 1 commit into
Conversation
…indexer Add, Insert, Remove, RemoveAt and Clear all subscribe or unsubscribe VisualStateGroup.StatesChanged as appropriate; the indexer setter assigned straight through to the backing list instead. The subscription runs group -> list, so a displaced group the app still held kept the whole VisualStateGroupList -- and the VisualElement that owns it -- alive, and went on raising validation notifications for a list it had left. The incoming group, meanwhile, was never subscribed, so its state changes never reached validation at all. The setter now unsubscribes the displaced group and subscribes the incoming one, with a reference-equality short circuit. Null is handled without subscribing rather than by throwing, to avoid introducing a new exception on a path that previously accepted it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 38411Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 38411" |
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
|
Closing this overlapping implementation in favor of #37340, already merged into The subscription repair here is useful, but the existing fix is more complete: it also calls This is duplication in |
Description of Change
VisualStateGroupListkeeps itsVisualStateGroup.StatesChangedsubscriptions in step on every mutation path —Add,Insert,Remove,RemoveAtandClearall subscribe or unsubscribe as appropriate. The indexer setter did not: it assigned straight through to the backing list.That left two defects:
VisualStateGroup.StatesChangedholds the list'sValidateAndNotify), so a displaced group the app still holds kept the wholeVisualStateGroupListalive, and with it theVisualElementthat owns it. The displaced group also went on raising validation notifications for a list it was no longer part of.The setter now unsubscribes the displaced group, assigns, and subscribes the incoming one, with a reference-equality short circuit so assigning the same instance stays a no-op. Null is handled without subscribing rather than by throwing, to avoid introducing a new exception on a path that previously accepted it.
Same defect class as #38397, #38403, #38405, #38408 and #38410, though the fix here is a missing unsubscribe rather than a weak-event conversion — the group and list are peers with a shared lifetime, so a plain subscription is correct as long as it is torn down.
Not covered here: the three related
[leak-scan]reports aboutStateTriggerBasedetachment (#38243, #38244, #38245) — triggers are only sentSendDetached()when the entireVisualStateGroupscollection is replaced, not when an individual group or state is removed. Fixing that means changing when triggers detach and re-attach, which is a behavioural change worth its own PR rather than a rider on this one.Tests
src/Controls/tests/Core.UnitTests/VisualStateGroupListIndexerTests.csadds four tests. Reverting the source change fails two of them —DisplacedGroupDoesNotRootTheList(the leak) andReplacingByIndexSubscribesTheIncomingGroup(the missed subscription). The other two pin behaviour the change must preserve: the displaced group no longer being validated by the list, and same-instance assignment being a no-op.With the fix all four pass and the full
Controls.Core.UnitTestssuite is green.Issues Fixed
Fixes #37171