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

bug(drag-drop): Failed to execute insertBefore on Node #29358

Open
1 task
SebastianPodgajny opened this issue Jul 1, 2024 · 1 comment
Open
1 task

bug(drag-drop): Failed to execute insertBefore on Node #29358

SebastianPodgajny opened this issue Jul 1, 2024 · 1 comment
Labels
area: cdk/drag-drop P4 A relatively minor issue that is not relevant to core functions

Comments

@SebastianPodgajny
Copy link

SebastianPodgajny commented Jul 1, 2024

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

When drag and drop is used and data refreshes in background this error can be thrown

ERROR DOMException: Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node.

Reproduction

StackBlitz link: https://stackblitz.com/edit/a9tq3w?file=src%2Fexample%2Fcdk-drag-drop-connected-sorting-example.html
Steps to reproduce:

  1. Keep moving first element to the bottom (fast)

Expected Behavior

Drag and drop should not cause DOMException

Actual Behavior

Screen.Recording.2024-07-01.at.16.25.46.mp4
Screen.Recording.2024-07-01.at.16.26.19.mp4
ERROR DOMException: Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node.
    at EmulatedEncapsulationDomRenderer2.insertBefore (/vendor.js:84094:20)
    at BaseAnimationRenderer.insertBefore (/vendor.js:17733:19)
    at nativeInsertBefore (/vendor.js:50345:12)
    at applyToElementOrContainer (/vendor.js:49879:7)
    at applyNodes (/vendor.js:50571:9)
    at applyView (/vendor.js:50578:3)
    at addViewToDOM (/vendor.js:49947:3)
    at addLViewToLContainer (/vendor.js:52300:7)
    at LiveCollectionLContainerImpl.attach (/vendor.js:63156:5)
    at LiveCollectionLContainerImpl.swap (/vendor.js:62667:12)

Environment

Angular CLI: 18.0.2
Node: 18.20.3
Package Manager: yarn 1.22.19
OS: linux x64

Angular: 18.0.1
... animations, common, compiler, compiler-cli, core, forms
... localize, platform-browser, platform-browser-dynamic, router

Package Version

@angular-devkit/architect 0.1800.2
@angular-devkit/build-angular 18.0.2
@angular-devkit/core 18.0.2
@angular-devkit/schematics 18.0.2
@angular/cdk 18.0.5
@angular/cli 18.0.2
@angular/material 18.0.5
@angular/material-experimental 18.0.5
@angular/material-moment-adapter 18.0.5
@schematics/angular 18.0.2
rxjs 7.4.0
typescript 5.4.5
zone.js 0.14.6

@SebastianPodgajny SebastianPodgajny added the needs triage This issue needs to be triaged by the team label Jul 1, 2024
@crisbeto
Copy link
Member

crisbeto commented Jul 2, 2024

I spent a bit of time investigating it. The problem is that we need to insert some elements while the dragging is happening (e.g. the placeholder and the preview) which get cleaned up once it's done, but in this case @for is trying to re-render while those elements are still there. Normally we have some backup logic in place which will do the cleanup if the dragged element is destroyed, but that doesn't happen here because @for tries to reuse the element rather than destroy it. There isn't an API that we can use to be notified when something like this has happened.

I'm setting a lower priority on this, because it's a bit of an edge case and in general it's not recommended to change the data while the user is dragging since they might not notice what's going on.

@crisbeto crisbeto added P4 A relatively minor issue that is not relevant to core functions area: cdk/drag-drop and removed needs triage This issue needs to be triaged by the team labels Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: cdk/drag-drop P4 A relatively minor issue that is not relevant to core functions
Projects
None yet
Development

No branches or pull requests

2 participants