iTwin / viewer

Monorepo that contains the iTwin Viewer npm packages and their related packages
MIT License
24 stars 15 forks source link

Fix viewport context loss by changing event listener #316

Open hl662 opened 1 month ago

hl662 commented 1 month ago

When the window.location.href of the viewer tab is modified, but the link is not a valid one, we still see the viewport context disappear, because IModelApp.shutdown() is called beforeunload (i.e regardless of whether a user is redirected, or a tab is closed, or not). Changed the event listener to be a unload event, but this is not intended to be the long-term solution, because it is deprecated

I explored using the visibilitychanged event, but the problem with that is IModelApp will be shutdown when a user switches to a different tab. Checking the window.visiblityState and whether it is visible or hidden is the way to do it, but browsers aren't able to differentiate whether a hidden visibilityState is from the browser closing/refreshing a tab or because it is switched. So in conclusion, there is no good long term solution right now...

hl662 commented 1 month ago

Fixes https://github.com/iTwin/itwinjs-backlog/issues/1116

GerardasB commented 1 month ago

Long term we should still look into switching over to the visibility APIs for cleanup: