Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicating Gutenberg blocks in edit mode erases data upon saving the post #923

Open
mrdarrengriffin opened this issue Jul 29, 2024 · 10 comments

Comments

@mrdarrengriffin
Copy link

Describe the bug
When duplicating a block with ACF fields in Gutenberg, there is an issue where if there are 2 or more of the same block on the page, the newly added block will not save correctly. Gutenberg does not correctly display the fact that the fields are empty which is causes a massive friction point for content loading.

To Reproduce
Steps to reproduce the behavior. I did this on a fresh install of WordPress 6.1.1 via Local. I installed ACF Pro 6.3.4 with no other plugins active. I was using the Twenty Twenty Four theme.

  1. Open the functions.php file from the active theme
  2. Copy the example provided here into the bottom of the file: https://www.advancedcustomfields.com/blog/acf-5-8-introducing-acf-blocks-for-gutenberg/#functionsphp
  3. In the WordPress admin area, go to ACF > Field Groups and create a block. For my example, I created a "Test Block" group with a "Title" text field. I ensured that the newly created block was chosen in the field block settings rules.
  4. Create a new page
  5. Insert the "Testimonial" block, enter edit mode and type something in the "Title" ACF field.
  6. Publish the page and once saved, refresh the page. You will notice the field shows the correct value
  7. Duplicate the testimonial block using the toolbar menu or CTRL+SHIFT+D
  8. Make an alteration to the field in the newly duplicated testimonials block
  9. Save the page and then refresh. You will first be asked if you want to leave and discard changes. Once the page loads, you will notice both fields show the correct values
  10. Duplicate the bottom testimonial block and change the title once again to something different
  11. Save the page and then refresh. You will notice that only the first two blocks have the correct value. The block we just made has a blank field.
  12. Make a change to the now empty field
  13. Save the page and then refresh. You will first be asked if you want to leave and discard changes. Once the page loads, you will notice that the last block has the correct field value.

Please note:

  • This issue does not occur if you are in the block preview mode.
  • This issue only occurs if you duplicate a block
  • This issue does not occur on version 6.2.9 or below

Expected behavior
When duplicating blocks, the data associated with the original block should be retained. Upon saving and refreshing, the data should persist.

Screenshots or Video
https://github.com/user-attachments/assets/e12d4494-e54a-458e-aaae-dd895f92cc17

Code
Test field group:
acf-export-2024-07-29.json

Example code used for testimonial block:

add_action('acf/init', 'my_acf_init');
function my_acf_init() {
    
    // check function exists
    if( function_exists('acf_register_block') ) {
        
        // register a testimonial block
        acf_register_block(array(
            'name'              => 'testimonial',
            'title'             => __('Testimonial'),
            'description'       => __('A custom testimonial block.'),
            'render_callback'   => 'my_acf_block_render_callback',
            'category'          => 'formatting',
            'icon'              => 'admin-comments',
            'keywords'          => array( 'testimonial', 'quote' ),
        ));
    }
}

Version Information:

  • WordPress 6.6.1
  • PHP 8.1.29
  • ACF Pro 6.3.4
  • Google Chrome 126.0.6478.185

Additional context
Add any other context about the problem here.

@mattgrshaw
Copy link
Member

Hi @mrdarrengriffin,

Thanks for the detailed report! We've been able to replicate this on our end and will look at fixing this up in a future release.

@mrdarrengriffin
Copy link
Author

Hi @mattgrshaw, out of curiosity, do you know what sort of timeline we're looking at? I just need to advice our team and content loaders as to when we can expect a fix. Thanks!

@maksymmamontov
Copy link

hi @mattgrshaw could you please update on the timelines for this?
we're struggling with this issue on all projects with ACF right now.

block duplication is basically not working at all at ACF Version 6.3.5.

@kmwalsh
Copy link

kmwalsh commented Aug 14, 2024

@maksymmamontov It's not at all a real workaround (especially for clients). Switch to block editor Code mode, copy the block markup manually, and paste it in in code mode, then switch back to editing mode to modify things as needed. That seemed to have worked on the site I tried it on.

@maksymmamontov
Copy link

@kmwalsh yes, this helps and as developers we usually do it this way
but clients are sometimes confused why it's not working, just as with this bug (but it's not ACF-related):
WordPress/gutenberg#38731

@selceeus
Copy link

I have run across this same issue or a similar one this week.
I would add that copy/pasting blocks have the same results.
I had to roll back the ACF Plugin to version 6.2.10.
Versions 6.3 and up had the issue.
Upon upgrade to 6.3 and up any duplicated block reverted to having these issues and would not render to the front end.

@cbirdsong
Copy link

I believe I've also run into this issue and have had to roll back. This bug has caused major issues with data loss for a client of ours. It definitely merits a quick point release fix if possible.

Does anyone know if disabling validation sidesteps the issue? If so, it would be ideal if there was a way to do that in blocks registered using acf_register_block_type, or even globally using a filter.

@cbirdsong
Copy link

Per support, validation is always disabled on blocks registered using acf_register_block_type, so that doesn't help. Just have to revert and wait for a fix.

@darren-strategiq
Copy link

darren-strategiq commented Aug 29, 2024

@mattgrshaw, please can we get an update on this issue and when it will likely to be fixed? It's clear that many people are affected by this and is causing issues for their clients.

Thanks in advance

@mattgrshaw
Copy link
Member

Hey folks, we're planning to fix this up as part of our next major release. We don't have an ETA on that just yet, but it is in development and we'll update this thread as we have more to share.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants