diff --git a/src/ReactiveUI.Blazor/ReactiveComponentBase.cs b/src/ReactiveUI.Blazor/ReactiveComponentBase.cs index f8ef575029..b6e609879f 100644 --- a/src/ReactiveUI.Blazor/ReactiveComponentBase.cs +++ b/src/ReactiveUI.Blazor/ReactiveComponentBase.cs @@ -7,12 +7,10 @@ using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics.CodeAnalysis; -using System.Linq; using System.Reactive; using System.Reactive.Linq; using System.Reactive.Subjects; using System.Runtime.CompilerServices; -using System.Threading.Tasks; using Microsoft.AspNetCore.Components; namespace ReactiveUI.Blazor @@ -37,7 +35,7 @@ public class ReactiveComponentBase : ComponentBase, IViewFor, INotifyPrope /// public ReactiveComponentBase() { - this.WhenAnyValue(x => x.ViewModel).Subscribe(_ => StateHasChanged()); + this.WhenAnyValue(x => x.ViewModel).Where(x => x != null).Subscribe(_ => StateHasChanged()); var viewModelsPropertyChanged = this.WhenAnyValue(x => x.ViewModel) .Where(x => x != null) .Select(x => Observable.FromEvent( diff --git a/src/ReactiveUI.Blazor/ReactiveLayoutComponentBase.cs b/src/ReactiveUI.Blazor/ReactiveLayoutComponentBase.cs index b73b443993..e7ada4551e 100644 --- a/src/ReactiveUI.Blazor/ReactiveLayoutComponentBase.cs +++ b/src/ReactiveUI.Blazor/ReactiveLayoutComponentBase.cs @@ -33,7 +33,7 @@ public class ReactiveLayoutComponentBase : LayoutComponentBase, IViewFor, /// public ReactiveLayoutComponentBase() { - this.WhenAnyValue(x => x.ViewModel).Subscribe(_ => StateHasChanged()); + this.WhenAnyValue(x => x.ViewModel).Where(x => x != null).Subscribe(_ => StateHasChanged()); var viewModelsPropertyChanged = this.WhenAnyValue(x => x.ViewModel) .Where(x => x != null) .Select(x => Observable.FromEvent( diff --git a/src/ReactiveUI.Blazor/ReactiveUI.Blazor.csproj b/src/ReactiveUI.Blazor/ReactiveUI.Blazor.csproj index 2461bd56db..0687178296 100644 --- a/src/ReactiveUI.Blazor/ReactiveUI.Blazor.csproj +++ b/src/ReactiveUI.Blazor/ReactiveUI.Blazor.csproj @@ -7,7 +7,7 @@ - +