-
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
Fix meta save causing autosave deletion, resulting in preview not displaying unsaved changes #13718
Conversation
Thanks to @noisysocks for being a helping hand in coming up with a strategy for this fix. I do want to look into writing an e2e test for this (if possible), but thought I'd get the fix PR up as it's a fairly high priority one. |
8a26a36
to
ab6952a
Compare
( wasAutosavingPost && wasPreviewingPost && ! isPreviewingPost ) | ||
) | ||
if ( hasMetaBoxes( store.getState() ) ) { | ||
addFilter( |
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.
Does addFilter
prevent multiple filters being registered or could it be worth a call to removeFilter
first, in case this SET_META_BOXES_PER_LOCATIONS
action is called more than once?
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.
Cursory glance at the code and it looks like I should probably add a call to removeFilter
to be safe.
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, otherwise you will add multiple callbacks
This is a very risky change, I'm a bit concerned about introducing this so late in the process.
According to your description, the autosave that was deleted is the one from the step 1, why can't we just show the autosave from step 3 instead when previewing? |
@youknowriad At that stage it's a POST request to post.php with only partial data: gutenberg/packages/edit-post/src/store/effects.js Lines 93 to 117 in 7980d19
The URL looks something like this:
The On the balance of it, I felt like that code would be more complicated to change. |
Even if it's a partial request, it will update the existing post object already saved and create a revision I guess. To clarify I'm not totally against changing the order of the save requests, but I do think it also impacts that code as I wonder if we should still do the autosave removal if we change the order? That said, the approach in the PR has another benefit. As I think if done properly, it could be something we could leverage to fix this too #13413 We may need people familiar with Core PHP to help here so pinging @pento @desrosj @BE-Webdesign |
4d813aa
to
3971ff8
Compare
…n instead of a promise
3971ff8
to
e54f1c8
Compare
#12903 details that some plugin developers have code that depends on the order of the requests, currently detecting when the meta save has completed to trigger a side-effect. That means this PR could cause some breakage. On the other hand, it might also make development using server-side hooks a bit easier, since devs would be able to rely only on the REST API request to determine when a save has occurred. |
I would second from experience that switching the save order would be a consequential change for plugin developers. In my opinion, it would at a minimum deserve a merge into core with related documentation early in a core release cycle. An alternative approach was suggested recently on Trac, which addressed the problem via the That alternative apparently works around the issue in #12617 by avoiding the second If the approach in this PR is chosen -- which still might be the best move, all things considered -- then I think the backwards-compatibility concerns that come with it could be lessened by also offering some comments on the alternative approaches, which I don't think have the same concerns. |
I've looked into rebasing this, but I don't think the solution here is viable any longer. Originally this code used the fact that the effect that handled saving the post was just a simple function that a filter could be applied to. Recently though, that code has been refactored and now a generator function is used to save the post. There might be ways to use a filter here, but I think it's just going to make the code very unusual and the solution even less acceptable. I'll have a look again at possible server-side solutions for the bug. |
Description
Fixes #12617 - when metaboxes are active, the preview does not show unsaved changes to posts.
A quick summary of the cause:
This PR fixes the issue by changing the save order. First save the metaboxes, then the autosave.
It does so by introducing a new filter 'editor.updatePost', which the metabox code (in the edit-post package) uses to defer the post update until after metaboxes have been saved.
How has this been tested?
Expected:
The preview displays the content added in step 4.
Previous Behaviour:
The content added in step 4 wasn't displayed.
Screenshots
Types of changes
Bug fix (non-breaking change which fixes an issue)
Checklist: