Skip to content
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions src/Core/Components/Menu/FluentMenu.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
private IMenuService? _menuService = null;
private IJSObjectReference _jsModule = default!;
private IJSObjectReference _anchoredRegionModule = default!;
private bool _disposed;

private (int top, int right, int bottom, int left) _stylePositions;

Expand Down Expand Up @@ -240,14 +241,14 @@
}
}

if (_jsModule is not null && _anchoredRegionModule is not null)
if (!_disposed)
{
await _jsModule.InvokeVoidAsync("initialize", Anchor, Id, Open, _anchoredRegionModule, _dotNetHelper);
}
}
else
{
if (_jsModule is not null && _anchoredRegionModule is not null && _reinitializeEventListeners)
if (!_disposed && _reinitializeEventListeners)
{
// If the menu was closed, remove its set event listeners. If it opened (ie if the menu starts out closed),
// we should set them now.
Expand Down Expand Up @@ -385,6 +386,10 @@

internal async Task<bool> IsCheckedAsync(FluentMenuItem item)
{
if (_jsModule is null)
{
return false;
}
return await _jsModule.InvokeAsync<bool>("isChecked", item.Id);
}

Expand All @@ -393,6 +398,12 @@
/// </summary>
public async ValueTask DisposeAsync()
{
if (_disposed)
{
return;
}

_disposed = true;
_dotNetHelper?.Dispose();

try
Expand All @@ -401,11 +412,13 @@
{
await _jsModule.InvokeVoidAsync("dispose", Anchor);
await _jsModule.DisposeAsync();
_jsModule = null;

Check warning on line 415 in src/Core/Components/Menu/FluentMenu.razor.cs

View workflow job for this annotation

GitHub Actions / Build and Test Core Lib

Cannot convert null literal to non-nullable reference type.

Check warning on line 415 in src/Core/Components/Menu/FluentMenu.razor.cs

View workflow job for this annotation

GitHub Actions / Build and Test Core Lib

Cannot convert null literal to non-nullable reference type.

Check warning on line 415 in src/Core/Components/Menu/FluentMenu.razor.cs

View workflow job for this annotation

GitHub Actions / Build and Test Core Lib

Cannot convert null literal to non-nullable reference type.

Check warning on line 415 in src/Core/Components/Menu/FluentMenu.razor.cs

View workflow job for this annotation

GitHub Actions / Build and Test Core Lib

Cannot convert null literal to non-nullable reference type.

Check warning on line 415 in src/Core/Components/Menu/FluentMenu.razor.cs

View workflow job for this annotation

GitHub Actions / Build and Test Core Lib

Cannot convert null literal to non-nullable reference type.

Check warning on line 415 in src/Core/Components/Menu/FluentMenu.razor.cs

View workflow job for this annotation

GitHub Actions / Build and Test Core Lib

Cannot convert null literal to non-nullable reference type.
}

if (_anchoredRegionModule is not null)
{
await _anchoredRegionModule.DisposeAsync();
_anchoredRegionModule = null;

Check warning on line 421 in src/Core/Components/Menu/FluentMenu.razor.cs

View workflow job for this annotation

GitHub Actions / Build and Test Core Lib

Cannot convert null literal to non-nullable reference type.

Check warning on line 421 in src/Core/Components/Menu/FluentMenu.razor.cs

View workflow job for this annotation

GitHub Actions / Build and Test Core Lib

Cannot convert null literal to non-nullable reference type.

Check warning on line 421 in src/Core/Components/Menu/FluentMenu.razor.cs

View workflow job for this annotation

GitHub Actions / Build and Test Core Lib

Cannot convert null literal to non-nullable reference type.

Check warning on line 421 in src/Core/Components/Menu/FluentMenu.razor.cs

View workflow job for this annotation

GitHub Actions / Build and Test Core Lib

Cannot convert null literal to non-nullable reference type.

Check warning on line 421 in src/Core/Components/Menu/FluentMenu.razor.cs

View workflow job for this annotation

GitHub Actions / Build and Test Core Lib

Cannot convert null literal to non-nullable reference type.

Check warning on line 421 in src/Core/Components/Menu/FluentMenu.razor.cs

View workflow job for this annotation

GitHub Actions / Build and Test Core Lib

Cannot convert null literal to non-nullable reference type.
}
}
catch (Exception ex) when (ex is JSDisconnectedException ||
Expand All @@ -414,5 +427,9 @@
// The JSRuntime side may routinely be gone already if the reason we're disposing is that
// the client disconnected. This is not an error.
}
finally
{
GC.SuppressFinalize(this);
}
}
}
Loading