Skip to content
Prev Previous commit
Next Next commit
Rename the action to editor.__unstableSavePost
  • Loading branch information
jsnajdr committed Jul 10, 2023
commit 7376e295061ff49e7cbcc685b063797821fd37bc
2 changes: 1 addition & 1 deletion packages/edit-post/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ export const initializeMetaBoxes =

// Save metaboxes on save completion, except for autosaves.
addFilter(
'editor.SavePost',
'editor.__unstableSavePost',
'core/edit-post/save-metaboxes',
( previous, options ) =>
previous.then( () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/editor/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export const savePost =

if ( ! error ) {
await applyFilters(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks more like an "action" than a filter, the only reason it's a filter is because we want it to be async. This makes me wonder if we shouldn't just support "async actions" instead.

await doAction( 'editor.SavePost' )

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, webpack also distinguishes between sync and async hooks, and it's a good thing to have in a JavaScript project.

We could introduce a new doAsyncAction API which is similar to doAction but awaits between calls and aborts on a rejected promise. The addAction API could stay the same. The entire difference is in how actions are called, not how they are registered.

If the caller makes a mistake and calls doAction instead of doAsyncAction, we could issue a warning in case an action callback returns a promise (or thenable in general) that would be ignored by doAction.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious why this needs to be async though, is the thought that options might get changed? if so pass that to the filter, if not just use action without async?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's async because saving post is in principle async. It involves a REST request for saving the post, and we wait for the response etc. And the callbacks registered with the __unstableSavePost hook typically want to do some additional async work related to saving. For example, the edit-post package registers a callback for saving metaboxes. I.e., in addition to the standard post saving, it will go through metabox forms on the page, and save their fields with a separate POST request to the server.

'editor.SavePost',
'editor.__unstableSavePost',
Promise.resolve(),
options
).catch( ( err ) => {
Expand Down