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

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

Closed
2 tasks done
carolinan opened this issue Aug 3, 2024 · 5 comments · Fixed by #64738
Closed
2 tasks done

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

carolinan opened this issue Aug 3, 2024 · 5 comments · Fixed by #64738
Assignees
Labels
[Feature] Block bindings Needs Dev Note Requires a developer note for a major WordPress release cycle [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended

Comments

@carolinan
Copy link
Contributor

carolinan commented Aug 3, 2024

Description

Since #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',
		)
	);
}
  1. Add a paragraph block bound to the custom field using the Code Editor
<!-- wp:paragraph {"metadata":{"bindings":{"content":{"source":"core/post-meta","args":{"key":"text_field"}}}}} -->
<p>Paragraph content</p>
<!-- /wp:paragraph -->

  1. Go to Options >Preferences > Advanced and enable custom fields.
  2. Select the bond block. Edit the text of the paragraph. Save.
  3. Refresh the page.
  4. 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.

  • Yes

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

  • Yes
@carolinan carolinan added [Type] Bug An existing feature does not function as intended [Feature] Block bindings labels Aug 3, 2024
@Mamaduka
Copy link
Member

Mamaduka commented Aug 3, 2024

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

@SantosGuillamot
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Member

gziolo commented Aug 23, 2024

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
Copy link
Contributor

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: #23078

@fabiankaegy fabiankaegy added the Needs Dev Note Requires a developer note for a major WordPress release cycle label Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Block bindings Needs Dev Note Requires a developer note for a major WordPress release cycle [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended
Projects
None yet
5 participants