Fix position bounds check in updateDraggedNode #190
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix-update-dragged-node-bounds-check"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
When a document changes size during a drag operation (e.g. via collaborative editing or an external state update), the stored node selection position (
sel.from) can exceed the new document's content size. Callingdoc.nodeAt()with an out-of-range position causesFragment.findIndexto throw:This crash originates in
updateDraggedNode(called fromupdateStateInner) wherethis.state.doc.nodeAt(sel.from)is called without verifying thatsel.fromis within the document's valid range.Reproduction
This occurs in collaborative editing environments where:
updateStateInneris called with the new stateupdateDraggedNodetries to look up the dragged node at the original position, which is now out of rangeWe've observed this affecting ~161 events across 7 users in our production collaborative editor (Dovetail, built on ProseMirror with Yjs).
Fix
Added bounds checks before both
nodeAtcalls inupdateDraggedNode:And similarly for the
movedPosfallback path.When the position is out of range, the method correctly falls through to
found = -1, which setsthis.dragging.nodetoundefined— the existing behavior for when the dragged node can't be found.Version
Tested against
prosemirror-view@1.32.7but the same code exists onmaster.Firstly, you reformatted the entire file. You're going to want to submit a patch with only the actual changes you made.
Secondly, can you confirm that you did not use AI to generate this patch?
Closing to resubmit with only the bug fix - apologies for the reformatting.
Pull request closed