From 2c63ff72bdfe5e15727acdbd3fa1e497817c1de1 Mon Sep 17 00:00:00 2001 From: "ed.charbeneau@gmail.com" Date: Tue, 25 Apr 2023 12:54:38 -0400 Subject: [PATCH] Fixes issue 90 --- BlazorSize/BlazorPro.BlazorSize.csproj | 3 ++- BlazorSize/MediaQuery/MediaQueryService.cs | 19 ++++++++++++++----- BlazorSize/Resize/ResizeListener.cs | 21 +++++++++++++++------ 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/BlazorSize/BlazorPro.BlazorSize.csproj b/BlazorSize/BlazorPro.BlazorSize.csproj index 12cbe8f..8237234 100644 --- a/BlazorSize/BlazorPro.BlazorSize.csproj +++ b/BlazorSize/BlazorPro.BlazorSize.csproj @@ -5,7 +5,7 @@ true enable latest - 6.2.0 + 6.2.1 Ed Charbeneau EdCh1rbeneau.com A JavaScript interop for Blazor used to detect the browser's screen size and perform Media Query tests. BlazorSize uses the DOM API `matchMedia` to test screen size. BlazorSize was created to allow Blazor components to render adaptively. @@ -16,6 +16,7 @@ https://github.com/EdCharbeneau/BlazorSize Blazor, JavaScript Interop + 6.2.1 Fixed Microsoft.JSInterop.JSDisconnectedException 6.2.0 Fixed bug where MediaQuery dispose was not always working correctly. 6.1.2 Fixed casing on JS modules, fixes deployment issues on Linux. (regression) 6.1.1 Replaced deprecated `addListener` method. Removed console log messages, again. diff --git a/BlazorSize/MediaQuery/MediaQueryService.cs b/BlazorSize/MediaQuery/MediaQueryService.cs index 00a0ad5..9850481 100644 --- a/BlazorSize/MediaQuery/MediaQueryService.cs +++ b/BlazorSize/MediaQuery/MediaQueryService.cs @@ -42,7 +42,7 @@ public async Task RemoveQuery(MediaQuery mediaQuery) if (mediaQuery == null) return; var cache = GetMediaQueryFromCache(byMedia: mediaQuery.Media); - + if (cache == null) return; cache.MediaQueries.Remove(mediaQuery); @@ -98,11 +98,20 @@ public async Task CreateMediaQueryList(DotNetObjectReference dot public async ValueTask DisposeAsync() { - if (DotNetInstance != null) + try { - var module = await moduleTask.Value; - await module.InvokeVoidAsync("removeMediaQueryList", DotNetInstance); - DotNetInstance.Dispose(); + if (DotNetInstance != null) + { + var module = await moduleTask.Value; + await module.InvokeVoidAsync("removeMediaQueryList", DotNetInstance); + DotNetInstance.Dispose(); + await module.DisposeAsync(); + GC.SuppressFinalize(this); + } + } + catch (Exception) + { + //https://stackoverflow.com/questions/72488563/blazor-server-side-application-throwing-system-invalidoperationexception-javas } } diff --git a/BlazorSize/Resize/ResizeListener.cs b/BlazorSize/Resize/ResizeListener.cs index 2adc7f6..c46fa5a 100644 --- a/BlazorSize/Resize/ResizeListener.cs +++ b/BlazorSize/Resize/ResizeListener.cs @@ -10,7 +10,7 @@ public class ResizeListener : IResizeListener, IAsyncDisposable private readonly Lazy> moduleTask; private readonly ResizeOptions options; - + private bool disposed; public ResizeListener(IJSRuntime jsRuntime, IOptions? options = null) { @@ -103,13 +103,22 @@ protected virtual void Dispose(bool disposing) public async ValueTask DisposeAsync() { - if (moduleTask.IsValueCreated) + try + { + + + if (moduleTask.IsValueCreated) + { + var module = await moduleTask.Value; + await module.DisposeAsync(); + } + Dispose(true); + GC.SuppressFinalize(this); + } + catch (Exception) { - var module = await moduleTask.Value; - await module.DisposeAsync(); + //https://stackoverflow.com/questions/72488563/blazor-server-side-application-throwing-system-invalidoperationexception-javas } - Dispose(true); - GC.SuppressFinalize(this); } } } \ No newline at end of file