docs/solutions/ui-bugs/2026-04-23-slate-mentions-portal-positioning-must-fail-closed-on-transient-dom-range-gaps.md
The mentions example can compute a valid model target while the matching DOM
node is not yet resolvable. Positioning the portal with ReactEditor.toDOMRange
must not crash the whole example during that transient gap.
mentions example › shows list of mentions failed because the portal count
stayed 0.Cannot resolve a DOM node from Slate node.editor.selection to Editor.getLiveSelection
was correct but not sufficient.Make portal positioning fail closed:
let domRange: globalThis.Range
try {
domRange = ReactEditor.toDOMRange(editor, target)
} catch {
return
}
Also make the test select the intended mention insertion point and place the DOM selection, not just the model selection.
Autocomplete state is model-owned, but portal placement is DOM-owned. During text insertion React can temporarily lack a DOM node for the exact target range. Failing closed keeps the portal state alive and lets the next stable render position it instead of crashing the example.
ReactEditor.toDOMRange should tolerate transient
DOM bridge gaps.