• David Pieri

    (@kosmical)


    Hi πŸ™‚

    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 here has an idea of what’s going on or if anybody has another idea of how it could be done.

    Any help is greatly appreciated πŸ™‚

    Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Block Editor: Reset Reusable Blocks to last saved record’ is closed to new replies.