mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-29 18:09: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 => {
|
e.onChange = options => {
|
||||||
// COMPAT: React < 18 doesn't batch `setState` hook calls, which means
|
const onContextChange = EDITOR_TO_ON_CHANGE.get(e)
|
||||||
// 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()
|
|
||||||
|
|
||||||
maybeBatchUpdates(() => {
|
if (onContextChange) {
|
||||||
const onContextChange = EDITOR_TO_ON_CHANGE.get(e)
|
onContextChange(options)
|
||||||
|
}
|
||||||
|
|
||||||
if (onContextChange) {
|
onChange(options)
|
||||||
onContextChange(options)
|
|
||||||
}
|
|
||||||
|
|
||||||
onChange(options)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return e
|
return e
|
||||||
|
Reference in New Issue
Block a user