Skip to content

Commit

Permalink
fix(blazor): remove sync dispose
Browse files Browse the repository at this point in the history
  • Loading branch information
SonicGD committed Dec 6, 2023
1 parent c397acc commit c880db5
Showing 1 changed file with 3 additions and 15 deletions.
18 changes: 3 additions & 15 deletions src/Sitko.Core.Blazor/Components/BaseComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public interface IBaseComponent
Task NotifyStateChangeAsync();
}

public abstract class BaseComponent : ComponentBase, IAsyncDisposable, IDisposable
public abstract class BaseComponent : ComponentBase, IAsyncDisposable
{
private static readonly FieldInfo? RenderFragment = typeof(ComponentBase).GetField("_renderFragment",
BindingFlags.NonPublic | BindingFlags.Instance);
Expand Down Expand Up @@ -120,29 +120,18 @@ public async ValueTask DisposeAsync()
if (!isDisposed)
{
NavigationManager.LocationChanged -= HandleLocationChanged;
Dispose(true);
await DisposeAsync(true);
if (scope is not null)
{
await scope.Value.DisposeAsync();
}

Dispose(true);
await DisposeAsync(true);
isDisposed = true;
GC.SuppressFinalize(this);
}
}

public void Dispose()
{
if (!isDisposed)
{
throw new InvalidOperationException(
"This class must not be disposed synchronously. This method only here to avoid exception on sync scope dispose in .NET 5");
}

GC.SuppressFinalize(this);
}

public override string ToString() => $"{GetType().Name} {ComponentId}";

public Task NotifyStateChangeAsync() => InvokeAsync(StateHasChanged);
Expand Down Expand Up @@ -334,4 +323,3 @@ public enum ScopeType
{
Parent = 0, Isolated = 1
}

0 comments on commit c880db5

Please sign in to comment.