-
Notifications
You must be signed in to change notification settings - Fork 4.7k
PostPreviewButton: rewrite to functional, avoid state transitions in lifecycles #44971
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9b9d188
PostPreviewButton: rewrite to functional, avoid state transitions in …
jsnajdr 56f6c59
PreviewOptions: close dropdown after opening external preview
jsnajdr f524989
Move metaboxes save into a hook in savePost
jsnajdr 92eda2f
Make isSavingPost true during entire save, not only when saving the e…
jsnajdr df7ff3e
Remove forceIsSaving and forcePreviewLink props: isSavingPost returns…
jsnajdr e00da35
Fix unit tests for isEditedPostAutosaveable and isSavingPost
jsnajdr 69e8c5c
Fix PostPreviewButton unit tests
jsnajdr 7376e29
Rename the action to editor.__unstableSavePost
jsnajdr df880bc
Remove the 'disabled when saving metaboxes' e2e test
jsnajdr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Rename the action to editor.__unstableSavePost
- Loading branch information
commit 7376e295061ff49e7cbcc685b063797821fd37bc
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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' )There was a problem hiding this comment.
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
doAsyncActionAPI which is similar todoActionbut awaits between calls and aborts on a rejected promise. TheaddActionAPI 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
doActioninstead ofdoAsyncAction, we could issue a warning in case an action callback returns a promise (or thenable in general) that would be ignored bydoAction.There was a problem hiding this comment.
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
optionsmight get changed? if so pass that to the filter, if not just use action without async?There was a problem hiding this comment.
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
__unstableSavePosthook typically want to do some additional async work related to saving. For example, theedit-postpackage 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.