dsuryd/dotNetify

connection disconnected with chrome tab inactive or chrome minimized

giuz78 opened this issue · 3 comments

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

This is a SignalR issue with the Chrome tab freeze feature. Read here: dotnet/aspnetcore#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.

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?

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.