Open aley2003 opened 1 year ago
In Vaadin 8 beforeLeave() was working reliable.
As leaving the View by closing the browser tab or similar is not under the control of Vaadin, this would probably not work with a BeforeLeaveObserver.
There is an old thread about this topic: https://vaadin.com/forum/thread/17523194/unsaved-changes-detect-page-exit-or-reload We more or less do what's described there.
BUT it would be great if Vaadin would support that out of the box.
In Vaadin 8 beforeLeave() was working reliable.
That is not true. It is working the same as in V8. If you call window.open("http://www.google.de", "_self");
in a V8 app / view with a before leave observer is also not called.
But in V8 beforeLeave() was triggered by a change in the application URL (e.g. https://my-server/myApp/view1 to https://my-server/myApp/view2) at least.
Description of the bug
From https://vaadin.com/docs/latest/routing/lifecycle: "A typical use case for this event is to ask the user whether they want to save any unsaved changes before navigating to another part of the application." For this use case the BeforeLeaveObserver is not usable because of (from interface BeforeLeaveObserver): "If a route target is left for reasons not under the control of the navigator (for instance using Page.setLocation(URI), typing a URL into the address bar, or closing the browser), listeners are not called." So the observer is not called reliable and there are many cases the view could be left without saving changes.
Expected behavior
BeforeLeaveObserver.beforeLeave should be called in any case before a View would be left.
Minimal reproducible example
Every view implementing BeforeLeaveObserver
Versions