Skip to content

Commit

Permalink
fix(lexical-editor): call onChange with a small timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel910 committed Jul 23, 2024
1 parent 5d0f987 commit bcac0a9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ const BaseRichTextEditor = ({
editorState.read(() => {
if (typeof onChange === "function") {
const editorState = editor.getEditorState();
onChange(JSON.stringify(editorState.toJSON()));
// The timeout is necessary to prevent the `flushSync` warning by React.
setTimeout(() => {
onChange(JSON.stringify(editorState.toJSON()));
}, 0);
}
});
}
Expand Down
2 changes: 2 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -18556,9 +18556,11 @@ __metadata:
apollo-link-http-common: ^0.2.16
apollo-utilities: ^1.3.4
boolean: ^3.0.1
bytes: ^3.0.0
graphql: ^15.7.2
invariant: ^2.2.4
lodash: ^4.17.21
minimatch: ^5.1.0
nanoid: ^3.3.7
react: 18.2.0
react-dom: 18.2.0
Expand Down

0 comments on commit bcac0a9

Please sign in to comment.