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:
@@ -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
|
||||
|
Reference in New Issue
Block a user