Skip to content

Preview fails to display edits on published posts when metaboxes are visible in Gutenberg #12617

Closed

Description

@davidAIS

The preview button in the Gutenberg editor in Wordpress 5 RC3 doesn't display unsaved edits.

Reproduced by creating and saving a page, then edit the page and click preview. The preview page only shows the original page and not the additional edits.

Activity

  1. added
    Needs Testing
    on Dec 5, 2018
  2. designsimply commented on Dec 5, 2018

    @designsimply
    Member

    I did a quick test with WordPress 5.0-RC3-43967 and do not see the same problem.

    preview-test

    Can you tell me a little more about your testing?

    Are you testing previews of a draft or a published post?

    Did you press "Preview" each time or save and try reloading a previously opened preview?

    Are you making changes to the post content or are you making changes to things like post settings and meta data?

    Would it be possible for you to provide a short list of exact testing steps?

  3. added
    [Status] Needs More Info
    [Type] Help Request
    and removed
    Needs Testing
    on Dec 5, 2018
  4. davidAIS commented on Dec 6, 2018

    @davidAIS
    Author
  5. designsimply commented on Dec 6, 2018

    @designsimply
    Member

    Thanks for the clarification! There are actually more scenarios than you might think if you consider autosaves vs "Save Draft" and draft vs published and post vs page and all the combinations thereof. My test had 3 cases: new post -> preview, edit draft -> preview, save & publish then edit then preview.

    Sounds like your testing steps are:

    1. Create page.
    2. Save.
    3. Go to Pages list.
    4. Re-open page.
    5. Make an edit to the text.
    6. Click Preview.

    Testing note: since publishing wasn't mentioned, try with a draft as well as a published page.

  6. davidAIS commented on Dec 6, 2018

    @davidAIS
    Author

    I'm sure there are lots of scenarios.

    This is mine.

    I have a previously published page (as it happens created before the site was updated to Wordpress 5) that now requires an update.

    Having made the edit, if I click Preview the update is not displayed. It's therefore not possible to check the progress of a set up updates on the page without publishing the page.

    That is not a safe way to edit the content and therefore renders the new editor unusable in this real world scenario.

  7. designsimply commented on Dec 6, 2018

    @designsimply
    Member

    I ran another test after upgrading a different site to WordPress 5.0 and I can still see previews working normally. I tested with Firefox 63.0.3 on macOS 10.13.6 and I tried with a draft as well as with a previously published post. Please have a look and let me know if I'm still missing anything from my testing steps!

    12617-44s

    5.0 was just released, so I suggest updating and uninstalling the Gutenberg plugin if you have it (you don't need it any more with 5.0). If you're still having trouble after that, I would suggest checking for a plugin or theme conflict by temporarily disabling all plugins and switching to the default theme as a test to see if the problem still happens under those conditions. If your test setup was already like that, we'll need to try to think of what else could be the source of the trouble in your case.

    Sometimes OS or browser version matter for cases like this. I tested with a Mac, and if you let me know you're OS and browser versions, I can test again from a more similar setup to you.

  8. designsimply commented on Dec 12, 2018

    @designsimply
    Member

    Thanks @slimmilkduds!

    I also just closed #12717 as a duplicate and wanted to note it also includes a video.

  9. added
    Needs Testing
    on Dec 12, 2018
  10. davidAIS commented on Dec 12, 2018

    @davidAIS
    Author

    Re:

    5.0 was just released, so I suggest updating and uninstalling the Gutenberg plugin if you have it (you don't need it any more with 5.0). If you're still having trouble after that, I would suggest checking for a plugin or theme conflict by temporarily disabling all plugins and switching to the default theme as a test to see if the problem still happens under those conditions. If your test setup was already like that, we'll need to try to think of what else could be the source of the trouble in your case.

    Repeating the test with 5.0, without plugins and using a default theme made no difference to the outcome. I am still not seeing the edits when I click the preview button.

    For info I'm using Chrome 70.0.3538.110 and MacOS 10.13.6

    I note that you've closed ticket #12717

    In fact that sheds additional light on this and I can confirm the findings in that ticket. Initially the preview button doesn't display the edited contents as I reported. But if you wait 5-10 seconds and then reload the preview page then it does display the edited content.

    So as soup-bowl reported in #127171 - it's not completely broken. But in my view just broken enough to make it unusable.

  11. xy0 commented on Dec 13, 2018

    @xy0

    I am experiencing the exact same behavior as @davidAIS. I don't think this started right away after 5, maybe the 5.0.1 update did it. Refreshing the preview after a few seconds does indeed work.

  12. amycmcc commented on Dec 14, 2018

    @amycmcc

    I am experiencing the exact same issue. I am using chrome, and windows 10. I set up a staging site, deactivated all plugins, and activated the default theme. I edit a page, that is published. Then I press preview and it does not show my edits. If I wait and refresh it will show my edits, or if I publish the post, it will also display my edits.

  13. 132 remaining items

  14. earnjam commented on May 3, 2019

    @earnjam
    Contributor

    @harmancheema93 have you tested this with the latest version of the Gutenberg plugin, or with the WordPress 5.2 release candidate?

    The fix for this has been merged, but will not be released in WordPress core until 5.2 comes out next week.

  15. jg314 commented on May 30, 2019

    @jg314
    Contributor

    In case this is helpful to anyone, updating to WordPress 5.2.1 fixed this issue for us.

  16. mj-watts commented on Jun 4, 2019

    @mj-watts

    We are still having the issue, just going to add my bit as slightly weird toggling thing going on where it toggles the content on and off, but long and short is that preview is not working for published pages using advanced custom fields, but is working for draft pages:

    Using:

    • Advanced Custom Fields Pro 5.8.1
    • WordPress 5.2.1

    Steps:

    1. Clicking preview on a published page will show no content (content is in ACF, no WordPress default blocks used), header and footer does show.
    2. Clicking preview again will bring the content from ACF this time but without content changes.
    3. Clicking preview again will then show the page to have no content. Like it toggles the ACF content on and off.

    Checked that the URL is same (?preview_id=27&preview_nonce=abd991463b&preview=true) and is.

    It works fine for pages in draft mode.

  17. talldan commented on Jun 5, 2019

    @talldan
    Contributor

    Hi @altescape, I was unable to reproduce on a published page using a custom field. Would you be able to create a separate issue for this as it seems like the problem you're having is different to the original report (and this issue is now closed).

    content is in ACF, no WordPress default blocks used

    I'm not sure what this means, it'd be good if you could add some extra steps about how you create the post when creating a separate issue.

    Thanks.

  18. vesaraiskila commented on Jun 5, 2019

    @vesaraiskila

    This has still occurred for me, although not every time I edit a published post. However, selecting "Preview" for the second or third time has shown the edited version.

  19. kaij commented on Jun 10, 2019

    @kaij

    @altescape Having exactly the same problem (tested ACF 5.8.1 and Wordpress 5.2.1). Did you find a solution or create a new issue somewhere? I already contacted the ACF developers but they could not reproduce the issue (they said).

    • Preview saves a revision which erases all ACF fields(!), so - of course - it will show an empty page. This can be seen in the page revisions.
    • Using preview on unpublished posts or pages works as expected, just if you try to preview an already published page, it will have all ACF fields erased
    • Autosave will also remove all ACF fields content(!)

    I know this issue is closed, but it could very well be that these problems are somehow related. Any help is appreciated.

  20. mj-watts commented on Jun 11, 2019

    @mj-watts

    @kaij Hi,

    I opened another issue #16006 see my description there

  21. Bt4ok commented on Dec 25, 2019

    @Bt4ok

    I fixed my website in the following way.

    1. not change post_modified_gmt if REQUEST_META_BOX_UPDATES action
    add_filter( 'wp_insert_post_data', function ( $data ) {
    	if ( isset( $_GET['meta-box-loader'] ) ) {
    		unset( $data["post_modified"] );
    		unset( $data["post_modified_gmt"] );
    	}
    
    	return $data;
    } );
    

    or

    1. set autosave's post_modified_gmt = original post's post_modified_gmt +1 sec
    add_action( 'save_post', function ( $post_id, $post ) {
    	if ( isset( $_GET['meta-box-loader'] ) ) {
    		$autosave = wp_get_post_autosave( $post_id, get_current_user_id() );
    		if ( $autosave ) {
    			$filter = function ( $data ) use ( &$filter, $post ) {
    				remove_filter( 'wp_insert_post_data', $filter );
    				$data["post_modified"]     = gmdate( 'Y-m-d H:i:s', strtotime( $post->post_modified ) + 1 );
    				$data["post_modified_gmt"] = gmdate( 'Y-m-d H:i:s', strtotime( $post->post_modified_gmt ) + 1 );
    
    				return $data;
    			};
    			add_filter( 'wp_insert_post_data', $filter );
    			wp_update_post( $autosave );
    		}
    	}
    }, 10, 2 );
    

    Where did you add the code? cause I'm trying to insert into my theme functions.php but nothing happened

  22. Armarsh commented on Dec 26, 2019

    @Armarsh

    @Bt4ok -- the code was for an earlier version of Wordpress -- the issue with post previews and metaboxes that is described in this thread was resolved quite some time ago with a Wordpress update. If you are having a problem now you should report an open a new issue. (If you'll note, this thread was marked closed)

  23. Bt4ok commented on Dec 26, 2019

    @Bt4ok

    @Bt4ok -- the code was for an earlier version of Wordpress -- the issue with post previews and metaboxes that is described in this thread was resolved quite some time ago with a Wordpress update. If you are having a problem now you should report an open a new issue. (If you'll note, this thread was marked closed)

    Yes still have the problem
    Clear wp install 5.3.2
    Built-in Gutenberg
    ACF 5.8.7

    Problem is still present
    No preview updates of changes in advanced custom fields forms if post is published.
    Tried to install gutenberg as plugin - received the same problem.
    Also trough time preview page get empty fields. 1click -preview - fields are empty, 2nd click - filled (saved post version without changes), 3rd-emptry, 4th - filled (without changes).
    Tested on built in twentytwenty theme.

    May be need to rollback for previous wp version or acf?

  24. vesaraiskila commented on Dec 26, 2019

    @vesaraiskila

    This preview issue was solved for me months ago, but recently I've been experiencing this:

    Auto-saving makes the preview window refresh itself continuously and frequently, which is really frustrating when one is reading through the text to see if everything is ok. After each refresh, the page is returned to the top, and one has to scroll back to the place that one was reading.

  25. Bt4ok commented on Dec 26, 2019

    @Bt4ok

    #12617 (comment)

    Thank you. The problem was resolved by rollback to wp 5.0 core version. Preview working as expected for drafts and published posts (including changes in ACF fields), but ACF fields automatically saved when I press the "preview" button.

  26. vesaraiskila commented on Dec 26, 2019

    @vesaraiskila

    Just to be sure: is the constant realoading of the preview window, absent any modifications, "working as expected"? It really makes concentrated reading difficult.

  27. Bt4ok commented on Dec 26, 2019

    @Bt4ok

    My english isn't very good, sorry.
    I mean. Rolled back to wp 5.0. Entered post edit page, made some changes in acf fields or in the content section. Press "preview" and see all made changes! No matter is post published or is draft.

    Only a problem is if make some changes in acf fields and press "preview" - after pressing the button I get updated (saved) post with my last changes in acf forms. Changes in content presented in "preview" mode but not saved until I press "update".

    For example. Open post for edit -> make some changes to ACF fields and to post content (or title, etc.), press preview - I see all changes (acf+content). Close edit post page without pressing update but get new version post with old content and changed acf. If don't close post edit page without saving and press update, get updated post with all changes in acf and content.

    I hope, my answer is understandable

  28. hoangemini commented on May 27, 2020

    @hoangemini

    I fixed my website in the following way.

    1. not change post_modified_gmt if REQUEST_META_BOX_UPDATES action
    add_filter( 'wp_insert_post_data', function ( $data ) {
    	if ( isset( $_GET['meta-box-loader'] ) ) {
    		unset( $data["post_modified"] );
    		unset( $data["post_modified_gmt"] );
    	}
    
    	return $data;
    } );
    

    or

    1. set autosave's post_modified_gmt = original post's post_modified_gmt +1 sec
    add_action( 'save_post', function ( $post_id, $post ) {
    	if ( isset( $_GET['meta-box-loader'] ) ) {
    		$autosave = wp_get_post_autosave( $post_id, get_current_user_id() );
    		if ( $autosave ) {
    			$filter = function ( $data ) use ( &$filter, $post ) {
    				remove_filter( 'wp_insert_post_data', $filter );
    				$data["post_modified"]     = gmdate( 'Y-m-d H:i:s', strtotime( $post->post_modified ) + 1 );
    				$data["post_modified_gmt"] = gmdate( 'Y-m-d H:i:s', strtotime( $post->post_modified_gmt ) + 1 );
    
    				return $data;
    			};
    			add_filter( 'wp_insert_post_data', $filter );
    			wp_update_post( $autosave );
    		}
    	}
    }, 10, 2 );
    

    Where did you add the code? cause I'm trying to insert into my theme functions.php but nothing happened

    I have the same question

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

[Feature] Meta Boxes[Feature] Saving[Priority] High[Type] Plugin Interoperability

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions