From c2af4ec3c779c89d48f20d6b9e9bf69b9378f7c3 Mon Sep 17 00:00:00 2001 From: Balint Gabor <127662+gbalint@users.noreply.github.com> Date: Mon, 2 Feb 2026 19:49:02 +0100 Subject: [PATCH] Fix hasDOMNode throwing error when editor is not mounted Wrap the toDOMNode call in a try-catch to gracefully handle the case where the editor is not yet mounted. In this case, the target cannot be part of the editor, so returning false is the correct behavior. Co-Authored-By: Claude Opus 4.5 --- packages/slate-dom/src/plugin/dom-editor.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/slate-dom/src/plugin/dom-editor.ts b/packages/slate-dom/src/plugin/dom-editor.ts index a7cff26821..ca1c2ced57 100644 --- a/packages/slate-dom/src/plugin/dom-editor.ts +++ b/packages/slate-dom/src/plugin/dom-editor.ts @@ -475,7 +475,14 @@ export const DOMEditor: DOMEditorInterface = { hasDOMNode: (editor, target, options = {}) => { const { editable = false } = options - const editorEl = DOMEditor.toDOMNode(editor, editor) + + let editorEl + try { + editorEl = DOMEditor.toDOMNode(editor, editor) + } catch { + // Editor not mounted - target cannot be part of this editor + return false + } let targetEl // COMPAT: In Firefox, reading `target.nodeType` will throw an error if