{"record":{"id":"0ab9007e0bfd725a","repo":"ianstormtaylor/slate","slug":"cannot-resolve-a-slate-range-from-a-dom-event-e","errorCode":null,"errorMessage":"Cannot resolve a Slate range from a DOM event: ${event}","messagePattern":"Cannot resolve a Slate range from a DOM event: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/slate-dom/src/plugin/dom-editor.ts","lineNumber":322,"sourceCode":"    const el = DOMEditor.toDOMNode(editor, editor)\n    const root = el.getRootNode()\n\n    if (root instanceof Document || root instanceof ShadowRoot) {\n      return root\n    }\n\n    return el.ownerDocument\n  },\n\n  findEventRange: (editor, event) => {\n    if ('nativeEvent' in event) {\n      event = event.nativeEvent\n    }\n\n    const { clientX: x, clientY: y, target } = event\n\n    if (x == null || y == null) {\n      throw new Error(`Cannot resolve a Slate range from a DOM event: ${event}`)\n    }\n\n    const node = DOMEditor.toSlateNode(editor, event.target)\n    const path = DOMEditor.findPath(editor, node)\n\n    // If the drop target is inside a void node, move it into either the\n    // next or previous node, depending on which side the `x` and `y`\n    // coordinates are closest to.\n    if (Node.isElement(node) && Editor.isVoid(editor, node)) {\n      const rect = target.getBoundingClientRect()\n      const isPrev = editor.isInline(node)\n        ? x - rect.left < rect.left + rect.width - x\n        : y - rect.top < rect.top + rect.height - y\n\n      const edge = Editor.point(editor, path, {\n        edge: isPrev ? 'start' : 'end',\n      })\n      const point = isPrev","sourceCodeStart":304,"sourceCodeEnd":340,"githubUrl":"https://github.com/ianstormtaylor/slate/blob/72a37c701e5da4bb13a305d416d9c070d19d3a45/packages/slate-dom/src/plugin/dom-editor.ts#L304-L340","documentation":"Thrown by DOMEditor.findEventRange when a DOM event cannot be converted to a Slate range because it lacks clientX/clientY coordinates. Slate needs pointer coordinates to compute a DOM caret position from the event; without them no range can be resolved.","triggerScenarios":"Calling editor.findEventRange(event) (e.g. in a custom paste, drop, or context-menu handler) with an event that has no clientX/clientY — typically a synthesized/Polymer-wrapped event, a keyboard event, or an event whose nativeEvent was not passed.","commonSituations":"Passing a React synthetic event after it was pooled/nullified, passing a CustomEvent or keyboard event to findEventRange, or frameworks that wrap native events so clientX/clientY are undefined at read time.","solutions":["Ensure you pass a real pointer event (mousedown, mouseup, drop, contextmenu) with coordinates","If using React, pass the event synchronously before pooling or use event.nativeEvent yourself","If you only need the current selection, use editor.selection instead of findEventRange","For custom menus, capture coordinates at trigger time and construct the range manually with document.caretRangeFromPoint/caretPositionFromPoint"],"exampleFix":"// before\nconst range = DOMEditor.findEventRange(editor, someKeyboardEvent)\n// after\nconst range = editor.selection ?? DOMEditor.findEventRange(editor, pointerEvent)","handlingStrategy":"validation","validationCode":"const e = event.nativeEvent ?? event\nif (e.clientX == null || e.clientY == null) {\n  // not a resolvable pointer event; use current selection instead\n  return editor.selection\n}","typeGuard":"const isPointerLikeEvent = (e: any): e is MouseEvent =>\n  typeof e?.clientX === 'number' && typeof e?.clientY === 'number'","tryCatchPattern":"try { DOMEditor.findEventRange(editor, event) } catch (e) { if (e.message.includes('Cannot resolve a Slate range')) fallback to editor.selection; else throw e }","preventionTips":["Only pass pointer events (click/drop/contextmenu) to findEventRange","Destructure nativeEvent synchronously in React handlers","Avoid calling findEventRange from keyboard handlers"],"tags":["slate","dom","event","selection"],"backgroundTag":"dom-event-selection-resolution","analyzedSha":"72a37c701e5da4bb13a305d416d9c070d19d3a45","analyzedAt":"2026-08-27T23:04:51.145Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}