-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Metaboxes registered after initial initialisation are not saved #44716
Comments
Hi, @lgladdy Can you provide a minimal code example to reproduce the issue without ACF? |
@Mamaduka Sure! I've thrown together a quick plugin that shows the issue via a simple JS loaded into the block editor, https://github.com/lgladdy/gutenberg-issue-44716-demo If you toggle between the Updating a post where the meta box was added immediately, the editor will save metaboxes with a call to |
Oops, sorry - repo is now public. The main code that needs to run to demo this is here: https://github.com/lgladdy/gutenberg-issue-44716-demo/blob/main/after-init.js - if you'd rather run it in some other way than a plugin! |
Yes, the buggy behavior is a combination of #15041, which moved the
@lgladdy This is probably not 100% reliable because Maybe we could change I'm fixing the |
Just to add my +1 that this resolves the issue in ACF. Thanks @jsnajdr! 🥳 |
Description
Somewhere around WordPress 5.8, Gutenberg stopped saving Advanced Custom Fields data for metaboxes which are added to pages after the page has been initialised.
This is because the
hasMetaBoxes
constant is only checked on init:gutenberg/packages/edit-post/src/store/actions.js
Line 570 in 46179e2
This means for any metaboxes added to the page after init (in ACF's case, this happens if a field group is only assigned to a specific category, and the user changes that page to that category), the check for
shouldTriggerMetaboxesSave
is always false:gutenberg/packages/edit-post/src/store/actions.js
Line 585 in 46179e2
ACF does dispatch
setAvailableMetaBoxesPerLocation
when it adds a new metabox after init, but that doesn't trigger the update forhasMetaBoxes
to allow them to save.We don't think this is an issue we can solve our side, short of registering a "hidden" meta box that is always present to trigger the save - we're also happy to raise a PR to help fix this in Gutenberg too, but would love some advice and direction on the best place to add the logic to fix this.
Thanks!
Step-by-step reproduction instructions
hasMetaBoxes
was empty on init, theshouldTriggerMetaboxesSave
check will return false when it should be aware new metaboxes have been added and save.I threw together a minimum viable demo of the issue here: https://github.com/lgladdy/gutenberg-issue-44716-demo/blob/main/after-init.js
Screenshots, screen recording, code snippet
No response
Environment info
No response
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
No
The text was updated successfully, but these errors were encountered: