-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Fix Editable tagName changes after #635 #661
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
b2b9349
69e5bb7
69c6f99
d7165a5
e24c918
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,42 @@ | ||
| export default class TinyMCE extends wp.element.Component { | ||
| componentDidMount() { | ||
| this.initialize(); | ||
| } | ||
|
|
||
| shouldComponentUpdate( nextProps ) { | ||
| // We must prevent rerenders because TinyMCE will modify the DOM, thus | ||
| // breaking React's ability to reconcile changes. | ||
| // | ||
| // See: https://github.com/facebook/react/issues/6802 | ||
| return nextProps.tagName !== this.props.tagName; | ||
| } | ||
|
|
||
| componentWillUpdate( nextProps ) { | ||
| if ( ! this.editor ) { | ||
| return; | ||
| } | ||
|
|
||
| if ( nextProps.tagName !== this.props.tagName ) { | ||
| this.editor.destroy(); | ||
|
||
| this.editor = null; | ||
| } | ||
| } | ||
|
|
||
| componentDidUpdate( prevProps ) { | ||
| if ( this.props.tagName !== prevProps.tagName ) { | ||
| this.initialize(); | ||
| } | ||
| } | ||
|
|
||
| componentWillUnmount() { | ||
| if ( ! this.editor ) { | ||
|
||
| return; | ||
| } | ||
|
|
||
| this.editor.destroy(); | ||
| this.editor = null; | ||
| } | ||
|
|
||
| initialize() { | ||
|
||
| tinymce.init( { | ||
| target: this.editorNode, | ||
|
|
@@ -8,7 +46,10 @@ export default class TinyMCE extends wp.element.Component { | |
| browser_spellcheck: true, | ||
| entity_encoding: 'raw', | ||
| convert_urls: false, | ||
| setup: this.props.onSetup, | ||
| setup: ( editor ) => { | ||
| this.editor = editor; | ||
| this.props.onSetup( editor ); | ||
| }, | ||
| formats: { | ||
| strikethrough: { inline: 'del' } | ||
| } | ||
|
|
@@ -19,24 +60,6 @@ export default class TinyMCE extends wp.element.Component { | |
| } | ||
| } | ||
|
|
||
| componentDidMount() { | ||
| this.initialize(); | ||
| } | ||
|
|
||
| componentDidUpdate( prevProps ) { | ||
| if ( this.props.tagName !== prevProps.tagName ) { | ||
| this.initialize(); | ||
| } | ||
| } | ||
|
|
||
| shouldComponentUpdate( nextProps ) { | ||
| // We must prevent rerenders because TinyMCE will modify the DOM, thus | ||
| // breaking React's ability to reconcile changes. | ||
| // | ||
| // See: https://github.com/facebook/react/issues/6802 | ||
| return nextProps.tagName !== this.props.tagName; | ||
| } | ||
|
|
||
| render() { | ||
| const { tagName = 'div', style, className, defaultValue } = this.props; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm surprised to find that this doesn't really break. I think it'd be worth updating the preceding comment to describe when and why we allow a rerender, and ideally how it's exempt from the concern noted in the referenced issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this sound okay?