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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Error in JS invoke in OnAfterRenderAsync #1673

Open
JamesNK opened this issue Mar 10, 2024 · 1 comment
Open

fix: Error in JS invoke in OnAfterRenderAsync #1673

JamesNK opened this issue Mar 10, 2024 · 1 comment

Comments

@JamesNK
Copy link
Member

JamesNK commented Mar 10, 2024

馃悰 Bug Report

It you put controls on a page and then rapidly refresh the browser you'll quickly get errors in logging from JS invoke calls from OnAfterRenderAsync.

I've observed this with FluentDivider and FluentInputLabel. I'm guessing the problem is common to all controls.

馃捇 Repro or Code Sample

Rapidly refresh browser with FluentDivider or FluentInputLabel on them, configured so that they call JS invoke when rendering.

Rapidly refresh browser.

馃 Expected Behavior

No error

馃槸 Current Behavior

Error.

2024-03-11T07:04:04.4305521 warn: Microsoft.AspNetCore.Components.Server.Circuits.RemoteRenderer[100]
      Unhandled exception rendering component: JavaScript interop calls cannot be issued at this time. This is because the circuit has disconnected and is being disposed.
      Microsoft.JSInterop.JSDisconnectedException: JavaScript interop calls cannot be issued at this time. This is because the circuit has disconnected and is being disposed.
         at Microsoft.JSInterop.JSRuntime.InvokeAsync[TValue](Int64 targetInstanceId, String identifier, CancellationToken cancellationToken, Object[] args)
         at Microsoft.JSInterop.JSRuntime.InvokeAsync[TValue](Int64 targetInstanceId, String identifier, Object[] args)
         at Microsoft.JSInterop.JSObjectReferenceExtensions.InvokeVoidAsync(IJSObjectReference jsObjectReference, String identifier, Object[] args)
         at Microsoft.FluentUI.AspNetCore.Components.FluentDivider.OnAfterRenderAsync(Boolean firstRender) in /_/src/Core/Components/Divider/FluentDivider.razor.cs:line 38
         at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)

馃拋 Possible Solution

馃敠 Context

Catch JSDisconnectedException from InvokeVoidAsync in OnAfterRender.

馃實 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]
@vnbaaij
Copy link
Collaborator

vnbaaij commented Mar 12, 2024

Adding a try...catch block in OnAfterRenderAsync never ends up in the catch block. On refresh the dispose functionality gets called and there you do end up in the try...catch block (which is already there).
We swllow the exception there but in VS you still get an error in the output window. I don't believethere is something we can do to prevent that.

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

2 participants