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

Commit

Permalink
2/n Do update 'blockSelectEvents' flag, during render
Browse files Browse the repository at this point in the history
Summary:
We found via logging that this flag actually is being used in some cases - so we need to keep setting it.
Seems like the closest we can get to the current timing is to set it in a child
component which mounts when a successful 'render' of the parent DraftEditor
finishes. This is an amazing hack that sophiebits thought of to deal with the
other flag we were setting in cWU.

logs -
https://our.intern.facebook.com/intern/scuba/query/?dataset=draft_js_events&pool=uber&view=Table&drillstate=%7B%22sampleCols%22%3A%5B%22time%22%2C%22weight%22%2C%22accountid%22%2C%22anonymized_dom%22%2C%22browser_full_version%22%2C%22browser_name%22%2C%22browser_os%22%2C%22event%22%2C%22extra_params%22%2C%22http_referrer%22%2C%22scribe_category_type%22%2C%22script_path%22%2C%22selection_state%22%2C%22userid%22%5D%2C%22derivedCols%22%3A%5B%5D%2C%22mappedCols%22%3A%5B%5D%2C%22enumCols%22%3A%5B%5D%2C%22return_remainder%22%3Afalse%2C%22should_pivot%22%3Afalse%2C%22is_timeseries%22%3Afalse%2C%22hideEmptyColumns%22%3Afalse%2C%22start%22%3A%22-1+week%22%2C%22samplingRatio%22%3A%221%22%2C%22compare%22%3A%22%22%2C%22hide_sample_cols%22%3Afalse%2C%22minBucketSamples%22%3A%22%22%2C%22dimensions%22%3A%5B%5D%2C%22cellOverlay%22%3A%22None%22%2C%22metric%22%3A%22avg%22%2C%22top%22%3A%22200%22%2C%22timezone%22%3A%22America%2FLos_Angeles%22%2C%22end%22%3A%22now%22%2C%22cols%22%3A%5B%22accountid%22%2C%22userid%22%5D%2C%22aggregateList%22%3A%5B%5D%2C%22param_dimensions%22%3A%5B%5D%2C%22modifiers%22%3A%5B%5D%2C%22order%22%3A%22weight%22%2C%22order_desc%22%3Atrue%2C%22filterMode%22%3A%22DEFAULT%22%2C%22constraints%22%3A%5B%5B%7B%22column%22%3A%22event%22%2C%22op%22%3A%22eq%22%2C%22value%22%3A%5B%22%5B%5C%22blocked_selection_event%5C%22%5D%22%5D%7D%5D%5D%2C%22c_constraints%22%3A%5B%5B%5D%5D%2C%22b_constraints%22%3A%5B%5B%5D%5D%7D
the code - https://github.com/facebook/draft-js/blob/a6317e60b06519d3c00a2c0621701f3da0837a88/src/component/handlers/edit/editOnSelect.js#L30-L40

Depends on D7116729

Reviewed By: sophiebits

Differential Revision: D7116762

fbshipit-source-id: d5707a52c684c8ceb84624848c4c0d139f6232b2
  • Loading branch information
flarnie authored and facebook-github-bot committed Mar 2, 2018
1 parent 4241f43 commit e571268
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/component/base/DraftEditor.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ type State = {

let didInitODS = false;

class UpdateEditorState extends React.Component<{
class UpdateDraftEditorFlags extends React.Component<{
editor: DraftEditor,
editorState: EditorState,
}> {
Expand All @@ -79,6 +79,7 @@ class UpdateEditorState extends React.Component<{
this._update();
}
_update() {
const editor = this.props.editor;
if (gkx('draft_js_remove_componentwillupdate')) {
/**
* Sometimes a render triggers a 'focus' or other event, and that will
Expand Down Expand Up @@ -113,9 +114,22 @@ class UpdateEditorState extends React.Component<{
* Note that if we don't set latestEditorState in 'render' in the above
* diagram, then STALE_STATE gets passed to render #2.
*/
const editor = this.props.editor;
editor._latestEditorState = this.props.editorState;
}
if (gkx('draft_js_stop_blocking_select_events')) {
/**
* The reason we set this 'blockSelectEvents' flag is that IE will fire a
* 'selectionChange' event when we programmatically change the selection,
* meaning it would trigger a new select event while we are in the middle
* of updating.
* We found that the 'selection.addRange' was what triggered the stray
* selectionchange event in IE.
* To be clear - we have not been able to reproduce specific bugs related
* to this stray selection event, but have recorded logs that some
* conditions do cause it to get bumped into during editOnSelect.
*/
editor._blockSelectEvents = true;
}
}
}

Expand Down Expand Up @@ -402,7 +416,7 @@ class DraftEditor extends React.Component<DraftEditorProps, State> {
Needs to come earlier in the tree as a sibling (not ancestor) of
all DraftEditorLeaf nodes so it's first in postorder traversal.
*/}
<UpdateEditorState editor={this} editorState={editorState} />
<UpdateDraftEditorFlags editor={this} editorState={editorState} />
<DraftEditorContents {...editorContentsProps} />
</div>
</div>
Expand Down Expand Up @@ -438,8 +452,6 @@ class DraftEditor extends React.Component<DraftEditorProps, State> {
*/
componentWillUpdate(nextProps: DraftEditorProps): void {
if (!gkx('draft_js_stop_blocking_select_events')) {
// We suspect this is not actually needed with modern React
// For people in the GK, we will skip setting this flag.
this._blockSelectEvents = true;
}
if (!gkx('draft_js_remove_componentwillupdate')) {
Expand Down

0 comments on commit e571268

Please sign in to comment.