Skip to content

Commit b9819c0

Browse files
authored
Merge pull request #48 from WiseTechGlobal/LNS/Winzor/WI00745224-JavaScript_interop_calls_cannot_be_issued_at_this_time
WI00745224 - JavaScript interop calls cannot be issued at this time
2 parents 1d5a782 + f8c24c1 commit b9819c0

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/Blazor.Diagrams/Components/DiagramCanvas.razor.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System;
2-
using System.Threading.Tasks;
3-
using Blazor.Diagrams.Core.Behaviors;
1+
using Blazor.Diagrams.Core.Behaviors;
42
using Blazor.Diagrams.Core.Geometry;
53
using Blazor.Diagrams.Extensions;
64
using Microsoft.AspNetCore.Components;
@@ -40,6 +38,9 @@ public async ValueTask DisposeAsync()
4038
await JSRuntime.UnobserveResizes(elementReference);
4139

4240
_reference.Dispose();
41+
_reference = null!;
42+
43+
GC.SuppressFinalize(this); // CA1816
4344
}
4445

4546
private string GetLayerStyle(int order)

src/Blazor.Diagrams/Extensions/JSRuntimeExtensions.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System;
2-
using System.Threading.Tasks;
3-
using Blazor.Diagrams.Core.Geometry;
1+
using Blazor.Diagrams.Core.Geometry;
42
using Microsoft.AspNetCore.Components;
53
using Microsoft.JSInterop;
64

@@ -28,7 +26,14 @@ public static async Task ObserveResizes<T>(this IJSRuntime jsRuntime, ElementRef
2826

2927
public static async Task UnobserveResizes(this IJSRuntime jsRuntime, ElementReference element)
3028
{
31-
await jsRuntime.InvokeVoidAsync("ZBlazorDiagrams.unobserve", element, element.Id);
29+
try
30+
{
31+
await jsRuntime.InvokeVoidAsync("ZBlazorDiagrams.unobserve", element, element.Id);
32+
}
33+
catch (JSDisconnectedException)
34+
{
35+
// Ignore, JSRuntime was already disconnected
36+
}
3237
}
3338

3439
public static async Task AddDefaultPreventingForWheelHandler(this IJSRuntime jsRuntime, ElementReference element)

0 commit comments

Comments
 (0)