ianstormtaylor / slate

A completely customizable framework for building rich text editors. (Currently in beta.)
http://slatejs.org
MIT License
29.79k stars 3.24k forks source link

insertText after addMark/removeMark will carsh #3708

Open akiwong-cn opened 4 years ago

akiwong-cn commented 4 years ago

Do you want to request a feature or report a bug?

bug

What's the current behavior?

insertText after addMark or removeMark in a React event handler, the editor will crash

editor

code example: https://codesandbox.io/s/slate-addmark-leggp

Slate: 0.58.1 Browser: Chrome OS: Mac

What's the expected behavior?

It may be caused by addMark function call editor.onChange sync and apply function call it in a microtask. conflict with lazy state update in React synthetic events https://github.com/ianstormtaylor/slate/blob/master/packages/slate/src/create-editor.ts#L109

flakekun commented 3 years ago

I'm experiencing the same crash behavior but in a different environment. It almost never happens in Chrome 87, but always happening in Firefox 83 (both on Mac and Windows).

Xheldon commented 3 years ago

you can use requestAnimationFrame to fix this error, just put the insertText in requestAnimationFrame callback.