From 15ba356cf2c084a9277701f8ed4b97369da4fd86 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Fri, 25 Apr 2025 14:26:26 -0500 Subject: [PATCH] Wait to update SearchText until we've actually updated SearchText Closes #38829 If we always UpdateProperty here, then there's a possible race condition, where we raise the PropertyChanged(SearchText) before the subclass actually retrieves the new SearchText from the model. In that race situation, if the UI thread handles the PropertyChanged before ListViewModel fetches the SearchText, it'll think that the old search text is the _new_ value. --- .../PageViewModel.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/PageViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/PageViewModel.cs index a082f0acd2d9..c34f7e38ef38 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/PageViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/PageViewModel.cs @@ -182,6 +182,7 @@ protected virtual void FetchProperty(string propertyName) return; // throw? } + var updateProperty = true; switch (propertyName) { case nameof(Name): @@ -198,9 +199,21 @@ protected virtual void FetchProperty(string propertyName) case nameof(Icon): this.Icon = new(model.Icon); break; + default: + updateProperty = false; + break; } - UpdateProperty(propertyName); + // GH #38829: If we always UpdateProperty here, then there's a possible + // race condition, where we raise the PropertyChanged(SearchText) + // before the subclass actually retrieves the new SearchText from the + // model. In that race situation, if the UI thread handles the + // PropertyChanged before ListViewModel fetches the SearchText, it'll + // think that the old search text is the _new_ value. + if (updateProperty) + { + UpdateProperty(propertyName); + } } public new void ShowException(Exception ex, string? extensionHint = null)