Make WordPress Core

Opened 6 weeks ago

Last modified 6 days ago

#52038 reopened defect (bug)

Issue in WooCommerce with wp_editor() after update to WP 5.6

Reported by: rodrigosprimo Owned by: azaozz
Milestone: 5.6.1 Priority: normal
Severity: normal Version:
Component: General Keywords: has-patch needs-testing fixed-major
Focuses: Cc:


I'm opening this ticket because in WooCommerce we are seeing an issue that might be caused by a change in WP 5.6. In wp-admin, if a user opens a product page (products are a custom post type) and then click any link to go to another page, they get a "Changes you made may not be saved" alert even if they haven't made any changes.

This error seems to be triggered by TinyMCE. We are able to reproduce this problem when running WP 5.6, but not when running previous versions of WP. I was not able to determine exactly which WP commit introduced this problem using git bisect, but that could be because I'm not super familiar with the WP build step.

The problem seems to be related to the call below that WooCommerce makes to wp_editor():


I'm inclined to think this is a bug in WP given that the editor is being flagged as dirty and an alert is displayed to the user even when the user didn't change anything. And also given that this is happening when using WP 5.6 but not WP 5.5. That being said, I'm not sure as I couldn't identify the commit that introduced this issue to further investigate it.

Here is the corresponding issue in the WooCommerce GitHub repository: https://github.com/woocommerce/woocommerce/issues/28557

Steps to reproduce the bug:

  1. Running WP 5.6, install and activate WooCommerce
  2. In the admin, go to Products > Add new. Alternatively, you can import sample products, go to the list of products, and open the page to edit one of them.
  3. Without making any changes, click on a different link in the menu. See the alert saying that changes may not be saved.
  4. Switch to WP 5.5, repeated the steps above and see that there is no alert when leaving the product edit page.

Attachments (3)

excerpt.png (83.6 KB) - added by jonathanstegall 5 weeks ago.
Screenshot of post edit screen with a wp_editor field and the JavaScript change alert
52038.diff (3.6 KB) - added by azaozz 5 weeks ago.
metalcoffee-52028-testing.gif (2.2 MB) - added by metalandcoffee 6 days ago.
Tested on WordPress 5.7-alpha-49644-src.

Change History (18)

#1 @jonathanstegall
5 weeks ago

I think this bug is more widespread than just Woocommerce. I've also seen it in CMB2 and in the Advanced Post Excerpt plugin on a clean install of WordPress 5.6.

I have seen that if I'm on a post type that has the Block Editor enabled, wp_editor does not seem to have the same problem.

Last edited 5 weeks ago by jonathanstegall (previous) (diff)

5 weeks ago

Screenshot of post edit screen with a wp_editor field and the JavaScript change alert

#2 @ifnoob
5 weeks ago

Again, I'm suffering from the same symptoms as my own custom posts, including WooCommerce. Other plugins also have symptoms.

#3 @kevin940726
5 weeks ago

#52080 was marked as a duplicate.

#4 @azaozz
5 weeks ago

Screencapture gif from 52080:


#5 @azaozz
5 weeks ago

  • Keywords has-patch needs-testing added

Think I got to the bottom of it, at least for beforeunload. Problem is somewhat related to upstream. The way the (old) autosave code works is by relying on several things/events to happen in the right order when the page is loading and when unloading (I'm surprised it worked well for so many years). Seems after the last TinyMCE update that order changes sometimes.

In 52038.diff:

  • Update the autosave.server.postChanged() function to specifically look at instances of TinyMCE for content and excerpt.
  • Prefer that function when triggering the AYS on beforeunload on the old Edit Post screen (in post.js).

Please test!

Should work correctly with all possible combinations of Visual and Text tabs for both the content and excerpt. It's still possible that the "The backup of this post in your browser..." message may get triggered when reloading the page, but that would require quite larger fix, not suitable for a dot version.

#6 @azaozz
5 weeks ago

  • Milestone changed from Awaiting Review to 5.6.1

5 weeks ago

#7 follow-up: @rodrigosprimo
5 weeks ago

Thanks for working on this, @azaozz. I tested and can confirm that your patch fixes the issue that we are seeing on the WooCommerce product pages.

#8 in reply to: ↑ 7 @azaozz
5 weeks ago

Replying to rodrigosprimo:

Thanks for testing!

Should fix all cases when there is a TinyMCE instance on the excerpt textarea. Going to commit it to trunk hoping it will get some more testing as it touches on showing the "Are you sure" message for the content editor too.

Last edited 5 weeks ago by azaozz (previous) (diff)

#9 @azaozz
5 weeks ago

  • Owner set to azaozz
  • Resolution set to fixed
  • Status changed from new to closed

In 49807:

Editor: Fix improper triggering of the "Are you sure" prompt when navigating away from the old, "classic" Edit Post screen and there are no changes. Was triggered when there is an instance of TinyMCE in the Excerpt postbox.

Props rodrigosprimo, jonathanstegall, kevin940726, azaozz.
Fixes #52038.

#10 @azaozz
5 weeks ago

  • Keywords fixed-major added
  • Resolution fixed deleted
  • Status changed from closed to reopened

Reopen for merging to 5.6.1.

Ideally this would get some more testing with and without TinyMCE in the Excerpt postbox.

#11 @ifnoob
5 weeks ago

Thank you for the patch. afterwards,
If you use the custom post type after patching, you will still have symptoms.

$args = array(
     'label'                 => __( 'Post List', '' ),
      'labels'                => $labels,
      'supports'              => array( 'title','editor' ),
      'show_in_rest'          => true,  // Gutenberg Editor ON
Last edited 4 weeks ago by SergeyBiryukov (previous) (diff)

This ticket was mentioned in Slack in #forums by timothybjacobs. View the logs.

3 weeks ago

This ticket was mentioned in Slack in #core by monikarao. View the logs.

6 days ago

This ticket was mentioned in Slack in #core by monikarao. View the logs.

6 days ago

#15 @metalandcoffee
6 days ago

I also tested this patch and can confirm that it fixes the issue. I am no longer seeing the "changes may not be saved" alert.

@ifnoob - can you please provide steps to reproduce since you are still seeing this issue on a different use case?

6 days ago

Tested on WordPress 5.7-alpha-49644-src.

Note: See TracTickets for help on using tickets.