From c0ea6a62bc81e19d30431db4d68e484d298e10d8 Mon Sep 17 00:00:00 2001 From: Nikola Date: Mon, 23 Oct 2023 18:31:08 +0200 Subject: [PATCH] fix react batching workaround --- packages/slate-react/src/plugin/with-react.ts | 22 +++++-------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/packages/slate-react/src/plugin/with-react.ts b/packages/slate-react/src/plugin/with-react.ts index 395f208dd..63ece1af0 100644 --- a/packages/slate-react/src/plugin/with-react.ts +++ b/packages/slate-react/src/plugin/with-react.ts @@ -349,25 +349,13 @@ export const withReact = ( } e.onChange = options => { - // COMPAT: React < 18 doesn't batch `setState` hook calls, which means - // that the children and selection can get out of sync for one render - // pass. So we have to use this unstable API to ensure it batches them. - // (2019/12/03) - // https://github.com/facebook/react/issues/14259#issuecomment-439702367 - const maybeBatchUpdates = - REACT_MAJOR_VERSION < 18 - ? ReactDOM.unstable_batchedUpdates - : (callback: () => void) => callback() + const onContextChange = EDITOR_TO_ON_CHANGE.get(e) - maybeBatchUpdates(() => { - const onContextChange = EDITOR_TO_ON_CHANGE.get(e) + if (onContextChange) { + onContextChange(options) + } - if (onContextChange) { - onContextChange(options) - } - - onChange(options) - }) + onChange(options) } return e