gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

Preview not working with Published Pages

Open mj-watts opened this issue 7 years ago • 66 comments

Describe the bug

I'm using a fresh install of the latest WordPress (v5.2.1) and latest Advanced Custom Fields Pro (v5.8.1), with no other plugins installed.

  • Once a page is published, changing and previewing content does not work.
  • Furthermore it hides the ACF content, but when clicking preview again shows the content - but is an older version of the content, clicking preview again then hides the content and so on.

It should be noted that when a page is not published it works correctly. If I switch the page back to draft the preview works correctly.

To reproduce Steps to reproduce the behavior:

  1. Install ACF Pro 5.8.1 and create a field group with a text field called title, and show it on all posts that are pages (I can provide export of this code if needed)
  2. Add <?php the_field('title'); ?> after line 17 of template-parts/content/content-page.php of twentynineteen theme
  3. Create a page and write something in ACF Title like 'This is an ACF Title', then preview
  4. Should see 'This is an ACF Title' on page
  5. Then publish page
  6. Change content of ACF Title to 'This is an ACF Title 123' and click preview
  7. You should see no ACF Title
  8. Then click preview again
  9. Should see 'This is an ACF Title' (noting that '123' had not been added)
  10. Click preview again
  11. Should not see ACF Title
  12. You can click preview again and again to toggle hide/show of ACF content

Expected behavior

  • A up-to-date preview of the changed Advanced Custom Fields content.
  • When previewing the page multiple times WordPress should not be toggling showing/hiding of Advanced Custom Fields content

Screenshots

Preview working on unpublished pages:

preview-on-unpublished-works-lg

Preview not working on published pages:

preview-on-published-not-working

Previewing multiple times toggles the content on and off:

preview-on-published-toggles-content

Desktop (please complete the following information):

  • OS: OSX
  • Browser chrome
  • Version [74.0.3729.169 (Official Build) (64-bit)]

Additional context

  • Please add the version of Gutenberg you are using in the description: Whatever is used in WordPress 5.2.1
  • Here is a JSON export so the custom fields can be easily recreated, just save as a file and import using Custom Fields > Tools > Import Field Groups:
[
    {
        "key": "group_5cf7bf8106d4d",
        "title": "Page",
        "fields": [
            {
                "key": "field_5cf7bf875b9ca",
                "label": "Title",
                "name": "title",
                "type": "text",
                "instructions": "",
                "required": 0,
                "conditional_logic": 0,
                "wrapper": {
                    "width": "",
                    "class": "",
                    "id": ""
                },
                "default_value": "",
                "placeholder": "",
                "prepend": "",
                "append": "",
                "maxlength": ""
            }
        ],
        "location": [
            [
                {
                    "param": "post_type",
                    "operator": "==",
                    "value": "page"
                }
            ]
        ],
        "menu_order": 0,
        "position": "acf_after_title",
        "style": "default",
        "label_placement": "top",
        "instruction_placement": "label",
        "hide_on_screen": [
            "permalink",
            "the_content",
            "excerpt",
            "discussion",
            "comments",
            "revisions",
            "slug",
            "author",
            "format",
            "page_attributes",
            "featured_image",
            "categories",
            "tags",
            "send-trackbacks"
        ],
        "active": true,
        "description": ""
    }
]

mj-watts avatar Jun 05 '19 13:06 mj-watts

Thanks for the details @altescape, really great bug report.

Out of interest, if you save the post (cmd+s/ctrl+s) before clicking preview do you see the latest changes? If so, that might be a (not ideal) workaround.

The issue might be that the fix (#14877) for the previous preview issue (#12617) involved disabling the saving of metaboxes when the preview button is clicked. Unfortunately the metabox save process was causing post revisions to be deleted.

I created an issue https://github.com/WordPress/gutenberg/issues/14900 to consider ways to re-enable metabox saving when previewing. It's not a simple thing to fix unfortunately.

talldan avatar Jun 11 '19 09:06 talldan

Thanks for the heads up @talldan - I'll have a look also at the issue you created.

cmd+s didn't work, WordPress only allows saving when I've edited WordPress blocks and not metaboxes, thank you for the tip though - I'll wait for further updates regarding this.

mj-watts avatar Jun 12 '19 15:06 mj-watts

I am seeing a similar issue without ACF. Preview is not working on an already-published post if an autosave of the post exists. Here are the steps to reproduce:

  1. Create a post.
  2. Publish the post.
  3. Close the post editor, and then re-open the post.
  4. Make a change to the post, and then close the editor without saving. You should see an alert that asks if you want to leave the page. Click the "Leave" button to leave the page.
  5. Re-open the post again, and note the "There is an autosave..." message at the top of the editor.
  6. Make a different change to the post, and click the "Preview" button.
  7. Note that the preview does not show the change(s) made in step 6.

The preview works for me when an autosave does not exist, but it does not work when an autosave exists.

corywebb avatar Jun 17 '19 20:06 corywebb

@altescape is there an equivalent ACF support post? It'd be good to cross reference and debug faster. It's possible this is an ACF specific issue, but if it isn't it'd be good for debugging to track down where things go wrong and improve Gutenberg accordingly

tomjn avatar Jun 18 '19 10:06 tomjn

@tomjn Most recent thing I've seen from ACF is https://github.com/AdvancedCustomFields/acf/issues/186

amanda-t avatar Jun 19 '19 18:06 amanda-t

@tomjn this issue isn't just happening with ACF. See my previous comment above: https://github.com/WordPress/gutenberg/issues/16006#issuecomment-502834583

corywebb avatar Jul 01 '19 15:07 corywebb

This issue is occurring for a WordPress VIP client. If anyone within the Automattic Gutenberg team are able to look at this, it would be appreciated.

dartiss avatar Jul 02 '19 07:07 dartiss

This bug is still occurring for me.

Using Twenty-Nineteen with 5.2.2 with ACF Pro 5.8.2

jweston491 avatar Jul 18 '19 16:07 jweston491

This bug till occurring for me, only in preview of published posts. Using Sage Roots theme (customized by me), WP 5.2.2 e ACF Pro 5.8.2. Both in local server and online.

andreabrunato avatar Jul 31 '19 14:07 andreabrunato

Still occurring for me. Need to switch back to classic editor.

newhope avatar Aug 01 '19 07:08 newhope

Can confirm, happening with me.

cyberphen avatar Aug 06 '19 10:08 cyberphen

Adding my voice, occurring to me as well. Wordpress 5.2.2, ACF Pro 5.8.3.

I solved the problem temporarily by installing and activating Disable Gutenberg plugin, but as I would like to be able to use both ACF and Blocks, it's not a long-term solution.

ejke avatar Aug 13 '19 10:08 ejke

Experiencing same issue as well.

atomiccherry avatar Aug 21 '19 23:08 atomiccherry

Also experiencing this issue. Edit: ejke's solution of installing Disable Gutenberg plugin worked for me.

df165 avatar Sep 27 '19 15:09 df165

A few of us are taking a look at this at WordCamp US Contributor Day. We're able to replicate this issue in a number of scenarios within WordPress 5.2.4.

  • We tested with both an Advanced Custom Fields meta field, but also with a generic meta field added via add_meta_box().
  • We tested with the Gutenberg plugin v6.8.0 both activated and deactivated.

In every case, the preview works correctly when the post is a draft, but once published, the preview doesn't update the meta field content.

jg314 avatar Nov 03 '19 17:11 jg314

Hey, I also have this problem. If I enable Classic Editor the preview works properly but when using Gutenberg the preview does not update custom fields if the post has been published.

In my opinion, Gutenberg should also save post meta changes when creating a preview as it worked before.

While "Just make everything a block" is probably the "Gutenberg way" of solving things, it doesn't work in all cases. Let's say you have a custom post type called "Event" and you want to use Gutenberg editor with it. You probably want custom fields called start_time and end_time so you can properly query the posts elsewhere on your site. You also probably want to show these fields in the post template. If you would save this data into blocks, it's impossible to query since it's stored as JSON in the post content.

So this bug prevents using preview properly when using custom fields and Gutenberg together.

joppuyo avatar Apr 01 '20 09:04 joppuyo

This longstanding bug still exists in April 2020: Changes to custom fields are not reflected when previewing a published post. I tested with WP 5.4, 2020 theme and all plugins disabled.

Although this bug report specifically mentions the ACF plugin, it affects all custom fields.

The only "solution" I can find is to install the Classic Editor plugin.

jnicol avatar Apr 09 '20 04:04 jnicol

Actually, it's my post content updates that are not showing in the preview. It's really weird and creates a lot of friction in the workflow.

Solution for now: if I save and refresh the current /wp-admin/post.php?post=[POSTID]&action=edit page, the preview works again, until next time. Sigh.

hubertnguyen avatar Apr 22 '20 00:04 hubertnguyen

Is there any update on this issue? Any workaround?

It's been a while..

thomascharbit avatar Apr 24 '20 10:04 thomascharbit

Seeing this with WP5.4. Installing the Classic Editor plugin worked for us.

KevinRay avatar Apr 27 '20 14:04 KevinRay