From f2ea1e1e3ae281cfef145b92a9cb61c7a749363d Mon Sep 17 00:00:00 2001 From: Raffael Date: Fri, 11 Jul 2025 01:31:24 +0200 Subject: [PATCH] Check if editor is still mounted before trying to focus (#5916) * Check if editor is still mounted before trying to focus * Add changeset --------- Co-authored-by: Raffael Wannenmacher --- .changeset/strong-humans-taste.md | 5 +++++ packages/slate-dom/src/plugin/dom-editor.ts | 6 ++++++ 2 files changed, 11 insertions(+) create mode 100644 .changeset/strong-humans-taste.md diff --git a/.changeset/strong-humans-taste.md b/.changeset/strong-humans-taste.md new file mode 100644 index 000000000..42983021c --- /dev/null +++ b/.changeset/strong-humans-taste.md @@ -0,0 +1,5 @@ +--- +'slate-dom': patch +--- + +Do not retry focusing editor after it has been unmounted diff --git a/packages/slate-dom/src/plugin/dom-editor.ts b/packages/slate-dom/src/plugin/dom-editor.ts index a44160b28..065d5da28 100644 --- a/packages/slate-dom/src/plugin/dom-editor.ts +++ b/packages/slate-dom/src/plugin/dom-editor.ts @@ -422,6 +422,12 @@ export const DOMEditor: DOMEditorInterface = { return } + // Return if no dom node is associated with the editor, which means the editor is not yet mounted + // or has been unmounted. This can happen especially, while retrying to focus the editor. + if (!EDITOR_TO_ELEMENT.get(editor)) { + return + } + // Retry setting focus if the editor has pending operations. // The DOM (selection) is unstable while changes are applied. // Retry until retries are exhausted or editor is focused.