Description
When the decorate function is regenerated due to async state updates (e.g., from a debounced onChange or setTimeout), the editor loses track of the current caret position and it jumps to an incorrect location.
Recording

Sandbox
https://codesandbox.io/p/sandbox/nervous-dijkstra-djm6j7
Steps
- Place caret at end of text
- Type a word that matches decoration criteria (e.g., "there")
- Wait for async state update (2 seconds in example)
- Observe caret jumps to wrong position when decorations apply
Expectation
Caret should remain at current position.
Environment
- Slate Version: 0.120.0
- Operating System: MacOS Tahoe 26.1
- Browser: Chrome
Context
It is possible to work around in a very hackish way by storing the selection, then wait 10 ms (0 ms does not work) and then restore the selection to ensure slate rerenders correctly.
const selection = editor.selection
ReactEditor.deselect(editor)
setTimeout(() => {
if (selection) {
Transforms.select(editor, selection)
}
}, 10)
Description
When the
decoratefunction is regenerated due to async state updates (e.g., from a debounced onChange or setTimeout), the editor loses track of the current caret position and it jumps to an incorrect location.Recording

Sandbox
https://codesandbox.io/p/sandbox/nervous-dijkstra-djm6j7
Steps
Expectation
Caret should remain at current position.
Environment
Context
It is possible to work around in a very hackish way by storing the selection, then wait 10 ms (0 ms does not work) and then restore the selection to ensure slate rerenders correctly.