WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 90fbcde

Browse files
authored
fix: Prevent ReactEditor.toDOMRange crash in setDomSelection (#5741)
1 parent 644ebdc commit 90fbcde

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

.changeset/serious-eels-pay.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'slate-react': patch
3+
---
4+
5+
Fix ReactEditor.toDOMRange crash in setDomSelection

packages/slate-react/src/components/editable.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ export const Editable = forwardRef(
339339
const focusNode = domSelection.focusNode
340340
let anchorNode
341341

342-
// COMPAT: In firefox the normal seletion way does not work
342+
// COMPAT: In firefox the normal selection way does not work
343343
// (https://github.com/ianstormtaylor/slate/pull/5486#issue-1820720223)
344344
if (IS_FIREFOX && domSelection.rangeCount > 1) {
345345
const firstRange = domSelection.getRangeAt(0)
@@ -412,8 +412,13 @@ export const Editable = forwardRef(
412412
// Otherwise the DOM selection is out of sync, so update it.
413413
state.isUpdatingSelection = true
414414

415-
const newDomRange: DOMRange | null =
416-
selection && ReactEditor.toDOMRange(editor, selection)
415+
let newDomRange: DOMRange | null = null
416+
417+
try {
418+
newDomRange = selection && ReactEditor.toDOMRange(editor, selection)
419+
} catch (e) {
420+
// Ignore, dom and state might be out of sync
421+
}
417422

418423
if (newDomRange) {
419424
if (ReactEditor.isComposing(editor) && !IS_ANDROID) {

0 commit comments

Comments
 (0)