{"record":{"id":"f36ab11b09b962b9","repo":"ianstormtaylor/slate","slug":"unable-to-find-a-host-window-element-for-this-edit","errorCode":null,"errorMessage":"Unable to find a host window element for this editor","messagePattern":"Unable to find a host window element for this editor","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/slate-dom/src/plugin/dom-editor.ts","lineNumber":471,"sourceCode":"        const domRange = DOMEditor.toDOMRange(editor, editor.selection)\n        domSelection?.removeAllRanges()\n        domSelection?.addRange(domRange)\n      }\n      // Create a new selection in the top of the document if missing\n      if (!editor.selection) {\n        Transforms.select(editor, Editor.start(editor, []))\n      }\n      // IS_FOCUSED should be set before calling el.focus() to ensure that\n      // FocusedContext is updated to the correct value\n      IS_FOCUSED.set(editor, true)\n      el.focus({ preventScroll: true })\n    }\n  },\n\n  getWindow: editor => {\n    const window = EDITOR_TO_WINDOW.get(editor)\n    if (!window) {\n      throw new Error('Unable to find a host window element for this editor')\n    }\n    return window\n  },\n\n  hasDOMNode: (editor, target, options = {}) => {\n    const { editable = false } = options\n    const editorEl = DOMEditor.toDOMNode(editor, editor)\n    let targetEl\n\n    // COMPAT: In Firefox, reading `target.nodeType` will throw an error if\n    // target is originating from an internal \"restricted\" element (e.g. a\n    // stepper arrow on a number input). (2018/05/04)\n    // https://github.com/ianstormtaylor/slate/issues/1819\n    try {\n      targetEl = (\n        isDOMElement(target) ? target : target.parentElement\n      ) as HTMLElement\n    } catch (err) {","sourceCodeStart":453,"sourceCodeEnd":489,"githubUrl":"https://github.com/ianstormtaylor/slate/blob/72a37c701e5da4bb13a305d416d9c070d19d3a45/packages/slate-dom/src/plugin/dom-editor.ts#L453-L489","documentation":"Thrown by DOMEditor.getWindow when the editor has no registered host window, i.e. the EDITOR_TO_WINDOW WeakMap entry was never set by attaching the editor to DOM withEditable/withDOM. It means DOM-specific APIs are being used on an editor that was never bound to the DOM layer.","triggerScenarios":"Calling editor.getWindow(), hasSelectableTarget, or other DOM helpers on an editor created with createEditor() instead of withDOM(withReact(createEditor())), or calling them before the editable component mounted.","commonSituations":"Using slate-dom utilities in Node/SSR or in unit tests without mounting <Editable>; creating a standalone editor for data manipulation but accidentally calling DOM APIs; import order causing withDOM to be skipped.","solutions":["Create the editor with DOMEditor.withDOM (usually via withReact from slate-react)","Only call DOM helpers after the <Editable> component has mounted","In SSR/tests, guard window-dependent calls behind a mounted check","For pure data manipulation, use slate core APIs (Node, Transforms) instead of DOMEditor"],"exampleFix":"// before\nconst editor = createEditor()\nconst win = DOMEditor.getWindow(editor)\n// after\nconst editor = withDOM(withReact(createEditor()))\n// after <Editable> mounted:\nconst win = DOMEditor.getWindow(editor)","handlingStrategy":"validation","validationCode":"const editor = withDOM(withReact(createEditor()))\n// and only after <Editable> mounts:\nif (EDITOR_TO_WINDOW.get(editor)) { /* safe to use DOM APIs */ }","typeGuard":"const isDOMAttached = (editor: Editor): boolean =>\n  EDITOR_TO_WINDOW.has(editor) // or track a mounted flag in your own state","tryCatchPattern":"try { DOMEditor.getWindow(editor) } catch (e) { if (/host window/.test(e.message)) skip DOM-specific logic; else throw e }","preventionTips":["Always construct editors with withReact/withDOM","Guard window access in SSR or non-DOM tests","Mount <Editable> before using DOM helpers"],"tags":["slate","window","ssr","editor-setup"],"backgroundTag":"editor-not-attached-to-dom","analyzedSha":"72a37c701e5da4bb13a305d416d9c070d19d3a45","analyzedAt":"2026-08-27T23:04:51.145Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}