OnDetach will not be called on page reload
See original GitHub issueDescription of the bug
The documentation states
The onAttach() method is invoked when the Component has attached to the UI. Its counterpart, the onDetach() method, is invoked right before the component detaches from the UI. These are good points at which to reserve and release resources used by the component.
This is what I did. Sadly, the onDetach() method is not called if a user decides to reload the page. Thus, all resources acquired during onAttach() leak.
Expected behavior
onDetach() will always be called if the component is detached - regardless the reason.
Minimal reproducible example
public class TestClass extends Component {
@Override
protected void onAttach(AttachEvent attachEvent) {
super.onAttach(attachEvent);
System.out.println("Calling onAttach");
}
@Override
protected void onDetach(DetachEvent detachEvent) {
super.onDetach(detachEvent);
System.out.println("Calling onDetach");
}
}
Versions
- Vaadin / Flow version:
- Java version: kotlin with JDK 17
- OS version: Arch Linux (current)
- Browser version (if applicable): Firefox 97
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (6 by maintainers)
Top Results From Across the Web
Don't call onDisconnect() on page refresh in Firebase
Since onDisconnect() is a server side operation, and the connection to the server is severed any time a page is unloaded, the simple...
Read more >Fragment | Android Developers
A Fragment is closely tied to the Activity it is in, and can not be used apart from ... onDetach() called immediately prior...
Read more >chrome.tabs - Chrome Developers
Permissions. Most features do not require any permissions to use. For example: creating a new tab, reloading a tab, navigating to another URL,...
Read more >5 common mistakes when using Architecture Components
Fragments have tricky lifecycle and when a fragment gets detached and ... so onDestroy() is not called and DESTROYED state is not reached....
Read more >Handling Orientation Changes on Android - Medium
Android does this so that your application can reload resources based on the new ... Notice that Android does not call onCreate and...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
To be clear,
onDetach
is always called and the API contract is not broken. It is called way later than you would expect though (when the session expires).No matter if we call this enhancement or bug or anything else, I think it should be improved (fixed). For instance by integrating the mentioned cookbook recipe.
There is a workaround based on Beacon API documented at https://cookbook.vaadin.com/notice-closed.