Use of window.name from ExtendedClientDetails

Vaadin 14 API states “ExtendedClientDetails window.name” although public, is marked as internal use only.

Is there a reason it cannot be used externally?

This seems to be the only way to be sure you are always relating to the same browser tab, or is there another way?

Using the method externally is fine. But observe that 1) the actual value is internal and no assumptions should be made about it; and 2) the method has been exposed primarily to support the @PreserveOnRefresh feature. For keeping the state of components between refreshes, we recommend using that feature rather than accessing ExtendedClientDetails::getWindowName directly.

Thanks Johannes,

The problem I am trying to solve is how and where to keep data related to a browser tab.

As the UI is changing all the time it cannot be kept with the UI.

Reading the info about @PreserveOnRefresh it seems that any of the views used in the tab, perhaps a main layout could be used.

If this is the case how then could the data be cleared or handled after the tab is closed?

Yes, the data can be stored in any of the components in the preserved view. There is no built-in feature in the framework to have data cleared once a tab is closed ([open ticket]
(https://github.com/vaadin/flow/issues/8399)). In fact, all preserved components are stored in the session and will be disposed only when the session expires. A solution may be to use the onbeforeunload event together with a @ClientCallable server method (see e.g. https://vaadin.com/forum/thread/17845554/executejs-with-onbeforeunload-or-similar-events) to dispose the data one when the browser is closed. Since the event also triggers on refreshes, the disposal action would need to be delayed until the server has verified that the same view is no long refreshed.

Thanks Again, Johannes,

I have tried the onbeforeunload method without success but will try again.

Detection of browser tab close is an area of flow that needs some love but from the open ticket it appears to be a very difficult problem to solve.

Related to @PreserveOnRefresh in Vaadin 14 docs https://vaadin.com/docs/v14/flow/advanced/tutorial-preserving-state-on-refresh.html Denis Anisimov provides some very worthwhile info in reponse to a question by Gabe Merton.

Paul Fraser:
I have tried the onbeforeunload method without success but will try again.

Detection of browser tab close is an area of flow that needs some love but from the open ticket it appears to be a very difficult problem to solve.

Maybe you can find some information on this topic: https://vaadin.com/forum/thread/17523194/unsaved-changes-detect-page-exit-or-reload

Jean-Christophe,

How come I have not heard about this fantastic resource through other channels?

It seems to be targeted at V17 but an indication in the code as it’s suitability for V14 would be handy although in most cases it is self evident.

Also as I am 100% OSGi/Vaadin 14 there are some other challenges until the Vaadin OSgi act is completed later this year.

Thanks for the link.

Paul