-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Fix modifying state during onChange triggered by beforeinput #667
Conversation
cc @hellendag – This fix felt too obvious to me. Am I missing some reason why it can't work? |
This doesn't work; typing |
8d98962
to
de3a149
Compare
Fixed – I had a silly mistake. :) @stopachka I choose you! Think this makes sense? And @hellendag too if you have time. |
Thanks! This seems reasonable to me! I may not have considered this because I regard the post-mutation nature of the This is enough of a core input change that it's worth staying on your toes to make sure it doesn't lead to any mysterious editing issues. 🦄 |
de3a149
to
2e418ce
Compare
If there's anything I can do to help move this along, please let me know. |
Hi, any idea when this will be merged? Thank you |
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.
2e418ce
to
345fa6f
Compare
…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.
…archive#667" This fixes some issues with the fix originally merged from PR facebookarchive#667[2] Credit to @balpert and @srmcconomy for this fix. For now I'm getting them back in sync. Also thanks to @davidchang for pinging me about landing this, @colinjeane for reporting this bug in facebookarchive#917 and submitting a nearly identical fix: facebookarchive#919 @colinjeane since we already had this fixed internally I'm going to use our approach to keep things in sync. fixes facebookarchive#917, facebookarchive#849 [2]: facebookarchive#667 We also had to tweak this compared to the current internal version to accomodate a recent change that makes 'editOnBeforeInput' and the other handlers take 'editor' as an explicit argument instead of assumming 'this' will be the editor; facebookarchive@e64c2c3 Note that we are updating the version of 'fbjs' required in order to get access to the 'setImmediate' polyfill.
) This fixes some issues with the fix originally merged from PR #667[2] Credit to @balpert and @srmcconomy for this fix. For now I'm getting them back in sync. Also thanks to @davidchang for pinging me about landing this, @colinjeane for reporting this bug in #917 and submitting a nearly identical fix: #919 @colinjeane since we already had this fixed internally I'm going to use our approach to keep things in sync. fixes #917, #849 [2]: #667 We also had to tweak this compared to the current internal version to accomodate a recent change that makes 'editOnBeforeInput' and the other handlers take 'editor' as an explicit argument instead of assumming 'this' will be the editor; e64c2c3 Note that we are updating the version of 'fbjs' required in order to get access to the 'setImmediate' polyfill.
…archive#667" (facebookarchive#871) This fixes some issues with the fix originally merged from PR facebookarchive#667[2] Credit to @balpert and @srmcconomy for this fix. For now I'm getting them back in sync. Also thanks to @davidchang for pinging me about landing this, @colinjeane for reporting this bug in facebookarchive#917 and submitting a nearly identical fix: facebookarchive#919 @colinjeane since we already had this fixed internally I'm going to use our approach to keep things in sync. fixes facebookarchive#917, facebookarchive#849 [2]: facebookarchive#667 We also had to tweak this compared to the current internal version to accomodate a recent change that makes 'editOnBeforeInput' and the other handlers take 'editor' as an explicit argument instead of assumming 'this' will be the editor; facebookarchive@e64c2c3 Note that we are updating the version of 'fbjs' required in order to get access to the 'setImmediate' polyfill.
) This fixes some issues with the fix originally merged from PR #667[2] Credit to @balpert and @srmcconomy for this fix. For now I'm getting them back in sync. Also thanks to @davidchang for pinging me about landing this, @colinjeane for reporting this bug in #917 and submitting a nearly identical fix: #919 @colinjeane since we already had this fixed internally I'm going to use our approach to keep things in sync. fixes #917, #849 [2]: #667 We also had to tweak this compared to the current internal version to accomodate a recent change that makes 'editOnBeforeInput' and the other handlers take 'editor' as an explicit argument instead of assumming 'this' will be the editor; e64c2c3 Note that we are updating the version of 'fbjs' required in order to get access to the 'setImmediate' polyfill.
Fixes textioHQ/frontend#2259 This is an alternative method to getting around the problem of IE11 having no input event and wanting to allow native browser insertion to increase react performance See also: facebook#667 See also: facebook#871 The premise of this is that it updates the editor state immediately, on the onBeforeInput event. And then it adds extra flags to know what to do during the render. As opposed to waiting for the input event on IE.
Fixes textioHQ/frontend#2259 This is an alternative method to getting around the problem of IE11 having no input event and wanting to allow native browser insertion to increase react performance See also: facebook#667 See also: facebook#871 The premise of this is that it updates the editor state immediately, on the onBeforeInput event. And then it adds extra flags to know what to do during the render. As opposed to waiting for the input event on IE.
…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.
…archive#667" (facebookarchive#871) This fixes some issues with the fix originally merged from PR facebookarchive#667[2] Credit to @balpert and @srmcconomy for this fix. For now I'm getting them back in sync. Also thanks to @davidchang for pinging me about landing this, @colinjeane for reporting this bug in facebookarchive#917 and submitting a nearly identical fix: facebookarchive#919 @colinjeane since we already had this fixed internally I'm going to use our approach to keep things in sync. fixes facebookarchive#917, facebookarchive#849 [2]: facebookarchive#667 We also had to tweak this compared to the current internal version to accomodate a recent change that makes 'editOnBeforeInput' and the other handlers take 'editor' as an explicit argument instead of assumming 'this' will be the editor; facebookarchive@e64c2c3 Note that we are updating the version of 'fbjs' required in order to get access to the 'setImmediate' polyfill.
…871) This fixes some issues with the fix originally merged from PR #667[2] Credit to @balpert and @srmcconomy for this fix. For now I'm getting them back in sync. Also thanks to @davidchang for pinging me about landing this, @colinjeane for reporting this bug in #917 and submitting a nearly identical fix: facebookarchive/draft-js#919 @colinjeane since we already had this fixed internally I'm going to use our approach to keep things in sync. fixes #917, #849 [2]: facebookarchive/draft-js#667 We also had to tweak this compared to the current internal version to accomodate a recent change that makes 'editOnBeforeInput' and the other handlers take 'editor' as an explicit argument instead of assumming 'this' will be the editor; facebookarchive/draft-js@e64c2c3 Note that we are updating the version of 'fbjs' required in order to get access to the 'setImmediate' polyfill.
Fixes #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
then type. Characters don't get duplicated like they did before.