1

I’m trying to build my own Block Editor and I would like to reset all blocks to their last saved state by dismissing all unsaved changes when switching from Edit Mode to Preview Mode without reloading the page.

Currently it works fine with all “normal” blocks:

const originalContent = select('core/editor').getCurrentPost().content;
const parsedOriginalContent = wp.blocks.parse(originalContent);
dispatch('core/block-editor').resetBlocks(parsedOriginalContent);

Unfortunately it doesn’t work as expected with Reusable Blocks.

For example I can get all saved Reusable Blocks with

const savedReusableBlocks = select('core').getEntityRecords('postType','wp_block');

then parse its raw content as well, add them to an array with all other blocks currently on the page and throw it altogether into the resetBlocks() method. The behavior I’m getting is that the saved Reusable Blocks are just added to the current page, in addition to the edited Reusable Blocks, so that there are now duplicates on the page. I’m not quite sure why this is happening and I’m wondering if anybody knows what’s going on or if anybody has an idea of how it could be done.

Any help is greatly appreciated 🙂

Thank you!

P.S. It could be done if I could get the block content from all the InnerBlocks inside Reusable Blocks, but these InnerBlocks are always multiple layers deep nested, differently for all individual Reusable Blocks, which are again different for every website. So that seems like an impossible task for me.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.