Skip to content

Commit f2ea1e1

Browse files
delijahRaffael Wannenmacher
andauthored
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 <raffael.wannenmacher@tx.group>
1 parent ef76eb4 commit f2ea1e1

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

.changeset/strong-humans-taste.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'slate-dom': patch
3+
---
4+
5+
Do not retry focusing editor after it has been unmounted

packages/slate-dom/src/plugin/dom-editor.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,12 @@ export const DOMEditor: DOMEditorInterface = {
422422
return
423423
}
424424

425+
// Return if no dom node is associated with the editor, which means the editor is not yet mounted
426+
// or has been unmounted. This can happen especially, while retrying to focus the editor.
427+
if (!EDITOR_TO_ELEMENT.get(editor)) {
428+
return
429+
}
430+
425431
// Retry setting focus if the editor has pending operations.
426432
// The DOM (selection) is unstable while changes are applied.
427433
// Retry until retries are exhausted or editor is focused.

0 commit comments

Comments
 (0)