[wp-trac] [WordPress Trac] #54708: Fix block theme featured image preview

WordPress Trac noreply at wordpress.org
Wed Dec 29 21:45:03 UTC 2021


#54708: Fix block theme featured image preview
------------------------------------------------+--------------------------
 Reporter:  adamsilverstein                     |       Owner:
                                                |  adamsilverstein
     Type:  defect (bug)                        |      Status:  assigned
 Priority:  normal                              |   Milestone:  5.9
Component:  General                             |     Version:  trunk
 Severity:  normal                              |  Resolution:
 Keywords:  dev-feedback has-patch 2nd-opinion  |     Focuses:
------------------------------------------------+--------------------------
Description changed by adamsilverstein:

Old description:

> (Improve `_set_preview` for case when autosave missing)
>
> **Problem: Autosaves are deleting when a new autosave is sent with the
> same data. In the block editor, this causes the preview data to be
> missing on previews.
>
> Bug exhibited: When using block themes, post previews do not properly
> display the currently set featured image. Several other data
> transformations are also missing because `_set_preview` exits early when
> it can't locate the autosave.
>
> When investigating an issue with previews in block themes not working
> correctly, I found an underlying bug that prevents autosaves from being
> used correctly for previews in some cases. (See
> [https://github.com/WordPress/gutenberg/pull/37622#issuecomment-1002690803
> PR comment]).
>
> In `src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-
> controller.php` in the `create_post_autosave` function - when the
> autosave sent to the autosave REST endpoint exactly matches the previous
> autosave, the controller **deletes the old autosave revision**, then
> returns an error "There is nothing to save. The autosave and the post
> content are the same."
>
> Deleting the old autosave revision means that later when `src/wp-
> includes/revision.php` `_set_preview` gets called, and it calls
> `wp_get_post_autosave` the autosave is missing, and the preview data
> swaps are not activated.
>
> The end result of this is that currently if you set a preview image using
> a block theme on a published post and preview it, the featured image is
> not displayed correctly. Skipping deleting the previous autosave fixes
> the issue.

New description:

 (Improve `_set_preview` for case when autosave missing)

 **Problem: Autosaves are deleted when a new autosave is sent with the same
 data. In the block editor, this causes the preview data to be missing on
 previews.

 Bug exhibited: When using block themes, post previews do not properly
 display the currently set featured image. Several other data
 transformations are also missing because `_set_preview` exits early when
 it can't locate the autosave.

 When investigating an issue with previews in block themes not working
 correctly, I found an underlying bug that prevents autosaves from being
 used correctly for previews in some cases. (See
 [https://github.com/WordPress/gutenberg/pull/37622#issuecomment-1002690803
 PR comment]).

 In `src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-
 controller.php` in the `create_post_autosave` function - when the autosave
 sent to the autosave REST endpoint exactly matches the previous autosave,
 the controller **deletes the old autosave revision**, then returns an
 error "There is nothing to save. The autosave and the post content are the
 same."

 Deleting the old autosave revision means that later when `src/wp-
 includes/revision.php` `_set_preview` gets called, and it calls
 `wp_get_post_autosave` the autosave is missing, and the preview data swaps
 are not activated.

 The end result of this is that currently if you set a preview image using
 a block theme on a published post and preview it, the featured image is
 not displayed correctly. Skipping deleting the previous autosave fixes the
 issue.

--

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/54708#comment:12>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list