-
Notifications
You must be signed in to change notification settings - Fork 161
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
Add flag to tell if DetachEvent happened because of resynchronization #18443
Comments
I don't think "resynchronization" is the correct semantic in this case since the same pattern with detaching and immediately re-attaching a whole component tree does also happen with Maybe "temporary" or "intermediate" would be more suitable? |
There is actually some sort of API for this. When resynchronization is happening, the same UI instance is re-attached, hence UI is not closing. So you can use UI#isClosing() as a flag, i.e. if it is true then detach is not due resynchronization or refresh (in case @PreserceOnRefresh). Do we need additional convenience API or just document this better? |
Looks similar to #18414. |
The trick of looking at |
This suggested solution would work for #18414 |
For us it's relevant because even though our resources are tied to the UI life cycle as well, they often only provide an API for releasing them permanently, which means they cannot be reacquired in onAttach afterwards. We thought this should work as long as we don't reattach a component to the UI after it has been removed, but due to resynchronization, these reattachments can happen out of the blue. In this sense, some Flag on the detach event would help us the understand whether this is "the final" detach, so we can decide whether to release these resources or not. |
@mperktold Did you look into using |
I haven't actually tried it, but as you said yourself, it doesn't work for components other than the UI itself, since they can be detached when navigating to another view. We did find another workaround for the NPEs, namely to remove the problematic components from the DOM tree on detach. If the detach is due to resynchronization, these components will only be detached but not reattached, because they won't belong to the DOM anymore. And if the detach is because of some navigation, removing these components won't have any noticable effect. |
@mperktold There is no need, you can get UI via event. I add here just example code to demonstrate that use of the proposed method is really simple
|
But it's the same for normal navigation to other views: the given component will be detached, whereas the UI will not be closing. You can't differentiate those cases using this pattern, and I would need to differentiate, because for normal navigation (or generally, the "last detach" for this component instance), I need to cleanup resources, whereas for resync I don't. |
The only difference between the two scenarios is that for resynchronization, the UI will be detached as well, whereas for normal navigation it won't. This fact doesn't help us, however, since UI will be detached last, so inside |
@mperktold Thanks for spotting silly mistake, I corrected the code and tested it works with preserve on refresh. |
Checking the number of children of the UI is an interesting idea. However, it never returns 0 for me, neither for resync, nor for normal navigation, nor for closing the tab/refresh. |
I did not test the resync case, with PreserveOnRefresh it works
In these cases it should not, that was exactly the point. |
It seems that when resync is done UI is detached after component is detached, but when preserve on refresh is done, it is not done.
|
To be fair, I tested resync by faking a resync request in my debugger, i.e. adding I don't think the behavior would be different for a "real" resync request, though. |
There is method in UI internals to trigger server initiated resync, which we use in our integration testing
|
Describe your motivation
In the case of resynchronization, the UI is detached and reattached. This causes the detach events to fire. In use cases where expensive resources are acquired on attach and released on detach, it would be useful to know that the detach happens because of resynchronization, meaning that it can be expected to see reattaching happen soon (and releasing the resources isn't necessary).
Describe the solution you'd like
The DetachEvent could contain a flag (such as
resynchronization
) that tells if the detach happened due to resynchronization or not.Describe alternatives you've considered
If this information would be available elsewhere, such as the current Request, that could work too.
Additional context
The text was updated successfully, but these errors were encountered: