2

I have built a Gutenberg block which is used on several pages on a client site. When the block is modified after a client request, it breaks the block on the editor of all the pages which needs to be manually fixed by using the Attempt Recovery feature.

In addition to this, the front end doesn't update until the block is recovered and saved again.

I was wondering if there is an easy way to fix the blocks whenever they're modified?

3
  • When updating a block that has been used, you need to "deprecate" the block, which allows it to be migrated to the new version. The process for that is documented here: developer.wordpress.org/block-editor/developers/block-api/… Commented May 25, 2020 at 13:40
  • Thanks a lot, this is just what I needed! Can you add this as an answer so that I can accept it? Commented May 25, 2020 at 14:51
  • Block deprecation works to address the rendering issues in the block editor but all of the blocks will still need to be manually updated as the markup is still saved in the database.
    – Welcher
    Commented May 26, 2020 at 23:02

1 Answer 1

2

I would recommend moving to a dynamic block as opposed to a static one. The difference being that dynamic blocks are rendered via PHP and don't save the markup in the database. This allows you to make any changes you want to the block output and it will be reflected without needing to update each instance of the block.

In order to convert your static block to a dynamic one, you'll need to modify the save property to return null on the JavaScript side and then register the block on the PHP side with a render_callback. There is a an example in the developer docs that you can review here.

If you update the question with your code, I'd be happy to help you update it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.