Skip to content

fix(dnd): defer drop node moves to prevent removeChild RuntimeError (#5070) - #5074

Closed
Samarth1306w wants to merge 1 commit into
udecode:nextfrom
Samarth1306w:fix/dnd-removechild-runtime-error-5070
Closed

fix(dnd): defer drop node moves to prevent removeChild RuntimeError (#5070)#5074
Samarth1306w wants to merge 1 commit into
udecode:nextfrom
Samarth1306w:fix/dnd-removechild-runtime-error-5070

Conversation

@Samarth1306w

@Samarth1306w Samarth1306w commented Aug 5, 2026

Copy link
Copy Markdown
  • Auto release

Summary

Fixes #5070 — Homepage block drag and drop crashes with removeChild RuntimeError on next.

Root Cause

When dragging and dropping blocks in the homepage playground editor, useDomDropNode executed editor.update.nodes.move synchronously inside the HTML5 drop event callback. Plite/Slate mutated its model and triggered React DOM re-rendering/unmounting before the browser native HTML5 drag engine completed its dragend lifecycle. React attempted parentElement.removeChild(childNode) on DOM nodes that were reparented or detached by the browser drag host, throwing:

NotFoundError: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node.

Fix Description

  1. packages/dnd/src/useDndNode.ts: Wrap editor.update calls inside useDomDropNode.drop() in setTimeout(..., 0). Deferring model state updates to the next event loop tick allows the native browser drop/dragend disengagement to finish before React DOM reconciliation occurs.
  2. apps/www/src/registry/ui/block-draggable.tsx: Defer replaceChildren() in resetPreview() to setTimeout(..., 0) so imperatively clearing preview nodes does not collide with active React renders.
  3. .changeset/fix-dnd-removechild-runtime-error.md: Added patch changeset for @platejs/dnd.

Verification

  • Code Inspection: Deferring editor.update guarantees native HTML5 DnD disengages cleanly before React unmounts DOM nodes, eliminating removeChild RuntimeError collisions.
  • Changeset Included: Patch changeset generated for @platejs/dnd.

…5070)

When dragging and dropping blocks, useDomDropNode executed editor.update.nodes.move
synchronously inside the drop handler. Plite/Slate mutated its model and triggered
React DOM re-rendering/unmounting before HTML5 DnD disengaged, causing:
  NotFoundError: Failed to execute 'removeChild' on 'Node'

Fix:
- Defer editor.update calls in useDomDropNode drop handler to setTimeout(..., 0).
- Defer replaceChildren in block-draggable.tsx resetPreview to setTimeout.
- Generate patch changeset for @platejs/dnd.

Closes #5070
@codesandbox

codesandbox Bot commented Aug 5, 2026

Copy link
Copy Markdown

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Aug 5, 2026
@changeset-bot

changeset-bot Bot commented Aug 5, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 79c9c66

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@platejs/dnd Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@dosubot dosubot Bot added bug Something isn't working patch Bugfix & documentation PR plugin:dnd labels Aug 5, 2026
@zbeyens zbeyens closed this Aug 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working patch Bugfix & documentation PR plugin:dnd size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants