diff --git a/packages/edit-post/src/store/actions.js b/packages/edit-post/src/store/actions.js index 1dc0401baf21c3..d00f7472382f80 100644 --- a/packages/edit-post/src/store/actions.js +++ b/packages/edit-post/src/store/actions.js @@ -8,7 +8,7 @@ import { privateApis as editorPrivateApis, } from '@wordpress/editor'; import deprecated from '@wordpress/deprecated'; -import { addAction } from '@wordpress/hooks'; +import { addFilter } from '@wordpress/hooks'; import { store as coreStore } from '@wordpress/core-data'; /** @@ -478,14 +478,21 @@ export const initializeMetaBoxes = metaBoxesInitialized = true; // Save metaboxes on save completion, except for autosaves. - addAction( - 'editor.savePost', + addFilter( + 'editor.__unstableSavePost', 'core/edit-post/save-metaboxes', - async ( options ) => { - if ( ! options.isAutosave && select.hasMetaBoxes() ) { - await dispatch.requestMetaBoxUpdates(); - } - } + ( previous, options ) => + previous.then( () => { + if ( options.isAutosave ) { + return; + } + + if ( ! select.hasMetaBoxes() ) { + return; + } + + return dispatch.requestMetaBoxUpdates(); + } ) ); dispatch( { diff --git a/packages/editor/src/store/actions.js b/packages/editor/src/store/actions.js index fa720e1fc7d347..4b519a9d8f6cc3 100644 --- a/packages/editor/src/store/actions.js +++ b/packages/editor/src/store/actions.js @@ -12,11 +12,7 @@ import { import { store as noticesStore } from '@wordpress/notices'; import { store as coreStore } from '@wordpress/core-data'; import { store as blockEditorStore } from '@wordpress/block-editor'; -import { - applyFilters, - applyFiltersAsync, - doActionAsync, -} from '@wordpress/hooks'; +import { applyFilters } from '@wordpress/hooks'; import { store as preferencesStore } from '@wordpress/preferences'; import { __ } from '@wordpress/i18n'; @@ -188,7 +184,7 @@ export const savePost = } const previousRecord = select.getCurrentPost(); - let edits = { + const edits = { id: previousRecord.id, ...registry .select( coreStore ) @@ -203,9 +199,9 @@ export const savePost = let error = false; try { - edits = await applyFiltersAsync( - 'editor.preSavePost', - edits, + error = await applyFilters( + 'editor.__unstablePreSavePost', + Promise.resolve( false ), options ); } catch ( err ) { @@ -240,25 +236,14 @@ export const savePost = ); } - // Run the hook with legacy unstable name for backward compatibility if ( ! error ) { - try { - await applyFilters( - 'editor.__unstableSavePost', - Promise.resolve(), - options - ); - } catch ( err ) { - error = err; - } - } - - if ( ! error ) { - try { - await doActionAsync( 'editor.savePost', options ); - } catch ( err ) { + await applyFilters( + 'editor.__unstableSavePost', + Promise.resolve(), + options + ).catch( ( err ) => { error = err; - } + } ); } dispatch( { type: 'REQUEST_POST_UPDATE_FINISH', options } );