WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.32k stars 4.12k forks source link

Block bindings: Can't save changes to the source if custom fields are opened #64217

Closed carolinan closed 1 week ago

carolinan commented 1 month ago

Description

Since https://github.com/WordPress/gutenberg/pull/61753 it is possible to edit the value of a (post meta) binding in a paragraph block or heading by selecting the block and typing. The change is synced across the site when saved.

But if the user preference to show Custom fields is enabled, meaning the meta boxes are open, the meta box field does not update and using the Save button on the post or page does not save the changes to the field. After clicking save and refreshing, the value is not updated.

Step-by-step reproduction instructions

I used the code example from 61753:

  1. Register post meta by adding this snippet to your theme's functions.php
    
    add_action( 'init', 'test_block_bindings' );

function test_block_bindings() { register_meta( 'post', 'text_field', array( 'show_in_rest' => true, 'single' => true, 'type' => 'string', 'default' => 'default text value', ) ); }

2. Add a paragraph block bound to the custom field using the Code Editor

Paragraph content


3. Go to Options >Preferences > Advanced and enable custom fields.
4. Select the bond block. Edit the text of the paragraph. Save.
5. Refresh the page.
6. Confirm if the value is updated or not.

### Screenshots, screen recording, code snippet

_No response_

### Environment info

WordPress 6.6.1.

### Please confirm that you have searched existing issues in the repo.

- [X] Yes

### Please confirm that you have tested with all plugins deactivated except Gutenberg.

- [X] Yes
Mamaduka commented 1 month ago

I'm guessing that the source of the issue is the same as in #23078.

SantosGuillamot commented 1 month ago

I've been taking a look today and I am able to reproduce it. After the first look, I believe the issue is caused by this code. I'll keep triaging it and see how it could be solved. The legacy meta box panel is tricky.

SantosGuillamot commented 1 month ago

I have started this pull request trying to solve this issue. Although I must say that I am not familiar with that code and I am not sure if that's a viable approach.

gziolo commented 3 weeks ago

But if the user preference to show Custom fields is enabled, meaning the meta boxes are open, the meta box field does not update and using the Save button on the post or page does not save the changes to the field.

What do you think about disabling editing for Post Meta block bindings source when Meta Boxes are open? This would essentially resolve the problem, as two-way synchronization would no longer be needed. I also assume that having two places to edit the same metadata for the sites that heavily depend on Meta Boxes isn't that helpful. In effect, when the setting is enabled to use Meta Boxes, then in the post editor Post Meta source would remain in the readonly mode bringing back the experience from WordPress 6.5. It also means that the previewed value won't refresh until the user clicks the Save button to propagate post meta changes to the server.

SantosGuillamot commented 2 weeks ago

What do you think about disabling editing for Post Meta block bindings source when Meta Boxes are open?

This would make sense to me 🙂 Although it is true that other plugins modifying post meta in the store would still face the same issue. This is an example reported a while ago: https://github.com/WordPress/gutenberg/issues/23078