dsuryd / dotNetify

Simple, lightweight, yet powerful way to build real-time web apps.
https://dotnetify.net
Other
1.17k stars 164 forks source link

connection disconnected with chrome tab inactive or chrome minimized #300

Closed giuz78 closed 2 years ago

giuz78 commented 3 years ago

In my project i have disconnection problems and it seems that happen when chrome tab is inactive or when chrome is minimized for some minutes, this results in a loss of state of the VM.

i can notice the same problem using your example simple list , if i minimize chrome or if i move to another tab when i come back later i see that i lose all the informations I added to the grid.

in console i can see disconnection log message: Information: Connection disconnected.

is there any way to avoid this problem?

thanks regards

dsuryd commented 3 years ago

This is a SignalR issue with the Chrome tab freeze feature. Read here: https://github.com/dotnet/aspnetcore/issues/33970. I was able to reproduce the inactive tab disconnection, but as soon as the tab is active, automatic reconnection occurs. Avoid losing information by persisting user data on the server.

giuz78 commented 2 years ago

Thanks , after reading your link i found this https://docs.microsoft.com/en-us/aspnet/core/signalr/javascript-client?view=aspnetcore-3.1#bsleep ,I haven't tried it yet, do you think it might be a solution? If not , how i can persist user data on server? i cannot use dotnetify connection id to identify on server the same user with inactive tab because when the tab come back active reconnection occurs but with a new id. could be by generating a unique id on the client side to use and pass to the server in initial state of connection?

dsuryd commented 2 years ago

I think it's worth a try! You're correct that you cannot rely on (SignalR) connection Id as it will change with every reconnection, so maintain your own Id scheme, or perhaps another way is to persist user state on browser's local/session storage and on reconnecting, send the state to the server to initialize the new view model instance.