From a96c27cf3fee24e20373149d6cc02a103656719f Mon Sep 17 00:00:00 2001 From: Jarda Snajdr Date: Thu, 20 Oct 2022 10:27:17 +0200 Subject: [PATCH 1/2] MetaBoxes Save: perform hasMetaBoxes check on every save --- packages/edit-post/src/store/actions.js | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/packages/edit-post/src/store/actions.js b/packages/edit-post/src/store/actions.js index 8c74b809c7594a..e34c153be12234 100644 --- a/packages/edit-post/src/store/actions.js +++ b/packages/edit-post/src/store/actions.js @@ -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 () => { @@ -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 && - 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(); } } ); From 5c4e4c75e2c8f3dad4393410e0e5646f5c13f3ce Mon Sep 17 00:00:00 2001 From: Jarda Snajdr Date: Thu, 20 Oct 2022 11:04:44 +0200 Subject: [PATCH 2/2] Reorg the condition --- packages/edit-post/src/store/actions.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/edit-post/src/store/actions.js b/packages/edit-post/src/store/actions.js index e34c153be12234..7d0479a79de291 100644 --- a/packages/edit-post/src/store/actions.js +++ b/packages/edit-post/src/store/actions.js @@ -576,13 +576,16 @@ export const initializeMetaBoxes = // Save metaboxes on save completion, except for autosaves. const shouldTriggerMetaboxesSave = - wasSavingPost && ! wasAutosavingPost && ! isSavingPost; + wasSavingPost && + ! wasAutosavingPost && + ! isSavingPost && + select.hasMetaBoxes(); // Save current state for next inspection. wasSavingPost = isSavingPost; wasAutosavingPost = isAutosavingPost; - if ( shouldTriggerMetaboxesSave && select.hasMetaBoxes() ) { + if ( shouldTriggerMetaboxesSave ) { await dispatch.requestMetaBoxUpdates(); } } );