1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-28 09:29:49 +02:00

fix react batching workaround

This commit is contained in:
Nikola
2023-10-23 18:31:08 +02:00
parent a77692047f
commit c0ea6a62bc

View File

@@ -349,25 +349,13 @@ export const withReact = <T extends BaseEditor>(
}
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