Description
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:
- Download the project from StackBlitz.
- Start it and open in the Edge browser. Open the deprecated "Detached elements" tool.
- Drag an item from the "To do" column to the "In progress" column and then to "Done".
- Collect garbage in the "Detached elements" tool and check detached items.
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 the DropListRef
's withItems
method.
While debugging I should have entered it via _syncItemsWithRef
, but there's a this._dropListRef.isDragging()
condition in the removeItem
method. In my case, I've already dropped an item and it's no longer dragging. Therefore _draggables
are not updated and there's a cdk-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 removed isDragging()
condition. For us, the case when an item should be removed while dragging is not relevant.
Environment
- Angular: 19.0.6
- CDK/Material: 19.0.0
- Browser(s): Chrome/Edge
- Operating System (e.g. Windows, macOS, Ubuntu): Windows 11 Pro