Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix modifying state during onChange triggered by beforeinput (faceboo…
…karchive#667) Fixes facebookarchive#92. If an onChange handler replaces every "x" with an "abc", then when you type "x", we trigger onChange from beforeinput and rerender immediately with the content "abc", then the browser still inserts an "x" character! This fix is surprisingly simple: instead of triggering an update during beforeinput, we simply wait until the input event to do so. This means that when we rerender, the browser would have already inserted the "x" character and React will correctly delete it when rerendering. Test Plan: In plaintext example, change the handler to ``` this.onChange = (editorState) => { var content = editorState.getCurrentContent(); return this.setState({ editorState: EditorState.set(editorState, { currentContent: Modifier.removeInlineStyle(content, content.getSelectionAfter(), 'OVERFLOW'); }), }); }; ``` then type. Characters don't get duplicated like they did before.
- Loading branch information