From b95e377a7ea2d0af6f7ae9aa9cd149a8b6fe3933 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Mon, 4 Jul 2022 17:30:57 +0200 Subject: [PATCH 1/2] Added failing batch update test. --- .../AvaloniaObjectTests_BatchUpdate.cs | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_BatchUpdate.cs b/tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_BatchUpdate.cs index 01d5752ead..45de860894 100644 --- a/tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_BatchUpdate.cs +++ b/tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_BatchUpdate.cs @@ -611,6 +611,36 @@ namespace Avalonia.Base.UnitTests Assert.Equal("foo", notifications[1].NewValue); } + [Fact] + public void Can_Run_Empty_Batch_Update_When_Ending_Batch_Update() + { + var target = new TestClass(); + var raised = 0; + var notifications = new List(); + + target.Foo = "foo"; + target.Bar = "bar"; + + target.BeginBatchUpdate(); + target.ClearValue(TestClass.FooProperty); + target.ClearValue(TestClass.BarProperty); + target.PropertyChanged += (sender, e) => + { + if (e.Property == TestClass.BarProperty) + { + target.BeginBatchUpdate(); + target.EndBatchUpdate(); + } + + ++raised; + }; + target.EndBatchUpdate(); + + Assert.Null(target.Foo); + Assert.Null(target.Bar); + Assert.Equal(2, raised); + } + public class TestClass : AvaloniaObject { public static readonly StyledProperty FooProperty = From 259c2d8020c3891f2f3394290568e558e9544621 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Mon, 4 Jul 2022 17:32:38 +0200 Subject: [PATCH 2/2] Remove check for invalid state. This state is not actually invalid: it can happen when running an empty batch update of >1 value which causes new, empty batch update to run in a `PropertyChanged` handler triggered from the first batch update. --- src/Avalonia.Base/ValueStore.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Avalonia.Base/ValueStore.cs b/src/Avalonia.Base/ValueStore.cs index 69c644dff9..bf29e0b0ac 100644 --- a/src/Avalonia.Base/ValueStore.cs +++ b/src/Avalonia.Base/ValueStore.cs @@ -462,10 +462,6 @@ namespace Avalonia values.Remove(entry.property); } } - else - { - throw new AvaloniaInternalException("Value could not be found at the end of batch update."); - } // If a new batch update was started while ending this one, abort. if (_batchUpdateCount > 0)