Skip to content

What is the proposed way to update blocks? #4849

Closed

Description

@fabianpimminger

I've been wondering how content should be updated on old posts after the block html-markup changes?

Without using dynamic blocks it is not possible to "re-render"/update all blocks, am I correct? What is the proposed way to update non-dynamic blocks when site owners want to change the markup of the content? Is there any way to do this without opening all old posts and re-saving them? Or should we just use dynamic blocks when markup could change in the future?

Activity

  1. youknowriad commented on Feb 3, 2018

    @youknowriad
    Contributor

    I'll reply with a question. Do you think it's ok to update old content on a website when a plugin gets updated without the user's consent? Don't you think if the content is published, the user doesn't want it to change unless he does explicitly?

    I think most of the time, this is not an issue.

    If you'd like to know more about deprecated blocks, see this page https://wordpress.org/gutenberg/handbook/block-api/deprecated-blocks/

    And yes, in some small use-cases (remains to be seen for static blocks), you want to update the content in which case, it's probably better to use a dynamic block.

    Thanks for opening the issue, I'm closing it right now. Let me know if I didn't answer your concerns.

  2. fabianpimminger commented on Feb 3, 2018

    @fabianpimminger
    ContributorAuthor

    Let me give a theoretical example. I'm developing a block for my own blog. I use divs and other current markup to achieve this. Then, a new html element emerges in a future standard and I want to update all instances of this block in all posts because it's a better fit. As I'm the developer of my own block, I know how it will affect my blog.

    I think this will drive many developers to choose dynamic blocks and this won't be such a small use-case?

    I just wanted to get a confirmation if dynamic blocks are the way to go if I want to have the possibility of updating all instances of one block. Thanks :)

  3. youknowriad commented on Feb 3, 2018

    @youknowriad
    Contributor

    Yes, dynamic blocks are the way to go in this case. But your use case is not so common. In general content creators are very different from block authors.

    Enjoy Hacking

  4. katerlouis commented on May 30, 2018

    @katerlouis

    I am facing the same issue and absolutely agree with Fabian on this.

    What if the frontend switches to a different carousel plugin, which requires new HTML structure for the galleries. From an editors perspective, the content isn't changing. From a devs perspective, quite a lot has to change.

    Or what if you simply made a simple mistake in the blocks output and need to update it?

    I mean, there must be a plan to deal with updating blocks, right? I don't even remotely see how updating blocks is an edge case.

    When even the slightest changes in my block.js break the block in the editor, I'd really like to have frontend output with PHP hooks back :'(

    image

    Maybe I'm completely missing something here; please elaborate on what that is, because falling back to RichText or the HTML alone effectively makes complex blocks uneditable once the js code is updated.

  5. wturnerharris commented on Aug 9, 2018

    @wturnerharris

    So I think we are encountering this very issue, and our only solve is to either have a stable block that will rarely change from a markup-perspective or build deprecations? As an agency we will be constantly iterating over blocks for clients as design needs change or as content structure evolves. To dismiss use-cases is to ignore the community.

    I do agree that some way to hook into the output to upgrade a block, to make intelligent decisions on whether to output content based on emptiness would be useful, especially for rapid development and without destroying non-markup content.

    There should be some way to manage the data layer. Furthermore, if there is a hook for the "Convert to Blocks" button, then we might be able to refactor on the spot without losing data.

  6. wpmark commented on Aug 23, 2018

    @wpmark

    I also agree that this is a massive problem is the markup of a block cannot be changed without re-saving the posts that use the block. I have tried to add some doc on the dynamic blocks doc page here to explain that using dynamic blocks is the way to go here.

    #8765

    However, @tofumatt indicates this is not the way to go - therefore what is?

    @youknowriad you mention

    Do you think it's ok to update old content on a website when a plugin gets updated without the user's consent?

    We are not talking about updating content - just markup.

  7. fabianpimminger commented on Aug 23, 2018

    @fabianpimminger
    ContributorAuthor

    @wpmark Good point, because @youknowriad said it is the way to go? I think this should be mentioned in the docs because it is an important factor to decide which type of block developers should use.

  8. youknowriad commented on Aug 23, 2018

    @youknowriad
    Contributor

    We are not talking about updating content - just markup.

    How is that different from the technical perspective, if we allow people to change markup, they would be able to change content without the user's consent.

    There is definitely some improvements we can make to the way we deal with those deprecated versions but dynamic blocks have their drawback:

    • If you disable the plugin, there's no content anymore
    • If for some reason the PHP filter is not executed (think about plugins exploiting the database), the content is there and it's semantically valid.

    While I agree that it seems better devX wise, but for the user I'd argue that dynamic blocks are worse and Gutenberg should definitely not emphasize on those. Content blocks are better defined as static blocks for the user.

  9. fabianpimminger commented on Nov 28, 2018

    @fabianpimminger
    ContributorAuthor

    I've revisited Gutenberg yesterday (as the 5.0 release is near) and I still think that this is a fundamental problem of Gutenberg.

    With the 5.0 release, there are still many blocks that are not 100% ready. The gallery block for example still doesn't solve all issues related to image sizes/responsiveness. As mentioned in #1450, blocks related to image handling will change after 5.0.

    So if I update my most important posts after the 5.0 release to include some Gutenberg features (probably 25-50 out of ~100), I will have to manually update all posts again when 5.1 is released to get better support for image handling? And probably again when 5.2 is released?

    Contrary to previous Wordpress updates, when image responsiveness (srcset attributes) just got added to ALL posts, this process seems overly cumbersome.

  10. jSanchoDev commented on Dec 12, 2018

    @jSanchoDev

    Correctly me if I'm wrong (b/c I'm new to Gutenberg), but if I develop a plugin with 20 or 30 blocks and release it, then rewrite blocks markup for version 1.0.1, then for 1.0.2, etc. - I'd have to copy/paste the save() / edit() methods code from each previous version? And keep them forever?

    If this is the case, then what is the best strategy - to keep the markup always the same? Or to use dynamic blocks for all blocks? What if I have a large markup for block and have to remove some tiny part of it, or correct an error - do I have to keep all this in deprecation history? This may result in huge js bundle size for version 2.0.0 :)

    Also, what is the proper way to handle this behavior while developing a block? Each markup change basically invalidates the saved version and you can only convert it to HTML.

  11. davidcrandall99 commented on Dec 14, 2018

    @davidcrandall99

    If the blocks don't update dynamically, it kind of defeats the purpose of using them. I.e, if I change my theme, I may need the blocks to use different html in order to work cohesively with my theme. Otherwise, I'm forced to manually go through all posts and update every block individually.

    Marrying the content to the UI is just bad content management. There's no reason that divs, columns, rows, etc., should be part of the SQL markup for the actual content.

    Gutenberg has a lot of promise, but it's not a scalable solution for developers.

  12. roryashfordbentley commented on Jan 9, 2019

    @roryashfordbentley

    Hypothetically, how would the following be possible:

    I have a blog with 1000s of posts. Within most of these posts are multiple Button Blocks that look like this:

    <div class="wp-block-button"><a class="wp-block-button__link" href="https://google.com">Link to Google</a></div>
    

    The client has made a support request to add an icon to each button and we would like to change the button markup to the following:

    <a class="my-button-class" href="https://google.com">Link to Google<img src="myicon.svg"</a>
    

    Right now, how would it be possible to roll this update out to all existing posts? Would I need to update the Block component and then use something like WP-CLI to do a database find and replace for all existing instances of the button?

  13. fabianpimminger commented on Jan 9, 2019

    @fabianpimminger
    ContributorAuthor

    Would I need to update the Block component and then use something like WP-CLI to do a database find and replace for all existing instances of the button?

    Yes, … or open each post where the block has been used and save it again using the editor.

    (just for the sake of the argument obviously. This could've been done using css for all instances)

  14. roryashfordbentley commented on Jan 9, 2019

    @roryashfordbentley

    Yeah this particular example could certainly use CSS I appreciate that :)

    I have just been testing out the an ACF (Advanced Custom Fields) acf_register_block() functionality and I really like the way they store and handle the data for blocks.

    ACF Gutenberg Blocks are stored in the DB like this:

    <!-- wp:acf/button {"id":"block_5c360c7625570","data":{"field_5c3604866626a":"Link to Google","field_5c3604996626b":"https://www.google.com"},"name":"acf/button","align":"","mode":"preview"} /-->
    

    Presumably this would suffer from similar issues with updating old instances of components but I'm a big fan of Key/Value/JSON stores and this way completely seperates markup from content. I can now load a theme component passing it the field values and that component handles all of the presentational styles.

  15. 27 remaining items

  16. pratham2003 commented on Feb 20, 2020

    @pratham2003

    There is also a technical road block to this that no one has spoken of so far in this thread..

    The block's structure is defined in a JavaScript file which generates the HTML (client side) when editing an article.

    We would need to figure out a way for PHP to update multiple articles when a block's structure is updated in JavaScript.
    Some kind of PHP/NodeJS based server-side rendering of JavaScript?

    Can someone point me to a page that documents reasons for WordPress' decision to use JS for HTML template instead of PHP?

  17. neryams commented on Feb 20, 2020

    @neryams

    There is also a technical road block to this that no one has spoken of so far in this thread..

    The block's structure is defined in a JavaScript file which generates the HTML (client side) when editing an article.

    We would need to figure out a way for PHP to update multiple articles when a block's structure is updated in JavaScript.
    Some kind of PHP/NodeJS based server-side rendering of JavaScript?

    Can someone point me to a page that documents reasons for WordPress' decision to use JS for HTML template instead of PHP?

    I think the upgrade would be a manual process; i.e. an upgrade script that the author would have to write that would run to update the HTML properly from one version to another, if the output needs to be changed.

  18. cfix-git commented on Mar 10, 2020

    @cfix-git

    There is also a technical road block to this that no one has spoken of so far in this thread..

    The block's structure is defined in a JavaScript file which generates the HTML (client side) when editing an article.

    We would need to figure out a way for PHP to update multiple articles when a block's structure is updated in JavaScript.
    Some kind of PHP/NodeJS based server-side rendering of JavaScript?

    Can someone point me to a page that documents reasons for WordPress' decision to use JS for HTML template instead of PHP?

    @pratham2003 If you want to edit the content of multiple posts at once, you can use some of the ideas in this StackOverflow post.

    As far as a reason to use JS over PHP, Gutenberg has explained its intentions pretty thoroughly in the handbook. In short it is about the editing experience. If you want strong UX, you need JavaScript.

    I'd support it further by saying that JavaScript is undeniably the immediate future of web development. Through popular frameworks, including React, we are able to easily create stunning UX. PHP does not provide stunning UX.

  19. MonsterKing commented on Mar 10, 2020

    @MonsterKing
  20. ddluc commented on Mar 17, 2020

    @ddluc

    Do you think it's ok to update old content on a website when a plugin gets updated without the user's consent? Don't you think if the content is published, the user doesn't want it to change unless he does explicitly?

    @youknowriad

    Why not just let the user choose? I do agree that it would be bad if the plugin was updated and the markup (or worse, the content) was modified, resulting in unconsented updates on a user's website. But, I think that only applies to publicly released plugins. For me, I'm a known vendor for my clients, and any updates I'd make to a block have explicit constent—or have been requested—to be updated.

    What would it take for there to be a setting that the user can set from the block sidebar, which allows static blocks to automatically apply any updates that have been made in the block's save method? I don't have experience contributing to WP, but this is such a headache for me that I'd be willing to devote some time to learning and implementing this feature.

    It would be a much much better development experience if the front-end portion of the block could just be built using Javascript/JSX rather than having to revert to PHP just so I can have my edits automatically detected and applied.

  21. marvinpoo commented on Apr 7, 2020

    @marvinpoo

    Why not just let the user choose? I do agree that it would be bad if the plugin was updated and the markup (or worse, the content) was modified, resulting in unconsented updates on a user's website.

    Exactly!

    I have no idea how everyone on here works, but I am sure most, if not all of us are following the laws, because as far as I know altering code without the consent of the owner (aka Client) is considered illegal in most western countries anyway, so why use the excuse of "you could update the content without consent" if it would include a illegal action of the dev. Is this the strategy of community management of Wordpress since Gutenberg? It's time to admit there have been some major problems in handling the transition and was forced way to hard and way to fast.

  22. jodamo5 commented on Apr 7, 2020

    @jodamo5
    Contributor

    I have no idea how everyone on here works, but I am sure most, if not all of us are following the laws, because as far as I know altering code without the consent of the owner (aka Client) is considered illegal in most western countries anyway,
    @marvinpoo

    I think you've got things confused. If the law worked the way you describe then all plugin updates that have been happening for many years would be illegal! Because plugin updates alter code used on sites. Instead, let's take a step back and look at the main issue being described here:

    A developer creates a block. That block is used on hundreds of pages - or maybe even hundreds or thousands of sites. The developer then wants to make some improvements to the block - maybe because users have requested improved functionality, or there is a bug with recent browser updates, or the developer finds a problem that should be fixed. When the update is applied to the site, the fix should be applied immediately to all current instances of the block, so that the issue is fixed everywhere they block is used. However, with the current deprecation process, all of the existing blocks would keep their old buggy state and only new blocks would get the fixed version. Multiply this across hundreds or thousands of pages - that is why it is impractical to get the user to go to every page that the block is used and edit and resave to upgrade to the new block.

    Our specific scenario that we personally had to deal with was that one of the custom Gutenberg blocks we built for a client's website included an image, a heading, text and a link. When we originally built the block the image was not linked only the heading was. But after using this block on a number of pages, we then wanted to adjust the block to make the image be linked too, in order to improve the user experience. It is ridiculous that we need to open up every page this block has been used on and re-save the page just to get the updated code to apply. When a client requests a change like this, Gutenberg blocks should all update automatically to reflect the new version of the block - which is exactly what used to happen with PHP blocks in Wordpress. For us to achieve this, we now build all blocks as Dynamic Blocks. But this is not exactly ideal as it has some limitations (e.g. no nested blocks) and isn't the intended use of Gutenberg.

    So this is still definitely an area that needs improvement! The conversation around how to improve this is happening on #7604 but there doesn't seem to be much confirmed progress so far.

  23. marvinpoo commented on Apr 8, 2020

    @marvinpoo

    I think you've got things confused. If the law worked the way you describe then all plugin updates that have been happening for many years would be illegal! Because plugin updates alter code used on sites.

    Thats technically something different. When you buy/download a plugin and enable auto updates/ updates, then you give consent to the altering or even agreed to the tos of the distributors shop and their conditions. If the dev changes something on the website without the consent of the client, then they would theoretically do a unauthorized modifiaction. Tho, as with everything in law it is, if no one sues, no one is sued. It's like with domains. If you would just move a domain from A to B without the consent of your client, you have breaken the law, but no (serious & integer) developer would move the domain of a client without their permission, same goes for altering the website/priject in general.

    What I was trying to express was, that in the normal behaviour a developer has a contract or atleast the permission to change/edit/differ something in the code. If you as developer change something on a website of a (ex)client without their consent then you are theoretically breaking the law. That doesn't mean in most cases your (ex)client wouldn't be thankful for the change (as example security fix or similar). But no developer would just go to their clients website and edit something out of the blue.

    But afterall, that was just a side node pointing to the excuse that this feature is not being aimed on because devs would alter the content, which puts the developer into a position of distrust by a thirdparty bystander. I am sure most developers have contracts or similar agreements with their clients.

    Our specific scenario that we personally had to deal with was that one of the custom Gutenberg blocks we built for a client's website included an image, a heading, text and a link. When we originally built the block the image was not linked only the heading was. But after using this block on a number of pages, we then wanted to adjust the block to make the image be linked too, in order to improve the user experience. It is ridiculous that we need to open up every page this block has been used on and re-save the page just to get the updated code to apply. When a client requests a change like this, Gutenberg blocks should all update automatically to reflect the new version of the block - which is exactly what used to happen with PHP blocks in Wordpress. For us to achieve this, we now build all blocks as Dynamic Blocks. But this is not exactly ideal as it has some limitations (e.g. no nested blocks) and isn't the intended use of Gutenberg.

    This is so true and basically exactly the same problem we have encountered recently (tho this wasn't the first time this annoyed us). Our example was different but very close. We've used infocards on some sites and wanted to add the ability for the client to choose their own icon at the infocard instead of a simple arrow icon. The old version and the new version are technically the same except for the fact that the content of the

    <i class="material-icons">{ attributes.urlicon }</i>

    is being altered by the input of it.

    I think it is very unpractical for both sides, the developer and the client and needs some work. We have some clients that work on their own content and for some clients we edit the content. If only we would be changing the content, I could live with that, but when I have to tell a client that he has to edit all of his pages because we added a new icon feature, that raises some questions in our clients if we are even competent enough. We understand in the technical way why and how this needs to be done atm, but when I tell that a client who understands the basics of the web, they just plainly ask us, "why did you choose that cms in the first place then?" and honestly, the client is correct. Why would we keep using wordpress if the basics of contenting will always bring up problems like this.

    For us to achieve this, we now build all blocks as Dynamic Blocks. But this is not exactly ideal as it has some limitations (e.g. no nested blocks) and isn't the intended use of Gutenberg.

    Yes, that is my concern, too.
    As @youknowriad stated in 2018

    There is definitely some improvements we can make to the way we deal with those deprecated versions but dynamic blocks have their drawback:
    If you disable the plugin, there's no content anymore
    If for some reason the PHP filter is not executed (think about plugins exploiting the database), the content is there and it's semantically valid.

    Thank you for linking to the correct issue, by the way. Let's hope there will be a acceptable solution for this topic at some point. Until then, we will keep the use of blocks at a minimum.

  24. pwkip commented on Aug 8, 2020

    @pwkip
    Contributor

    @youknowriad concerning these quotes:

    Do you think it's ok to update old content on a website when a plugin gets updated without the user's consent?

    and

    How is that different from the technical perspective, if we allow people to change markup, they would be able to change content without the user's consent.

    Plugin authors already have the power to do this. Nothing (technical) is preventing them from running a DB query and modifying the code parts between <!-- org:block --> and <!-- /org:block -->

    Now they would do it all in their own way, instead of doing it in a well documented manner. Having an approach well documented in one place, could also include a best practices note to encourage plugin developers to actually ask the user for consent before running the actual DB updates.

    I am not saying that updating a block should automatically update all existing posts. What I'm (and I believe most people here are) asking is some kind of standardized way or documentation on how to bulk update the blocks in existing posts.

    Do you have any suggestions? actionable items? I'd be happy to reopen and explore if that's the case.

    Here's a suggestion:

    • add a function called update_block($block_name, $post_id) that will convert all the $block_name blocks in a post to their updated version.

    Would this be sufficient to reopen the issue?

  25. pwkip commented on Aug 16, 2020

    @pwkip
    Contributor

    Since this doesn't seem to be a priority for the core team, I went ahead and created a plugin that allows updating blocks. It is very raw, so I wouldn't recommend using it on production websites at this stage. There might be some useful code snippets for developers. https://github.com/pwkip/bulk-update-blocks

  26. cbratschi commented on Oct 30, 2020

    @cbratschi

    In my opinion the main issue is that the whole architecture is markup oriented and not data oriented at the end. In order to support the deprecation handling path, the same old markup has to be generated forever or the block is broken. I would like to have a way to completely decouple blocks from the generated markup. This would allow developers to focus on the attributes and provide a more stable process to handle older block data. I am wondering why this does not exist and why there is no versioning available.

    Simple example of a block registration:

    {
        ...
        version: '1.0.1',
        migration: (attributes, from, to) => {
            switch (from) {
                case '1.0.0':
                    //upgrade data
                   break;
    
                //throw exception if migration not possible (broken block case; should be avoided at all costs)
            }
        }
    }
    

    The other issue is that rendering is done mostly on the client side and updates are only possible through a manual edit and save. Due to a strict versioning it should be possible to iterate through all posts and update the markup to the latest version (if not up-to-date). A lot of plugins have to scan through all posts, for instance to generate a database index, so this is quite familiar to most WordPress users.

    Just my two cents.

  27. juandahveed commented on Nov 5, 2020

    @juandahveed

    @studionenontwerp I know i'm a little late to the party, but I love the approach. Any idea why the prepare_attributes method throws an error with this line?

    $obj = WP_Block_Type_Registry::get_instance()->get_registered( $block['blockName'] );

    it always returns NULL but I'm not sure why.

  28. studionenontwerp commented on Nov 5, 2020

    @studionenontwerp

    @juandahveed , I think your block is not registered when you use this line of code. I register all my blocks in 'init' , priority 9.

    add_action( 'init', 'register_my_blocks' , 9 );

  29. juandahveed commented on Nov 5, 2020

    @juandahveed

    @studionenontwerp I'm just not understanding... In the example above, you used JavaScript to register the block.

  30. added
    [Feature] Blocks
    on Oct 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Feature] Blocks

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions