WordPress.org

Make WordPress Core

Opened 10 months ago

Last modified 9 months ago

#45768 new defect (bug)

Content before editing are displayed in the preview

Reported by: tmatsuur Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Editor Keywords:
Focuses: Cc:
PR Number:

Description

With the widget(meta box) added to the editing screen, if you edit the published post and display the preview screen, the contents before editing will be displayed.

This problem can be confirmed by adding the following code to the functions.php of the theme.

function meta_box_test() {
}
function admin_add_meta_box_test() {
	add_meta_box( 'meta_box_test', 'test', 'meta_box_test', 'post', 'side', 'high' );
}
add_action( 'admin_init', 'admin_add_meta_box_test' );

WordPress: 5.0.2

Theme: Twenty Nineteen

Plugin: nothing

This problem may be the same cause as #45654, but I posted it because the symptoms are different.

Change History (7)

#1 follow-up: @swissspidy
10 months ago

Related: #45532.

#2 in reply to: ↑ 1 @tmatsuur
10 months ago

Replying to swissspidy:

Related: #45532.

It is the same as the symptom of # 45532.

I noticed this problem with updating the Classic Editor plugin.

When I investigated this problem, the same symptoms were confirmed in other plugins.
In the process of narrowing down the cause, commenting out the add_meta_box function got the preview normal.
After that I prepared a new simple environment and tried the code above.

I hope to solve this problem.

#3 @tmatsuur
9 months ago

I traced the request at preview.

1.Press the preview button to request automatic save.

POST /wp-json/wp/v2/posts/299/autosaves?_locale=user

2.Only if there are any meta boxes, there was a next request immediately after the above request.

POST /wp-admin/post.php?post=299&action=edit&meta-box-loader=1&_wpnonce=a537ca4521&_locale=user

3.Subsequently, this request will be redirected to the following URL (/wp-admin/post.php:213).

GET /wp-admin/post.php?post=299&action=edit&message=4

4.This request seems to delete the autosaved post information for preview (/wp-admin/edit-form-blocks.php:301).
As a result, the contents before editing are displayed on the preview window.

#4 @aaemnnosttv
9 months ago

From what I can see the problem is with this request:

POST /wp-admin/post.php?post=299&action=edit&meta-box-loader=1&_wpnonce=a537ca4521&_locale=user

The action in the POST request body is actually editpost which takes precedence over the action=edit in the query string since it is a POST request. This action performs a different function in wp-admin/post.php, which invokes edit_post() instead of simply loading the editor (and in turn meta boxes in this case).

This triggers the post modified date of the post to be updated and causes the autosave required for the preview to be deleted when its modified date is compared to its parent. By the time the preview loads, the autosave may be deleted but I've seen it get created again in the background which makes this into a bit of a nasty race condition.

#5 follow-up: @dlh
9 months ago

Related: #46076 and GB-12617.

#6 in reply to: ↑ 5 ; follow-up: @tmatsuur
9 months ago

Replying to dlh:

Related: #46076 and GB-12617.

Thank you for valuable information.

#7 in reply to: ↑ 6 @tmatsuur
9 months ago

In an environment using the classic editor plug-in, I respond interimly with the following modifications.

redirect_post function ( /wp-admin/includes/post.php )

function redirect_post($post_id = '') {
	if ( isset( $_GET['meta-box-loader'] ) ) {
		exit;
	}

	:

With this fix, the preview is functioning properly.

Note: See TracTickets for help on using tickets.