From 19c63261c9283470ddd1e2547859dc05075d5c5f Mon Sep 17 00:00:00 2001 From: Jarda Snajdr Date: Fri, 2 Aug 2024 12:28:50 +0200 Subject: [PATCH] Stabilize the PreSavePost and SavePost filters --- packages/editor/src/store/actions.js | 35 ++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/packages/editor/src/store/actions.js b/packages/editor/src/store/actions.js index 59faa6b5b73624..a3c2283b831b9e 100644 --- a/packages/editor/src/store/actions.js +++ b/packages/editor/src/store/actions.js @@ -184,7 +184,7 @@ export const savePost = } const previousRecord = select.getCurrentPost(); - const edits = { + let edits = { id: previousRecord.id, ...registry .select( coreStore ) @@ -199,9 +199,9 @@ export const savePost = let error = false; try { - error = await applyFilters( - 'editor.__unstablePreSavePost', - Promise.resolve( false ), + edits = await applyFilters( + 'editor.PreSavePost', + Promise.resolve( edits ), options ); } catch ( err ) { @@ -236,14 +236,29 @@ export const savePost = ); } + // Run the hook with legacy unstable name for backward compatibility if ( ! error ) { - await applyFilters( - 'editor.__unstableSavePost', - Promise.resolve(), - options - ).catch( ( err ) => { + try { + await applyFilters( + 'editor.__unstableSavePost', + Promise.resolve(), + options + ); + } catch ( err ) { error = err; - } ); + } + } + + if ( ! error ) { + try { + await applyFilters( + 'editor.SavePost', + Promise.resolve(), + options + ); + } catch ( err ) { + error = err; + } } dispatch( { type: 'REQUEST_POST_UPDATE_FINISH', options } );