Skip to content
This repository was archived by the owner on Feb 6, 2023. It is now read-only.

Commit 26040e5

Browse files
flarniefacebook-github-bot
authored andcommitted
Add 'flushSync' to Draft.js for *only* GK folks
Summary: We did this in https://our.intern.facebook.com/intern/diff/D6727557/ and then it was reverted due to bugs like https://our.intern.facebook.com/intern/tasks/?t=25244286 ... But we still want to do this! Let's enable under a GK so we can dogfood and possibly identify repro steps. Context from original version of this diff - We have seen various issues with Draft and other controlled text inputs when React is in "async mode", such that updates are rendered asynchronously. For more context and repro steps, see #1577 I also added the logic to the plain text editor test page for manual testing, until we write unit tests for this. Reviewed By: acdlite Differential Revision: D6802653 fbshipit-source-id: 9f6952e9cb77cf79f9650d167075b1c337e3d35f
1 parent f6fbf1c commit 26040e5

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/component/base/DraftEditor.react.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const DraftEditorContents = require('DraftEditorContents.react');
2626
const DraftEditorDragHandler = require('DraftEditorDragHandler');
2727
const DraftEditorEditHandler = require('DraftEditorEditHandler');
2828
const DraftEditorPlaceholder = require('DraftEditorPlaceholder.react');
29+
const DraftFeatureFlags = require('DraftFeatureFlags');
2930
const EditorState = require('EditorState');
3031
const React = require('React');
3132
const ReactDOM = require('ReactDOM');
@@ -171,10 +172,15 @@ class DraftEditor extends React.Component<DraftEditorProps, State> {
171172
* editor mode, if any has been specified.
172173
*/
173174
_buildHandler(eventName: string): Function {
175+
const flushSyncSupported = !!ReactDOM.flushSync;
174176
return e => {
175177
if (!this.props.readOnly) {
176178
const method = this._handler && this._handler[eventName];
177-
method && method(this, e);
179+
if (flushSyncSupported && DraftFeatureFlags.draft_js_flush_sync) {
180+
method && ReactDOM.flushSync(() => method(this, e));
181+
} else {
182+
method && method(this, e);
183+
}
178184
}
179185
};
180186
}

src/component/utils/DraftFeatureFlags-core.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ var DraftFeatureFlags = {
1818
draft_segmented_entities_behavior: false,
1919
draft_handlebeforeinput_composed_text: false,
2020
draft_tree_data_support: false,
21+
draft_js_flush_sync: false,
2122
};
2223

2324
module.exports = DraftFeatureFlags;

0 commit comments

Comments
 (0)