-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
[drag-drop] cdk-drag node is detached after element is dropped from one container to another #30506
Comments
I tried the component from the Stackblitz in our local dev app and I couldn't reproduce the leak on Chrome 133. I also don't think it would be particularly severe since the The context behind the |
@crisbeto Hello. How have you tried dragging items? Was it from container to container and not inside one? Because I can reproduce the issue in Chrome 133.0.6943.99 and Edge 133.0.3065.69.
The provided example is simple enough, but in my app, I have a lot of containers (including nested ones) that can consist of many complex components. Hence, if such a container is moved to another and a detached node is created - it can create memory leaks.
What things can break down? Can you specify what test covers it? Because I see only a test that checks if |
Yes, I tried a few times taking an item from "Todo" and dropping it into "Done" while passing over "In progress". The only detached nodes I saw were being retained by the Chrome dev tools, rather than anything in Angular or the CDK.
The |
Trying to remember: I think the |
@crisbeto What detached node retained by the Chrome dev tools are you talking about? Can you please share a screen with it? It's not the same as from my screens, yes? |
@crisbeto I've encountered such detached nodes before, but in my case, I have a reference to Also, my colleague tried to reproduce the issue and she has the same results as I. Maybe the reproduction can be related to OS? We are checking it on Windows. What about you? |
I'm checking it on a Mac with Chrome 133. |
We have some logic that registers and de-registers the items on create/destroy. That logic only syncs the item with the internal `DragRef` once the next dragging starts which means that we might retain a destroyed item if another drag doesn't start. These changes switch to always syncing the list when an item is removed. I've also added some context around why things are set up as they are right now since it took a while to remember the reasoning. Fixes angular#30506.
I've sent #30514 which should resolve it. |
…30514) We have some logic that registers and de-registers the items on create/destroy. That logic only syncs the item with the internal `DragRef` once the next dragging starts which means that we might retain a destroyed item if another drag doesn't start. These changes switch to always syncing the list when an item is removed. I've also added some context around why things are set up as they are right now since it took a while to remember the reasoning. Fixes #30506. (cherry picked from commit 26765a4)
Description
If the element is dropped from one container to another, a detached node is created because of
CdkDropList._dropListRef._draggables
.Reproduction
StackBlitz link: https://stackblitz.com/edit/stackblitz-starters-vygnusmw
Steps to reproduce:
Expected Behavior
There are no detached nodes related to the cdk-drag element.
Actual Behavior
There are 2
cdk-drag-dragging
detached nodes.The same result will be achieved if performed in Chrome, but more details can be seen in the Edge. If the "Analyze" button is clicked - you will get an id to the retainer (instead of the initial text "Object not found in memory anymore"). Double-clicking on it will show the retainer info. In this case, it's the
CdkDropList._dropListRef._draggables
array.Some info after my analysis:
_draggables
are set in theDropListRef
'swithItems
method.While debugging I should have entered it via
_syncItemsWithRef
, but there's athis._dropListRef.isDragging()
condition in theremoveItem
method. In my case, I've already dropped an item and it's no longer dragging. Therefore_draggables
are not updated and there's acdk-drag
detached node because of that.I'm not sure if that condition should be there at all, cause surely we need to sync items with ref not only when dragging is in progress. Here's a link to the commit where those changes were added.
For my project, I monkey-patched
removeItem
method and removedisDragging()
condition. For us, the case when an item should be removed while dragging is not relevant.Environment
The text was updated successfully, but these errors were encountered: