diff --git a/packages/block-library/src/paragraph/edit.js b/packages/block-library/src/paragraph/edit.js index 0ed9c5c91b5820..91dc83c69984f9 100644 --- a/packages/block-library/src/paragraph/edit.js +++ b/packages/block-library/src/paragraph/edit.js @@ -244,8 +244,8 @@ class ParagraphBlock extends Component { } } unstableOnSplit={ this.splitBlock } onMerge={ mergeBlocks } - onReplace={ this.onReplace } - onRemove={ () => onReplace( [] ) } + onReplace={ this.props.onReplace && this.onReplace } + onRemove={ onReplace && ( () => onReplace( [] ) ) } aria-label={ content ? __( 'Paragraph block' ) : __( 'Empty block; start writing or type forward slash to choose a block' ) } placeholder={ placeholder || __( 'Start writing or type / to choose a block' ) } /> diff --git a/packages/e2e-tests/specs/plugins/__snapshots__/cpt-locking.test.js.snap b/packages/e2e-tests/specs/plugins/__snapshots__/cpt-locking.test.js.snap index de467ce40d3e80..24166c89f310b3 100644 --- a/packages/e2e-tests/specs/plugins/__snapshots__/cpt-locking.test.js.snap +++ b/packages/e2e-tests/specs/plugins/__snapshots__/cpt-locking.test.js.snap @@ -1,5 +1,19 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`cpt locking template_lock all should not error when deleting the cotents of a paragraph 1`] = ` +" +
\\"\\"/
+ + + +

+ + + +

+" +`; + exports[`cpt locking template_lock false should allow blocks to be inserted 1`] = ` "
\\"\\"/
diff --git a/packages/e2e-tests/specs/plugins/cpt-locking.test.js b/packages/e2e-tests/specs/plugins/cpt-locking.test.js index 2a858b8a5c8499..4239716c6c1a48 100644 --- a/packages/e2e-tests/specs/plugins/cpt-locking.test.js +++ b/packages/e2e-tests/specs/plugins/cpt-locking.test.js @@ -8,6 +8,7 @@ import { deactivatePlugin, getEditedPostContent, insertBlock, + pressKeyTimes, } from '@wordpress/e2e-test-utils'; describe( 'cpt locking', () => { @@ -58,6 +59,14 @@ describe( 'cpt locking', () => { await page.$( 'button[aria-label="Move up"]' ) ).toBeNull(); } ); + + it( 'should not error when deleting the cotents of a paragraph', async () => { + await page.click( '.block-editor-block-list__block[data-type="core/paragraph"] p' ); + const textToType = 'Paragraph'; + await page.keyboard.type( 'Paragraph' ); + await pressKeyTimes( 'Backspace', textToType.length + 1 ); + expect( await getEditedPostContent() ).toMatchSnapshot(); + } ); } ); describe( 'template_lock insert', () => {