Skip to content

Commit

Permalink
Fixes issue 90
Browse files Browse the repository at this point in the history
  • Loading branch information
EdCharbeneau committed Apr 25, 2023
1 parent 248076c commit 2c63ff7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
3 changes: 2 additions & 1 deletion BlazorSize/BlazorPro.BlazorSize.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<Version>6.2.0</Version>
<Version>6.2.1</Version>
<Authors>Ed Charbeneau</Authors>
<Company>EdCh1rbeneau.com</Company>
<Description>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.</Description>
Expand All @@ -16,6 +16,7 @@
<RepositoryUrl>https://github.com/EdCharbeneau/BlazorSize</RepositoryUrl>
<PackageTags>Blazor, JavaScript Interop</PackageTags>
<PackageReleaseNotes>
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.
Expand Down
19 changes: 14 additions & 5 deletions BlazorSize/MediaQuery/MediaQueryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -98,11 +98,20 @@ public async Task CreateMediaQueryList(DotNetObjectReference<MediaQueryList> 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
}
}

Expand Down
21 changes: 15 additions & 6 deletions BlazorSize/Resize/ResizeListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class ResizeListener : IResizeListener, IAsyncDisposable
private readonly Lazy<Task<IJSObjectReference>> moduleTask;

private readonly ResizeOptions options;

private bool disposed;
public ResizeListener(IJSRuntime jsRuntime, IOptions<ResizeOptions>? options = null)
{
Expand Down Expand Up @@ -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);
}
}
}

0 comments on commit 2c63ff7

Please sign in to comment.