1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-09-03 12:12:39 +02:00

Avoid selection reconciliation on Android when there are pending changes

This commit is contained in:
Claudéric Demers
2023-02-21 22:41:34 +00:00
parent d0d1cb981b
commit a9da0eb6d1
2 changed files with 14 additions and 5 deletions

View File

@@ -0,0 +1,5 @@
---
'slate-react': patch
---
Fixed a bug on Android where Slate would attempt to reconcile the DOM selection with Slate's internal selection while there are pending diffs or while the pending diffs are being flushed, which could result in an error being thrown because of a mismatch between the state of the DOM and Slate's internal representation if they were out of sync.

View File

@@ -266,16 +266,20 @@ export const Editable = (props: EditableProps) => {
NODE_TO_ELEMENT.delete(editor)
}
if (
!ReactEditor.isFocused(editor) ||
androidInputManager?.hasPendingChanges() ||
androidInputManager?.isFlushing()
) {
return
}
// Make sure the DOM selection state is in sync.
const { selection } = editor
const root = ReactEditor.findDocumentOrShadowRoot(editor)
const domSelection = root.getSelection()
if (
!domSelection ||
!ReactEditor.isFocused(editor) ||
androidInputManager?.hasPendingAction()
) {
if (!domSelection) {
return
}