diff --git a/packages/block-library/src/list/utils.js b/packages/block-library/src/list/utils.js index 61d1cbef89234..481ec3b6accd9 100644 --- a/packages/block-library/src/list/utils.js +++ b/packages/block-library/src/list/utils.js @@ -30,7 +30,7 @@ export function createListBlockFromDOMElement( listElement ) { const [ nestedList, ...nodes ] = children; const hasNestedList = - nestedList.tagName === 'UL' || nestedList.tagName === 'OL'; + nestedList?.tagName === 'UL' || nestedList?.tagName === 'OL'; if ( ! hasNestedList ) { return createBlock( 'core/list-item', { content: listItem.innerHTML, diff --git a/test/e2e/specs/editor/blocks/__snapshots__/List-can-be-created-by-pasting-an-empty-list-1-chromium.txt b/test/e2e/specs/editor/blocks/__snapshots__/List-can-be-created-by-pasting-an-empty-list-1-chromium.txt new file mode 100644 index 0000000000000..a947833fba19d --- /dev/null +++ b/test/e2e/specs/editor/blocks/__snapshots__/List-can-be-created-by-pasting-an-empty-list-1-chromium.txt @@ -0,0 +1,5 @@ + + + \ No newline at end of file diff --git a/test/e2e/specs/editor/blocks/list.spec.js b/test/e2e/specs/editor/blocks/list.spec.js index 7545056812614..051cf18c107aa 100644 --- a/test/e2e/specs/editor/blocks/list.spec.js +++ b/test/e2e/specs/editor/blocks/list.spec.js @@ -1132,4 +1132,25 @@ test.describe( 'List', () => { ` ); } ); + + test( 'can be created by pasting an empty list', async ( { + editor, + pageUtils, + } ) => { + // Open code editor + await pageUtils.pressKeyWithModifier( 'secondary', 'M' ); // Emulates CTRL+Shift+Alt + M => toggle code editor + + // Paste empty list block + await pageUtils.setClipboardData( { + plainText: + '\n\n', + } ); + await pageUtils.pressKeyWithModifier( 'primary', 'v' ); + + // Go back to normal editor + await pageUtils.pressKeyWithModifier( 'secondary', 'M' ); // Emulates CTRL+Shift+Alt + M => toggle code editor + + // Verify no WSOD and content is proper. + expect( await editor.getEditedPostContent() ).toMatchSnapshot(); + } ); } );