Skip to content

Commit

Permalink
Remove any existing subscriptions before adding a new save metaboxes …
Browse files Browse the repository at this point in the history
…sub to prevent multiple saves (#17522)
  • Loading branch information
glendaviesnz authored and youknowriad committed Sep 30, 2019
1 parent ec0618a commit b384252
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/edit-post/src/store/effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { metaBoxUpdatesSuccess, requestMetaBoxUpdates } from './actions';
import { getActiveMetaBoxLocations } from './selectors';
import { getMetaBoxContainer } from '../utils/meta-boxes';

let saveMetaboxUnsubscribe;

const effects = {
SET_META_BOXES_PER_LOCATIONS( action, store ) {
// Allow toggling metaboxes panels
Expand All @@ -40,8 +42,14 @@ const effects = {
//
// See: https://github.com/WordPress/WordPress/blob/5.1.1/wp-admin/includes/post.php#L2307-L2309
const hasActiveMetaBoxes = select( 'core/edit-post' ).hasMetaBoxes();

// First remove any existing subscription in order to prevent multiple saves
if ( !! saveMetaboxUnsubscribe ) {
saveMetaboxUnsubscribe();
}

// Save metaboxes when performing a full save on the post.
subscribe( () => {
saveMetaboxUnsubscribe = subscribe( () => {
const isSavingPost = select( 'core/editor' ).isSavingPost();
const isAutosavingPost = select( 'core/editor' ).isAutosavingPost();

Expand Down

0 comments on commit b384252

Please sign in to comment.