Skip to content

Commit

Permalink
Only save metaboxes when it's not an autosave
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbachhuber committed Jun 25, 2018
1 parent f143608 commit 652d0a5
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion edit-post/store/effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,21 @@ const effects = {
store.dispatch( setMetaBoxSavedData( dataPerLocation ) );

// Saving metaboxes when saving posts
const { isAutosavingPost } = select( 'core/editor' );
let shouldRequestMetaBoxUpdates = false;
subscribe( onChangeListener( select( 'core/editor' ).isSavingPost, ( isSavingPost ) => {
if ( ! isSavingPost ) {
// Only save metaboxes when this isn't an autosave.
if ( isSavingPost && ! isAutosavingPost( store.getState() ) ) {
shouldRequestMetaBoxUpdates = true;
}
// If a full save just completed, trigger metabox save.
if ( ! isSavingPost && shouldRequestMetaBoxUpdates ) {
store.dispatch( requestMetaBoxUpdates() );
}
// Regardless of which save just occurred, reset metabox save state.
if ( ! isSavingPost ) {
shouldRequestMetaBoxUpdates = false;
}
} ) );
},
REQUEST_META_BOX_UPDATES( action, store ) {
Expand Down

0 comments on commit 652d0a5

Please sign in to comment.