-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Fix metabox reordering #30617
Fix metabox reordering #30617
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed this fixes the bug with some manual testing. Also checked the postType
is passed as a string on trunk
with some well placed console.log
s and that is the case too.
packages/edit-post/src/editor.js
Outdated
@@ -102,6 +106,7 @@ function Editor( { | |||
? getEditedPostTemplate() | |||
: null, | |||
post: postObject, | |||
isEditorReady: __unstableIsEditorReady(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reading the coding standards and wondering if this should be returned with the __unstable
prefix too.
What am I missing? This is mainly for my own education rather than an opinion either way :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was following the style established elsewhere in the code where __unstable
and __experimental
is often removed, for example here:
gutenberg/packages/edit-post/src/components/layout/index.js
Lines 17 to 25 in 04c7c76
import { | |
BlockBreadcrumb, | |
__experimentalLibrary as Library, | |
} from '@wordpress/block-editor'; | |
import { Button, ScrollLock, Popover } from '@wordpress/components'; | |
import { | |
useViewportMatch, | |
__experimentalUseDialog as useDialog, | |
} from '@wordpress/compose'; |
Also, if I'm not mistaken, it seems that the __unstable
and __experimental
prefix is there for people using Gutenberg packages in their projects, so it's important not to document these functions and tell people to use them and so forth. Here it's just used locally and not exported anywhere.
That's just my reasoning for renaming it, but I'll put the __unstable
prefix back if you think that would be better.
I believe this PR could use some additional eyes... |
Hi there! thanks for the fix here, it seems to me that the current way this call is handled could be improved, and this is highlighted by the issue being fixed here. In other words and to avoid any timing issues in the future, what about a solution like this: 1- Remove the promise from here https://github.com/WordPress/WordPress/blob/57da3e781320dd62e3016624b310c23447d9e6d1/wp-admin/includes/post.php#L2379-L2381 and just call 2- Split the gutenberg/packages/edit-post/src/store/actions.js Lines 275 to 322 in 8aa446b
c- when setting the metaboxes, only call the second part if the editor is ready 3- Add an effect somewhere in the The main reason I'm suggesting this is to make the code less dependent on the timing of the actions being called. Does that sound like a better solution? |
Associated PR: |
Thank you for the review @youknowriad. Your suggestions sound good. However, I realized that I will not be able to invest time into this PR for at least a month. Just wanted to let you know. If it's still relevant when I can invest time in it, I'll do it. |
Hey @ribaricplusplus, just wanted to see if you had some time that freed up to revise this PR. I'd love to wrap this one up and get it shipped in a 5.8.x release of WordPress. |
Hi, I'm having a similar issue with ACF that I think has the same origin. After inserting a taxonomy I cannot open the meta boxes. The error doesn't happen in WP 5.6.x I've seen a similar report here: https://core.trac.wordpress.org/ticket/52818 It would be great if you could have this fix for the next minor version as right now it is hard to use the block editor since WP 5.7 with this bug. Thank you |
I haven't forgotten about this, but finding time is a struggle! I'll update you in the next few days about when I'll be able to work on this. |
I'll try to do it mid September. |
@youknowriad Hey. I've made the changes as you proposed, the patch to WordPress core is here: https://core.trac.wordpress.org/ticket/52818 Please review this again and let me know if something still needs to be changed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking very good to me, I'd appreciate some testing from folks relying on meta boxes a bit.
I assume this works even without the Core patch right (as we're supposed to support existing and previous WP versions in the Gutenberg plugin)
@youknowriad Yes.
@desrosj Can you mention anyone who could potentially do some testing? |
@youknowriad I just realized that my previous solution was actually not good because the Now I extracted the meta box initializing logic into a separate action on the |
* | ||
* @return {boolean} Whether meta boxes are initialized. | ||
*/ | ||
export function metaBoxesInitialized( state ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we maybe rename this one areMetaBoxesInitialized
, hasInitializedMetaboxes
or something like that to match the naming scheme of the other selectors?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still looking good. Good point on the extraction to an action + isInitialized check.
Thanks for your work and persistence here :) |
Tested on a last checkout from trunk: the re-ordering bug from the original issue is not reproduced. Re-ordering is kept after updating the post. |
* Fix API docs generation (#33384) * Docs: use markdown headings instead of links for API declarations (#33381) * Docs: Run Prettier after updating API in documentation (#33498) (cherry picked from commit 626f233) * Use tabs instead of spaces in block transform doc example (#33549) (cherry picked from commit 8afca1e) * Fix metabox reordering (#30617). * Block editor: don't render layout and duotone styles in between blocks (#32083) * Widgets: Allow HTML tags in description (#33814) * Widgets: Allow HTML tags in description * Use `dangerouslySetInnerHTML` Avoid `<div />` inside the `<p />` tag * Describe by dangerouslySetInnerHTML is used * Use safeHTML * Update comment * Editor: Set 'hide_empty' for the most used terms query (#33457) Don't include terms that aren't assigned to any posts as "most used" terms. * Update widget editor help links to point to the new support article (#33482) * If select-all fires in .editor-post-title__input, end the process.. (#33621) * Writing flow: select all: remove early return for post title (#33699) * Call onChangeSectionExpanded conditionally (#33618) * FontSizePicker: Use number values when the initial value is a number (#33679) * FontSizePicker: Don't use units if the value is a number * Add unit tests * Disable units when we have number values * Fix justification for button block when selected (#33739) * Remove margin setting, auto right conflict with justify buttons * Per review, add little margin back * Add error boundaries to widget screens (#33771) * Add error boundary to edit widgets screen * Add error boundary to customize widgets * Refactor sidebar controls provider to application level so that its state is not lost when re-initializing * Revert "Refactor sidebar controls provider to application level so that its state is not lost when re-initializing" This reverts commit 7d607ff. * Remove rebootability from customize widgets * Remove debug code * Fix insertion point in Widgets editors (#33802) * Default batch processor: Respect the batch endpoint's maxItems (#34280) This updates the default batch processor to make multiple batch requests if the number of requests to process exceeds the number of requests that the batch endpoint can handle. We determine the number of requests that the batch endpoint can handle by making a preflight OPTIONS request to /batch/v1. By default it is 25 requests. See https://make.wordpress.org/core/2020/11/20/rest-api-batch-framework-in-wordpress-5-6/. * Fix button block focus trap after a URL has been added (#34314) * Rework button block link UI to match RichText format implementation * Refine some more, determine visibility by selection and url state * Add e2e test * Also focus rich text when unlinking using a keyboard shortcut * Text for dropdown fields within legacy widgets in the Customizer is off centered (#34076) * Fix ESLint errors reported * Regenerate autogenerated docs * Update the `INSERTER_SEARCH_SELECTOR` path. This is a partial cherry pick of 2356b2d in order to fix the performance tests. Co-authored-by: André <[email protected]> Co-authored-by: JuanMa <[email protected]> Co-authored-by: Greg Ziółkowski <[email protected]> Co-authored-by: Jeff Bowen <[email protected]> Co-authored-by: Bruno Ribarić <[email protected]> Co-authored-by: Ella van Durpe <[email protected]> Co-authored-by: Petter Walbø Johnsgård <[email protected]> Co-authored-by: George Mamadashvili <[email protected]> Co-authored-by: Daniel Richards <[email protected]> Co-authored-by: Hiroshi Urabe <[email protected]> Co-authored-by: Kai Hao <[email protected]> Co-authored-by: Marcus Kazmierczak <[email protected]> Co-authored-by: Robert Anderson <[email protected]> Co-authored-by: Anton Vlasenko <[email protected]>
Description
Fixes #30071
Important: This PR also includes changes to WordPress core. I will submit those here: https://core.trac.wordpress.org/ticket/52818
Cause of issue:
postboxes.js wp-admin script (this one), which is responsible for saving meta box order, is initialized by
setAvailableMetaBoxesPerLocation
here:gutenberg/packages/edit-post/src/store/actions.js
Lines 279 to 281 in 8aa446b
However, that function is called from
post.php
, here:https://github.com/WordPress/WordPress/blob/57da3e781320dd62e3016624b310c23447d9e6d1/wp-admin/includes/post.php#L2379-L2381
But at that point the editor is not yet fully initialized because
setupEditor
action didn't run yet. SopostType
is still null, postboxes becomes initialized incorrectly (with null instead of proper post type), and then when reordering happens the reordered metaboxes are saved incorrectly.How has this been tested?
Manually. Try changing metabox order. Steps to reproduce are given in the linked issue.
Types of changes
Bug fix
Checklist:
I'm not sure if anything needs to be changed for React Native:
*.native.js
files for terms that need renaming or removal).