Skip to content

MudDrawer: Handle JSDisconnectedExceptions thrown when disposed.#4609

Closed
diegofrata wants to merge 1 commit intoMudBlazor:devfrom
diegofrata:jsdisconnected-exceptions
Closed

MudDrawer: Handle JSDisconnectedExceptions thrown when disposed.#4609
diegofrata wants to merge 1 commit intoMudBlazor:devfrom
diegofrata:jsdisconnected-exceptions

Conversation

@diegofrata
Copy link
Contributor

@diegofrata diegofrata commented May 16, 2022

Description

Resolves #4608 by ignoring exceptions thrown during Dispose. Also changes the call to Console.WriteLine to Debug.WriteLine as these messages are not desirable in a release build of a production application -- Console.WriteLine mangles log outputs of other components and doesn't allow the user to control the format (e.g. JSON logging)

How Has This Been Tested?

Visually.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • The PR is submitted to the correct branch (dev).
  • My code follows the code style of this project.
  • I've added relevant tests.

@codecov
Copy link

codecov bot commented May 16, 2022

Codecov Report

Merging #4609 (57c02f2) into dev (6f5264b) will not change coverage.
The diff coverage is 0.00%.

@@           Coverage Diff           @@
##              dev    #4609   +/-   ##
=======================================
  Coverage   91.30%   91.30%           
=======================================
  Files         362      362           
  Lines       12499    12499           
=======================================
  Hits        11412    11412           
  Misses       1087     1087           
Impacted Files Coverage Δ
src/MudBlazor/Components/Drawer/MudDrawer.razor.cs 80.12% <0.00%> (ø)
src/MudBlazor/Extensions/TaskExtensions.cs 55.55% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6f5264b...57c02f2. Read the comment docs.

@mikes-gh
Copy link
Contributor

Thanks for this
IMO the better solution is to have a DisposeAsync await and trap the error there. Thats the pattern we use in other places.
@just-the-benno @henon.

Really not a fan of AndForget

@just-the-benno
Copy link
Contributor

Hi @diegofrata, and thanks for submitting the PR.

I guess, the Console.WriteLine() is an artefact of a "testing" sessions. I also forget multiple times to take it out. I would remove it instead of changing it to Debug.WriteLine.

I agree with @mikes-gh regarding the DisposeAsync. It is consistent with other components and makes sense because you want to detach the event if the drawer is not needed anymore. (If I understood it correctly).

@diegofrata
Copy link
Contributor Author

Oh, I must have missed it. I saw AndForget being used in a few other places and understood it as pattern to be followed. I will refactor it and amend the PR! Thanks for the feedback!

@mikes-gh
Copy link
Contributor

mikes-gh commented May 19, 2022

Can we centralise the error trapping in the extension method?
So calling the extension. method is just a best efforts?

I would still advocate DisposeAsync as well though

@diegofrata
Copy link
Contributor Author

diegofrata commented May 19, 2022 via email

@mikes-gh
Copy link
Contributor

I probably should have been clearer.
I mean

https://github.com/diegofrata/MudBlazor/blob/57c02f2d321e9de2d9638e62779bba3078ac812a/src/MudBlazor/Extensions/ElementReferenceExtensions.cs#L96

What I am saying applies. to all our ElementRef extension methods. Trapping JSDisconnectedException might make sense here instead of in the component. When calling the extension method when there is no JSRuntime available should we just return a ValueTask.CompletedTask. These extension methods were written before JSDisconnectedException existed.

I may be wrong and haven't done tests.

@JonBunator JonBunator added bug Unexpected behavior or functionality not working as intended needs: changes A maintainer has asked for further modifications to be made to this pull request labels Jun 29, 2022
@mikes-gh mikes-gh changed the title Handle JSDisconnectedExceptions thrown when MudDrawer is disposed. MudDrawer: Handle JSDisconnectedExceptions thrown when disposed. Sep 13, 2022
@mikes-gh mikes-gh mentioned this pull request Oct 22, 2022
6 tasks
@henon
Copy link
Contributor

henon commented Oct 23, 2022

The bug this PR fixes has already been fixed by #5562. Thus we are closing this PR. Nevertheless, thank you, all contributions are appreciated!

@henon henon closed this Oct 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Unexpected behavior or functionality not working as intended needs: changes A maintainer has asked for further modifications to be made to this pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JSDisconnectedException thrown by MudDrawer's Dispose when used in Blazor Server

5 participants