Skip to content

Commit

Permalink
Merge pull request #85 from ckeditor/t/83
Browse files Browse the repository at this point in the history
Fix: The `<CKEditor>` component will not update anything until it is not ready. Closes #83.
  • Loading branch information
ma2ciek committed Mar 29, 2019
2 parents efde85c + 28df18c commit 63cb97d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/ckeditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ export default class CKEditor extends React.Component {

// This component should never be updated by React itself.
shouldComponentUpdate( nextProps ) {
if ( !this.editor ) {
return false;
}

if ( this._shouldUpdateContent( nextProps ) ) {
this.editor.setData( nextProps.data );
}
Expand Down
18 changes: 18 additions & 0 deletions tests/ckeditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,24 @@ describe( 'CKEditor Component', () => {
} );

describe( 'properties', () => {
// See: #83.
it( 'does not update anything if component is not ready', () => {
const editorInstance = new Editor();

sandbox.stub( Editor, 'create' ).resolves( editorInstance );

wrapper = mount( <CKEditor editor={ Editor } /> );

const component = wrapper.instance();
let shouldComponentUpdate;

expect( () => {
shouldComponentUpdate = component.shouldComponentUpdate( { disabled: true } );
} ).to.not.throw();

expect( shouldComponentUpdate ).to.be.false;
} );

describe( '#onInit', () => {
it( 'calls "onInit" callback if specified when the editor is ready to use', done => {
const editorInstance = new Editor();
Expand Down

0 comments on commit 63cb97d

Please sign in to comment.