Skip to content

Commit ea37993

Browse files
fix(slate-dom): propagate suppressThrow to toSlateNode in toSlatePoint (#6072)
* fix(slate-dom): propagate suppressThrow through toSlateNode in toSlatePoint When toSlatePoint is called with suppressThrow: true, errors thrown by toSlateNode were not being suppressed — only errors from findPath were handled. Wrap the toSlateNode call in the same try/catch pattern already used for findPath. This is the gap left by PR #6004 which guarded findPath but not the preceding toSlateNode call. * chore: add changeset for toSlatePoint suppressThrow fix * Prettier fix
1 parent c5ea32e commit ea37993

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

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+
Fix `toSlatePoint` not respecting `suppressThrow` when `toSlateNode` throws. Only errors from `findPath` were guarded; errors from the preceding `toSlateNode` propagated unconditionally even with `suppressThrow: true`.

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,15 @@ export const DOMEditor: DOMEditorInterface = {
920920
// COMPAT: If someone is clicking from one Slate editor into another,
921921
// the select event fires twice, once for the old editor's `element`
922922
// first, and then afterwards for the correct `element`. (2017/03/03)
923-
const slateNode = DOMEditor.toSlateNode(editor, textNode!)
923+
let slateNode
924+
try {
925+
slateNode = DOMEditor.toSlateNode(editor, textNode!)
926+
} catch (e) {
927+
if (suppressThrow) {
928+
return null as T extends true ? Point | null : Point
929+
}
930+
throw e
931+
}
924932
let path
925933
try {
926934
path = DOMEditor.findPath(editor, slateNode)

0 commit comments

Comments
 (0)