-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Only save metaboxes when it's not an autosave #7502
Conversation
Thanks for working on this. Interesting question pops up for me — if we were to want to look at an autosave overhaul in a distant future version of Gutenberg, one where there is no button at all, there's just an autosave that kicks in when a change is detected, we probably wouldn't be able to make that work for metaboxes. In such a future, could we make the button appear explicitly only when metaboxes are present? |
edit-post/store/effects.js
Outdated
@@ -54,10 +54,21 @@ const effects = { | |||
store.dispatch( setMetaBoxSavedData( dataPerLocation ) ); | |||
|
|||
// Saving metaboxes when saving posts | |||
const { isAutosavingPost } = select( 'core/editor' ); | |||
let shouldRequestMetaBoxUpdates = false; | |||
subscribe( onChangeListener( select( 'core/editor' ).isSavingPost, ( isSavingPost ) => { |
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.
I think it's not correct at 100% to use the onChangeListener
to call the listener while also watching for changes in the isAutosavingPost
selector. Maybe we could add support for watching multiple selectors in onChangeListener
or just drop it and use custom logic.
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.
Maybe we could add support for watching multiple selectors in
onChangeListener
or just drop it and use custom logic.
What custom logic would you use?
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.
Just checking both selector results without extracting the logic in a utility like onChangeListener
let wasSavingPost = select( 'core/editor' ).isSavingPost();
let wasAutosavingPost = select( 'core/editor' ). isAutosavingPost();
subscribe( () => {
const isSavingPost = select( 'core/editor' ).isSavingPost();
const isAutosavingPost = select( 'core/editor' ).isSavingPost();
const shouldTriggerMetaboxesSave = wasSavingPost && ! wasAutosavingPost && ! isSavingPost && !isAutosavingPost; // not certain about this check entirely
// Restore
wasSavingPost = isSavingPost;
wasAutosavingPost = isAutosavingPost;
// trigger
if ( shouldTriggerMetaboxesSave ) {
// do something.
}
} )
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.
Do you think this custom logic is better than what I have? At first glance, what I have already seems more precise.
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 not about better or worse, it's about the fact that we want to run the listener whenever the value of isAutosavingPost
's selector changes. In your code it's not the case, if for some reason (even if it's not possible at the moment) isSavingPost
doesn't change but isAutosavingPost
does, your listener is not being executed and I don't think it's intentional.
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.
subscribe( () => {
fires for every change, which seems too frequent. Is there an alternative you'd suggest?
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.
There is none actually, we can bundle the multiple selectors support into onChangeListener
. Maybe by supporting an "array of selectors" instead of a given "selector" as an argument passed to onChangeListener
but in terms of performance, it doesn't change anything compared to my logic above.
That's how redux work in general, a unique eventEmitter
calling all its listeners, It has proved to scale well in several contexts.
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.
Ok, updated in ed79968
bca2cd2
to
652d0a5
Compare
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.
LGTM 👍 Thanks for the updates
Some previous context / discussion at #6257 (comment)
|
@aduth Does your comment block merge? |
Nope. |
* 'master' of https://github.com/WordPress/gutenberg: (69 commits) fix: Show permalink editor in editor (WordPress#7494) Fix text wrapping in Firefox. (WordPress#7472) Try another approach to fixing the sibling inserter in Firefox (WordPress#7530) fix: Improve "add block" text in NUX onboarding (WordPress#7511) Implement core style of including revisions data on Post response (WordPress#7495) Testing: Add e2e test for PluginPostStatusInfo (WordPress#7284) Add end 2 end test for sidebar behaviours on mobile and desktop. (WordPress#6877) Only save metaboxes when it's not an autosave (WordPress#7502) Fix broken links in documentation (WordPress#7532) Remove post type 'viewable' compatibility shim (WordPress#7496) Fix typo. (WordPress#7528) Blocks: Remove wrapping div from paragraph block (WordPress#7477) fix: change import for InnerBlocks (WordPress#7484) Polish library just a teeeeensy bit (WordPress#7522) feat: Add snapshot update script (WordPress#7514) Display server error message when one exists (WordPress#7434) Fix issues with gallery in IE11. (WordPress#7465) Polish region focus style (WordPress#7459) Fix IE11 formatting toolbar visibility (WordPress#7413) Update plugin version to 3.1. (WordPress#7402) ...
Description
Improves autosave behavior to disable accidental saving of metaboxes. Metaboxes should only be saved on full saves.
See conversation in https://wordpress.slack.com/archives/C02QB2JS7/p1529698040000346
Fixes #7135
How has this been tested?
When the revision UI appears in Post Settings after step 5, it should indicate 2 revisions, not 4:
Previously, the two autosave events would trigger full save events / revision creation.
Screenshots
Types of changes
Bug fix.
Checklist: