Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onDetach() is not called after page closed and hearbeats stopped, even for a long time #14241

Closed
bardyamomeni opened this issue Jul 30, 2022 · 5 comments

Comments

@bardyamomeni
Copy link

bardyamomeni commented Jul 30, 2022

Description of the bug

When a page is closed, heartbeats stop, but the UI is not destroyed and detached, even after a long time.

Expected behavior

the UI should get detached after a finite amount of time after the last heartbeat

Minimal reproducible example

class UiServletInitListener : VaadinServiceInitListener {
    
     override fun serviceInit(serviceInitEvent: ServiceInitEvent) {
        
           serviceInitEvent.source.addUIInitListener { e: UIInitEvent ->
                e.ui.addHeartbeatListener {
                   println("HEARTBEAT ${it.heartbeatTime}")
                }
               e.ui.addDetachListener {
                   println("DETACHED") //never gets called. even after 10x times heartbeat interval later of the last heartbeat
                }
        }
    }
}

Versions

  • Vaadin / Flow version: 23.1.3
  • Java version: 17
  • OS version: macOS 12
  • Browser version (if applicable): Firefox
  • Application Server (if applicable): Spring Boot 2.7.2 + rsocket + vaadin
  • IDE (if applicable): IntelliJ IDEA
@taefi
Copy link
Contributor

taefi commented Aug 2, 2022

@bardyamomeni thanks for creating this issue. If "when a page is closed" means closing the browser's tab, I think this might not be exactly a bug, but more of an enhancement request since currently the support for this is not implemented yet, similar to #6293 and #13221. If this is about other circumstances or a regression, please elaborate more.

@bardyamomeni
Copy link
Author

bardyamomeni commented Aug 2, 2022

@taefi
Hi Soroosh,
Thank you for your comment.

What I think about sessions and UI's is that UI's could attach to a session and can be destroyed before the Vaadin session expires, so they could get detached sooner by an event like closing the browser tab.

Currently I am attaching a RSocket connection to my main UI, so I want it to get destroyed when user closes the browser tab as soon as possible (maybe 3x or 4x times the heartbeat interval).

The workaround for this is to set the session timeout to a small value like 30 seconds (for my usecase) to force the session and its UI's to detach and destroy.

@taefi
Copy link
Contributor

taefi commented Aug 2, 2022

Another workaround (before the functionality is added officially to the platform) can be something like: https://cookbook.vaadin.com/notice-closed to take control of what should happen when the user closes a browser tab. Note that the unload event on the browser gets fired as well when the user refreshes the page.

@bardyamomeni
Copy link
Author

Thanks Soroosh, I will take a look at the link.
🤟🏼

@mshabarov
Copy link
Contributor

@bardyamomeni this has been fixed in Vaadin 24.1.0.alpha4 by implementing #6293. Now when you close a tab in browser or refresh a page, onDetach listener is called immediately. I close this ticket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants