Description
Description
Following the example found here https://developer.wordpress.org/block-editor/how-to-guides/metabox/ there is an issue updating meta, if the Custom Fields
Panel is open.
It looks like there is a race condition happening where the meta field is updated via the block, but then the custom fields below are updated afterwards using the static values below.
This can be negated by either
- Ensuring the custom field panel is always closed
- Prefixin the meta key with an
_
- Using the
is_protected_meta
filter to mark the field as protected
The last 2 options just suppresses the field from being shown in the Custom Fields Panel.
Not sure what can be done about this, but ideally should be documented on the above developer guide, as this confused me.
Step-by-step reproduction instructions
Create the block as detailed here
Turn on the custom field Panel
Set a value using the block and reload the page, your meta should be set (and displayed)
Update the meta field and reload the page once saved, it will be reverted back to the initial value (as the custom fields below do not get updated)
Screenshots, screen recording, code snippet
metabox.issue.mp4
Environment info
WP 6.1.1
No plugins active bar the one with this block.Twenty Twenty Two
theme or Twenty Twenty One
or Twenty Twenty
Chrome and Firefox on Ubuntu
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