Skip to content

Commit

Permalink
Only save metaboxes when it's not an autosave (#7502)
Browse files Browse the repository at this point in the history
* Only save metaboxes when it's not an autosave

* Decouple listener from `isSavingPost` state
  • Loading branch information
danielbachhuber committed Jun 25, 2018
1 parent f143608 commit d7dc8f2
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions edit-post/store/effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,24 @@ const effects = {
}, {} );
store.dispatch( setMetaBoxSavedData( dataPerLocation ) );

// Saving metaboxes when saving posts
subscribe( onChangeListener( select( 'core/editor' ).isSavingPost, ( isSavingPost ) => {
if ( ! isSavingPost ) {
let wasSavingPost = select( 'core/editor' ).isSavingPost();
let wasAutosavingPost = select( 'core/editor' ).isAutosavingPost();
// Save metaboxes when performing a full save on the post.
subscribe( () => {
const isSavingPost = select( 'core/editor' ).isSavingPost();
const isAutosavingPost = select( 'core/editor' ).isAutosavingPost();

// Save metaboxes on save completion when past save wasn't an autosave.
const shouldTriggerMetaboxesSave = wasSavingPost && ! wasAutosavingPost && ! isSavingPost && ! isAutosavingPost;

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

if ( shouldTriggerMetaboxesSave ) {
store.dispatch( requestMetaBoxUpdates() );
}
} ) );
} );
},
REQUEST_META_BOX_UPDATES( action, store ) {
const state = store.getState();
Expand Down

0 comments on commit d7dc8f2

Please sign in to comment.