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

Only save metaboxes when it's not an autosave #7502

Merged
merged 2 commits into from
Jun 25, 2018
Merged
Changes from all commits
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
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