Skip to content

Commit

Permalink
Revert "fix react batching workaround"
Browse files Browse the repository at this point in the history
This reverts commit c0ea6a6.
  • Loading branch information
Nikola-Bijelic committed Oct 23, 2023
1 parent 25e514e commit 1a0e65d
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions packages/slate-react/src/plugin/with-react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,13 +349,25 @@ export const withReact = <T extends BaseEditor>(
}

e.onChange = options => {
const onContextChange = EDITOR_TO_ON_CHANGE.get(e)

if (onContextChange) {
onContextChange(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()

maybeBatchUpdates(() => {
const onContextChange = EDITOR_TO_ON_CHANGE.get(e)

if (onContextChange) {
onContextChange(options)
}

onChange(options)
onChange(options)
})
}

return e
Expand Down

0 comments on commit 1a0e65d

Please sign in to comment.