Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Exception in FluentAnchor #1652

Closed
JamesNK opened this issue Mar 7, 2024 · 1 comment
Closed

fix: Exception in FluentAnchor #1652

JamesNK opened this issue Mar 7, 2024 · 1 comment

Comments

@JamesNK
Copy link
Member

JamesNK commented Mar 7, 2024

🐛 Bug Report

💻 Repro or Code Sample

I left a Blazor page open for a while in the background. When I came back to it there was an error from FluentAnchor:

2024-03-07T17:49:39.8637041 warn: Microsoft.AspNetCore.Components.Server.Circuits.RemoteRenderer[100]
      Unhandled exception rendering component: A task was canceled.
      System.Threading.Tasks.TaskCanceledException: A task was canceled.
         at Microsoft.JSInterop.JSRuntime.InvokeAsync[TValue](Int64 targetInstanceId, String identifier, Object[] args)
         at Microsoft.JSInterop.JSRuntimeExtensions.InvokeVoidAsync(IJSRuntime jsRuntime, String identifier, Object[] args)
         at Microsoft.JSInterop.Implementation.JSObjectReference.DisposeAsync()
         at Microsoft.FluentUI.AspNetCore.Components.FluentAnchor.DisposeAsync() in /_/src/Core/Components/Anchor/FluentAnchor.razor.cs:line 151
         at Microsoft.AspNetCore.Components.RenderTree.Renderer.<ProcessDisposalQueueInExistingBatch>g__GetHandledAsynchronousDisposalErrorsTask|79_0(Task result)

🤔 Expected Behavior

No error.

😯 Current Behavior

Error.

💁 Possible Solution

Error comes from here:

public async ValueTask DisposeAsync()
{
try
{
if (_jsModule is not null)
{
await _jsModule.DisposeAsync();
}
}
catch (JSDisconnectedException)
{
// The JSRuntime side may routinely be gone already if the reason we're disposing is that
// the client disconnected. This is not an error.
}
}

It appears to throw JSDisconnectedException or OperationCanceledException. Catch both?

🔦 Context

🌍 Your Environment

  • OS & Device: [e.g. MacOS, iOS, Windows, Linux] on [iPhone 7, PC]
  • Browser [e.g. Microsoft Edge, Google Chrome, Apple Safari, Mozilla FireFox]
  • .NET and Fluent UI Blazor library Version [e.g. 8.0.2 and 4.4.1]
@JamesNK
Copy link
Member Author

JamesNK commented Mar 7, 2024

I also saw this with a list:

2024-03-07T20:33:43.5306944 warn: Microsoft.AspNetCore.Components.Server.Circuits.RemoteRenderer[100]
      Unhandled exception rendering component: A task was canceled.
      System.Threading.Tasks.TaskCanceledException: A task was canceled.
         at Microsoft.JSInterop.JSRuntime.InvokeAsync[TValue](Int64 targetInstanceId, String identifier, Object[] args)
         at Microsoft.JSInterop.JSRuntimeExtensions.InvokeVoidAsync(IJSRuntime jsRuntime, String identifier, Object[] args)
         at Microsoft.JSInterop.Implementation.JSObjectReference.DisposeAsync()
         at Microsoft.FluentUI.AspNetCore.Components.ListComponentBase`1.DisposeAsync() in /_/src/Core/Components/List/ListComponentBase.razor.cs:line 595
         at Microsoft.AspNetCore.Components.RenderTree.Renderer.<ProcessDisposalQueueInExistingBatch>g__GetHandledAsynchronousDisposalErrorsTask|79_0(Task result)

I suggest you add a utility method for disposing JSObjectReference and have it catch the two errors, then use that where ever you dispose.

vnbaaij added a commit that referenced this issue Mar 7, 2024
@vnbaaij vnbaaij closed this as completed in acf444f Mar 7, 2024
vnbaaij added a commit that referenced this issue Mar 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant