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

Metaboxes save: perform hasMetaBoxes check on every save #45145

Merged
merged 2 commits into from
Oct 20, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions packages/edit-post/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,6 @@ export const initializeMetaBoxes =
let wasAutosavingPost = registry
.select( editorStore )
.isAutosavingPost();
const hasMetaBoxes = select.hasMetaBoxes();

// Save metaboxes when performing a full save on the post.
registry.subscribe( async () => {
Expand All @@ -575,23 +574,15 @@ export const initializeMetaBoxes =
.select( editorStore )
.isAutosavingPost();

// Save metaboxes on save completion, except for autosaves that are not a post preview.
//
// Meta boxes are initialized once at page load. It is not necessary to
// account for updates on each state change.
//
// See: https://github.com/WordPress/WordPress/blob/5.1.1/wp-admin/includes/post.php#L2307-L2309.
// Save metaboxes on save completion, except for autosaves.
const shouldTriggerMetaboxesSave =
hasMetaBoxes &&
Copy link
Contributor

@youknowriad youknowriad Oct 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we keep the call to select.hasMetaBoxes() here that way a single boolean is enough for the check later?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like the change in 5c4e4c7? Done!

wasSavingPost &&
! isSavingPost &&
! wasAutosavingPost;
wasSavingPost && ! wasAutosavingPost && ! isSavingPost;

// Save current state for next inspection.
wasSavingPost = isSavingPost;
wasAutosavingPost = isAutosavingPost;

if ( shouldTriggerMetaboxesSave ) {
if ( shouldTriggerMetaboxesSave && select.hasMetaBoxes() ) {
await dispatch.requestMetaBoxUpdates();
}
} );
Expand Down