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

Commit

Permalink
2/n Remove last vestiges of cWU
Browse files Browse the repository at this point in the history
Summary: We have been testing this change for the last few weeks, now time to remove the flag.

Reviewed By: bvaughn

Differential Revision: D7415031

fbshipit-source-id: 2c8d57d6645873a90a278a2f3fe838cf913b0a25
  • Loading branch information
flarnie authored and facebook-github-bot committed Mar 27, 2018
1 parent 0f6199d commit e954091
Showing 1 changed file with 37 additions and 54 deletions.
91 changes: 37 additions & 54 deletions src/component/base/DraftEditor.react.js
Expand Up @@ -80,42 +80,41 @@ class UpdateDraftEditorFlags extends React.Component<{
}
_update() {
const editor = this.props.editor;
if (gkx('draft_js_remove_componentwillupdate')) {
/**
* Sometimes a render triggers a 'focus' or other event, and that will
* schedule a second render pass.
* In order to make sure the second render pass gets the latest editor
* state, we update it here.
* Example:
* render #1
* +
* |
* | cWU -> Nothing ... latestEditorState = STALE_STATE :(
* |
* | render -> this.props.editorState = FRESH_STATE
* | + *and* set latestEditorState = FRESH_STATE
* |
* | |
* | +--> triggers 'focus' event, calling 'handleFocus' with latestEditorState
* | +
* | |
* +>cdU -> latestEditorState = FRESH_STATE | the 'handleFocus' call schedules render #2
* | with latestEditorState, which is FRESH_STATE
* |
* render #2 <--------------------------------------+
* +
* |
* | cwU -> nothing updates
* |
* | render -> this.props.editorState = FRESH_STATE which was passed in above
* |
* +>cdU fires and resets latestEditorState = FRESH_STATE
* ---
* Note that if we don't set latestEditorState in 'render' in the above
* diagram, then STALE_STATE gets passed to render #2.
*/
editor._latestEditorState = this.props.editorState;
}
/**
* Sometimes a render triggers a 'focus' or other event, and that will
* schedule a second render pass.
* In order to make sure the second render pass gets the latest editor
* state, we update it here.
* Example:
* render #1
* +
* |
* | cWU -> Nothing ... latestEditorState = STALE_STATE :(
* |
* | render -> this.props.editorState = FRESH_STATE
* | + *and* set latestEditorState = FRESH_STATE
* |
* | |
* | +--> triggers 'focus' event, calling 'handleFocus' with latestEditorState
* | +
* | |
* +>cdU -> latestEditorState = FRESH_STATE | the 'handleFocus' call schedules render #2
* | with latestEditorState, which is FRESH_STATE
* |
* render #2 <--------------------------------------+
* +
* |
* | cwU -> nothing updates
* |
* | render -> this.props.editorState = FRESH_STATE which was passed in above
* |
* +>cdU fires and resets latestEditorState = FRESH_STATE
* ---
* Note that if we don't set latestEditorState in 'render' in the above
* diagram, then STALE_STATE gets passed to render #2.
*/
editor._latestEditorState = this.props.editorState;

/**
* The reason we set this 'blockSelectEvents' flag is that IE will fire a
* 'selectionChange' event when we programmatically change the selection,
Expand Down Expand Up @@ -444,26 +443,10 @@ class DraftEditor extends React.Component<DraftEditorProps, State> {
}
}

/**
* Prevent selection events from affecting the current editor state. This
* is mostly intended to defend against IE, which fires off `selectionchange`
* events regardless of whether the selection is set via the browser or
* programmatically. We only care about selection events that occur because
* of browser interaction, not re-renders and forced selections.
*/
componentWillUpdate(nextProps: DraftEditorProps): void {
if (!gkx('draft_js_remove_componentwillupdate')) {
// we are using the GK to phase out setting this here
this._latestEditorState = nextProps.editorState;
}
}

componentDidUpdate(): void {
this._blockSelectEvents = false;
if (gkx('draft_js_remove_componentwillupdate')) {
// moving this here, when it was previously set in componentWillUpdate
this._latestEditorState = this.props.editorState;
}
// moving this here, when it was previously set in componentWillUpdate
this._latestEditorState = this.props.editorState;
this._latestCommittedEditorState = this.props.editorState;
}

Expand Down

0 comments on commit e954091

Please sign in to comment.