Skip to content

Commit

Permalink
Rich Text: Remove componentDidUpdate deep equality
Browse files Browse the repository at this point in the history
  • Loading branch information
aduth committed Jul 3, 2018
1 parent 66581eb commit 6831606
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 19 deletions.
8 changes: 1 addition & 7 deletions editor/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -808,13 +808,7 @@ export class RichText extends Component {
!! this.editor &&
this.props.tagName === prevProps.tagName &&
this.props.value !== prevProps.value &&
this.props.value !== this.savedContent &&

// Comparing using isEqual is necessary especially to avoid unnecessary updateContent calls
// This fixes issues in multi richText blocks like quotes when moving the focus between
// the different editables.
! isEqual( this.props.value, prevProps.value ) &&
! isEqual( this.props.value, this.savedContent )
this.props.value !== this.savedContent
) {
this.setContent( this.props.value );
}
Expand Down
3 changes: 1 addition & 2 deletions test/e2e/specs/__snapshots__/adding-blocks.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ exports[`adding blocks Should insert content using the placeholder and the regul
<!-- wp:quote -->
<blockquote class=\\"wp-block-quote\\">
<p>Quote block</p>
</blockquote>
<p>Quote block</p><cite>Quote citation</cite></blockquote>
<!-- /wp:quote -->
<!-- wp:code -->
Expand Down
19 changes: 9 additions & 10 deletions test/e2e/specs/adding-blocks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
* Internal dependencies
*/
import '../support/bootstrap';
import { newPost, newDesktopBrowserPage, insertBlock } from '../support/utils';
import {
newPost,
newDesktopBrowserPage,
insertBlock,
getHTMLFromCodeEditor,
} from '../support/utils';

describe( 'adding blocks', () => {
beforeAll( async () => {
Expand Down Expand Up @@ -47,6 +52,8 @@ describe( 'adding blocks', () => {
await page.keyboard.type( '/quote' );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( 'Quote block' );
await page.keyboard.press( 'ArrowDown' );
await page.keyboard.type( 'Quote citation' );

// Using the regular inserter
await insertBlock( 'Code' );
Expand All @@ -62,14 +69,6 @@ describe( 'adding blocks', () => {
await page.click( '[data-type="core/quote"] .editor-block-list__insertion-point-button' );
await page.keyboard.type( 'Second paragraph' );

// Switch to Text Mode to check HTML Output
await page.click( '.edit-post-more-menu [aria-label="More"]' );
const codeEditorButton = ( await page.$x( '//button[contains(text(), \'Code Editor\')]' ) )[ 0 ];
await codeEditorButton.click( 'button' );

// Assertions
const textEditorContent = await page.$eval( '.editor-post-text-editor', ( element ) => element.value );

expect( textEditorContent ).toMatchSnapshot();
expect( await getHTMLFromCodeEditor() ).toMatchSnapshot();
} );
} );
6 changes: 6 additions & 0 deletions test/e2e/support/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ export async function switchToEditor( mode ) {
await button.click( 'button' );
}

/**
* Switches to Code editor and retrieves the editor HTML, returning a promise
* resolving with the HTML string.
*
* @return {Promise} Promise resolving with editor HTML string.
*/
export async function getHTMLFromCodeEditor() {
await switchToEditor( 'Code' );
const textEditorContent = await page.$eval( '.editor-post-text-editor', ( element ) => element.value );
Expand Down

0 comments on commit 6831606

Please sign in to comment.