Fix null dereference in updateOverlay when after-node uses a custom NodeView #23
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "nosooqua/prosemirror-dropcursor:fix/updateoverlay-null-nodedom-after-node"
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?
nodeDOM() can return null for nodes rendered with custom NodeViews (e.g.
React-based). The existing null check on line 89 guards the before-node,
but the after-node lookup inside
if (before && after)was unguarded.nodeDOMcan return null when pointed at a text node, at a position where there is no node, or at a position inside an opaque node's inner structure. This code runs only for block positions, so a text node isn't possible. The fact thatafteris non-null means that there is a node there, and the fact that the node before has a representation means that we're not inside an opaque node.So theoretically this is not a thing that can happen. Did you run into it? What do you mean by 'React-based node views'? Those will also have an outer node, and should not affect
nodeDOM.We found the root cause — it was indeed a bug in our implementation. A transaction was being dispatched synchronously during a NodeView’s initialization (during a drag-and-drop remount), which caused the DOM state to be inconsistent.
However, I’d still suggest adding a null guard for nodeDOM. Currently, the as HTMLElement cast bypasses TypeScript's safety, and if the DOM tree is temporarily out of sync, it leads to a hard crash. Falling back to the coordsAtPos logic instead of crashing would make the editor much more resilient to such edge cases.
I prefer not to insert checks that paper over issues that originate elsewhere like that. I feel it's generally better to have a crash point you towards a bug than to have it silently sit there.
Pull request closed