.NET 6 Blazor server app not Disposing razor pages on browser tab close
See original GitHub issueIs there an existing issue for this?
- I have searched the existing issues
Describe the bug
When IDisposable is implemented in razor page and browser tab is closed by user, the Dispose method is called after few minutes and not immediately after tab close. The very first thing I’d mention is that disposing of razor pages worked correctly in .NET 5 so apparently it’s a bug in .NET 6 (or ASP.NET Core Runtime). Problem started to appear after I’ve upgraded my project to .NET 6.
This problem was discused previously in https://github.com/dotnet/aspnetcore/issues/38147 but solution in answer does not solve this problem - .NET knows about tab being closed but just do not call Dispose.
Expected Behavior
When browser tab is closed .NET should dispose all razor pages that existed in this session.
Steps To Reproduce
- Create Blazor server app according to https://dotnet.microsoft.com/en-us/learn/aspnet/blazor-tutorial/create
- Implement IDisposable in Counter.razor and set breakpoint in Dispose method
- Add HubFilter using
builder.Services.Configure<HubOptions>(O => O.AddFilter<HubFilter>());
and set breakpoint in OnDisconnectedAsync - Start app and navigate to /counter
- Close tab
- OnDisconnectedAsync is called but Dispose is not.
Exceptions (if any)
No response
.NET Version
6.0.101
Anything else?
No response
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
How to detect that a client closed the browser on Blazor ...
1 Answer 1 · 1. This only detects when user leaves the page. It cannot differ between a link click (changing page) or...
Read more >ASP.NET Core Blazor state management
Learn how to persist user data (state) in Blazor apps. ... The user might close and reopen their browser or reload the page,...
Read more >Dependency Injection Scopes in Blazor
Coming from ASP.NET Core, it seems that the dependency injection scope in Blazor works differently. This article shows why this is the case....
Read more >Blazor's New LocationChanging Events in .NET 7
It's worth knowing the limitations of the LocationChanging event—the main one being that it doesn't always fire when you might want/need it to....
Read more >Guide to Blazor JavaScript Interop - Imaginet Blog
Learn how to use Blazor JavaScript Interop to make JavaScript and .NET code interact seamlessly. Get up and running quickly with step-by-step..
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I studied problem further and it looks like problem appear in Vivaldi and Firefox but not in Google Chrome. So it’s somehow browser issue.
This issue has been resolved and has not had any activity for 1 day. It will be closed for housekeeping purposes.
See our Issue Management Policies for more information.