Skip to content

Commit

Permalink
Rich Text: Scold deeply equally referentially inequal value updates
Browse files Browse the repository at this point in the history
  • Loading branch information
aduth committed Jul 3, 2018
1 parent 6831606 commit 59cfb2c
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions editor/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -803,21 +803,34 @@ export class RichText extends Component {
}

componentDidUpdate( prevProps ) {
const { tagName, value } = this.props;

// The `savedContent` var allows us to avoid updating the content right after an `onChange` call
if (
!! this.editor &&
this.props.tagName === prevProps.tagName &&
this.props.value !== prevProps.value &&
this.props.value !== this.savedContent
tagName === prevProps.tagName &&
value !== prevProps.value &&
value !== this.savedContent
) {
this.setContent( this.props.value );
}

// Note: Environment condition must be independent for it to be dropped
// in dead code elimination with webpack.DefinePlugin.
if ( 'development' === process.env.NODE_ENV ) {
/* eslint-disable no-console */
if ( value !== prevProps.value && isEqual( value, prevProps.value ) ) {
console.error( 'RichText value reference changed while being deeply equal to `prevProps.value`. This will incur wasted effort to update the RichText field.' );
}

if ( value !== this.savedContent && isEqual( value, this.savedContent ) ) {
console.error( 'RichText value reference changed while being deeply equal to `this.savedContent`. This will incur wasted effort to update the RichText field.' );
}

if ( ! isEqual( this.props.formatters, prevProps.formatters ) ) {
// eslint-disable-next-line no-console
console.error( 'Formatters passed via `formatters` prop will only be registered once. Formatters can be enabled/disabled via the `formattingControls` prop.' );
}
/* eslint-enable no-console */
}
}

Expand Down

0 comments on commit 59cfb2c

Please sign in to comment.