Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Reusable blocks allows conversion back to blocks when the reusable block has unsaved edits 1`] = `
"<!-- wp:paragraph -->
<p>12</p>
<!-- /wp:paragraph -->"
`;

exports[`Reusable blocks can be created from multiselection and converted back to regular blocks 1`] = `
"<!-- wp:paragraph -->
<p>Hello there!</p>
Expand Down
25 changes: 25 additions & 0 deletions packages/e2e-tests/specs/editor/various/reusable-blocks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,4 +297,29 @@ describe( 'Reusable blocks', () => {
expect( content ).toEqual( 'Awesome Paragraph modified' );
} );
} );

// Check for regressions of https://github.com/WordPress/gutenberg/issues/26421.
it( 'allows conversion back to blocks when the reusable block has unsaved edits', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the test.

await createReusableBlock( '1', 'Edited block' );

// Make an edit to the reusable block and assert that there's only a
// paragraph in a reusable block.
await page.waitForSelector( 'p[aria-label="Paragraph block"]' );
await page.click( 'p[aria-label="Paragraph block"]' );
await page.keyboard.type( '2' );
const selector =
'//div[@aria-label="Block: Reusable block"]//p[@aria-label="Paragraph block"][.="12"]';
const reusableBlockWithParagraph = await page.$x( selector );
expect( reusableBlockWithParagraph ).toBeTruthy();

// Convert back to regular blocks.
await clickBlockToolbarButton( 'Select Reusable block' );
await clickBlockToolbarButton( 'Convert to regular blocks' );
await page.waitForXPath( selector, {
hidden: true,
} );

// Check that there's only a paragraph.
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
} );
11 changes: 10 additions & 1 deletion packages/reusable-blocks/src/store/controls.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* External dependencies
*/
import { isFunction } from 'lodash';

/**
* WordPress dependencies
*/
Expand Down Expand Up @@ -70,7 +75,11 @@ const controls = {
oldBlock.attributes.ref
);

const newBlocks = parse( reusableBlock.content );
const newBlocks = parse(
isFunction( reusableBlock.content )
? reusableBlock.content( reusableBlock )
: reusableBlock.content
);
registry
.dispatch( 'core/block-editor' )
.replaceBlocks( oldBlock.clientId, newBlocks );
Expand Down