Fix position bounds check in updateDraggedNode #191

Merged
dougrathbone merged 1 commit from fix-update-dragged-node-bounds-check-v2 into master 2026-03-18 10:19:15 +01:00
dougrathbone commented 2026-03-17 21:25:33 +01:00 (Migrated from github.com)

When a document changes size during a drag operation (e.g. via collaborative editing), the stored node selection position (sel.from) can exceed the new document's content size. Calling doc.nodeAt() with an out-of-range position causes Fragment.findIndex to throw:

RangeError: Position X outside of fragment (...)

This adds bounds checks before both nodeAt calls in updateDraggedNode. When the position is out of range, the method falls through to found = -1, which already correctly sets this.dragging.node to undefined.

We've observed this crash in our production collaborative editor (Dovetail, using ProseMirror + Yjs)

Apologies for the formatting noise on the previous PR (#190)

When a document changes size during a drag operation (e.g. via collaborative editing), the stored node selection position (`sel.from`) can exceed the new document's content size. Calling `doc.nodeAt()` with an out-of-range position causes `Fragment.findIndex` to throw: ``` RangeError: Position X outside of fragment (...) ``` This adds bounds checks before both `nodeAt` calls in `updateDraggedNode`. When the position is out of range, the method falls through to `found = -1`, which already correctly sets `this.dragging.node` to `undefined`. We've observed this crash in our production collaborative editor (Dovetail, using ProseMirror + Yjs) Apologies for the formatting noise on the previous PR (#190)
marijnh commented 2026-03-18 10:19:33 +01:00 (Migrated from github.com)

Thanks, looks much better.

Thanks, looks much better.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
prosemirror/prosemirror-view!191
No description provided.