Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/merge-net11-to-release.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Merge net11.0 → next release branch
# Target branch is configured in /github-merge-flow-release-11.jsonc (MergeToBranch)
#
# This workflow must be triggered FROM the net11.0 branch because the arcade merge
# script uses GITHUB_REF_NAME as the config lookup key. When triggered via
# workflow_dispatch from the GitHub UI, select 'net11.0' from the branch dropdown.
# The schedule trigger only works when this file exists on net11.0.

name: Merge net11.0 to next release

Expand All @@ -17,6 +22,8 @@ permissions:

jobs:
Merge:
# Only run if triggered from net11.0 (push trigger or correct workflow_dispatch)
if: github.ref_name == 'net11.0'
uses: dotnet/arcade/.github/workflows/inter-branch-merge-base.yml@main
with:
configuration_file_path: 'github-merge-flow-release-11.jsonc'
1 change: 1 addition & 0 deletions eng/pipelines/ci-official.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ extends:
onlyAndroidPlatformDefaultApis: true
skipAndroidEmulatorImages: true
skipAndroidCreateAvds: true
skipSimulatorSetup: true
skipProvisioning: true
skipXcode: false
base64Encode: true
Expand Down
2 changes: 1 addition & 1 deletion github-merge-flow-release-11.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
"merge-flow-configurations": {
"net11.0": {
"MergeToBranch": "release/11.0.1xx-preview4",
"MergeToBranch": "release/11.0.1xx-preview6",
"ExtraSwitches": "-QuietComments",
"ResetToTargetPaths": "global.json;NuGet.config;eng/Version.Details.xml;eng/Versions.props;eng/common/*"
}
Expand Down
9 changes: 6 additions & 3 deletions src/Controls/src/Core/AdaptiveTrigger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ namespace Microsoft.Maui.Controls
/// </summary>
public sealed class AdaptiveTrigger : StateTriggerBase
{
VisualElement? _visualElement;
// Weak reference so the trigger does not prevent the VisualElement from being
// garbage-collected if SendDetached() is somehow missed.
WeakReference<VisualElement>? _visualElement;
Window? _window;

/// <summary>
Expand Down Expand Up @@ -69,9 +71,10 @@ void AttachEvents()
{
DetachEvents();

_visualElement = VisualState?.VisualStateGroup?.VisualElement;
var element = VisualState?.VisualStateGroup?.VisualElement;
_visualElement = element is not null ? new WeakReference<VisualElement>(element) : null;

_window = _visualElement?.Window;
_window = element?.Window;
if (_window is not null)
{
_window.SizeChanged += OnWindowSizeChanged;
Expand Down
17 changes: 17 additions & 0 deletions src/Controls/src/Core/VisualStateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ static void VisualStateGroupsPropertyChanged(BindableObject bindable, object old

foreach (var group in oldVisualStateGroupList)
{
// Detach triggers first so OnDetached() unsubscribes window events before visual cleanup.
foreach (var visualState in group.States)
{
foreach (var trigger in visualState.StateTriggers)
{
trigger.SendDetached();
}
}

if (group.CurrentState is { } state)
{
// Only promote system-driven states (Disabled, Focused, etc.) to full VSM priority.
Expand All @@ -62,6 +71,14 @@ static void VisualStateGroupsPropertyChanged(BindableObject bindable, object old
visualElement.ChangeVisualState();

UpdateStateTriggers(visualElement);

// Attach state triggers from the incoming groups if the element is already in a Window.
// Normally triggers are attached via VisualElement.InvalidateStateTriggers(true) when the
// element joins a Window, but that event has already fired before this replacement occurs.
if (newValue != null && visualElement.Window != null)
{
visualElement.InvalidateStateTriggers(true);
}
}

/// <summary>
Expand Down
56 changes: 56 additions & 0 deletions src/Controls/tests/Core.UnitTests/AdaptiveTriggerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,62 @@ namespace Microsoft.Maui.Controls.Core.UnitTests

public class AdaptiveTriggerTests : BaseTestFixture
{
// Regression tests for https://github.com/dotnet/maui/issues/36032
// AdaptiveTrigger leaks VisualElement when VisualStateGroups are replaced after attach

[Fact]
public void OldAdaptiveTriggerDetachedWhenVSGsReplacedAfterAttach()
{
// Arrange: set up a label with an AdaptiveTrigger, attach it to a Window
var label = new Label();
var oldTrigger = new AdaptiveTrigger { MinWindowWidth = 300 };
var newTrigger = new AdaptiveTrigger { MinWindowWidth = 500 };

VisualStateManager.SetVisualStateGroups(label, new VisualStateGroupList
{
new VisualStateGroup
{
States =
{
new VisualState
{
Name = "Large",
StateTriggers = { oldTrigger },
Setters = { new Setter { Property = Label.BackgroundProperty, Value = new SolidColorBrush(Colors.Green) } }
},
}
}
});

var page = new ContentPage { Content = label };
_ = new Window { Page = page };

// Old trigger should be attached after element joins a Window
Assert.True(oldTrigger.IsAttached);

// Act: replace the VisualStateGroups while the element is already attached to a Window
VisualStateManager.SetVisualStateGroups(label, new VisualStateGroupList
{
new VisualStateGroup
{
States =
{
new VisualState
{
Name = "ExtraLarge",
StateTriggers = { newTrigger },
Setters = { new Setter { Property = Label.BackgroundProperty, Value = new SolidColorBrush(Colors.Blue) } }
},
}
}
});

// Assert: old trigger must be detached (unsubscribed from Window.SizeChanged)
Assert.False(oldTrigger.IsAttached, "Old AdaptiveTrigger should be detached after VSGs are replaced");
// Assert: new trigger should now be attached
Assert.True(newTrigger.IsAttached, "New AdaptiveTrigger should be attached after VSGs are replaced");
}

[Fact]
public void ResizingWindowPageActivatesTrigger()
{
Expand Down
Loading