Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 2 years ago

#52038 closed defect (bug) (fixed)

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

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

Description

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():

https://github.com/woocommerce/woocommerce/blob/master/includes/admin/meta-boxes/class-wc-meta-box-product-short-description.php#L35

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 4 years ago.
Screenshot of post edit screen with a wp_editor field and the JavaScript change alert
52038.diff (3.6 KB) - added by azaozz 4 years ago.
metalcoffee-52028-testing.gif (2.2 MB) - added by metalandcoffee 4 years ago.
Tested on WordPress 5.7-alpha-49644-src.

Change History (24)

#1 @jonathanstegall
4 years 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 4 years ago by jonathanstegall (previous) (diff)

@jonathanstegall
4 years ago

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

#2 @ifnoob
4 years ago

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

#3 @kevin940726
4 years ago

#52080 was marked as a duplicate.

#4 @azaozz
4 years ago

Screencapture gif from 52080:

https://core.trac.wordpress.org/raw-attachment/ticket/52080/Kapture%202020-12-15%20at%2015.57.08.gif

#5 @azaozz
4 years 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
4 years ago

  • Milestone changed from Awaiting Review to 5.6.1

@azaozz
4 years ago

#7 follow-up: @rodrigosprimo
4 years 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
4 years ago

Replying to rodrigosprimo:

Thanks for testing!

Going to commit this to trunk hoping it will get some more testing as it touches on showing the "Are you sure" message for the content editor too.

Version 0, edited 4 years ago by azaozz (next)

#9 @azaozz
4 years 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
4 years 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
4 years ago

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

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

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


4 years ago

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


4 years ago

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


4 years ago

#15 @metalandcoffee
4 years 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?

@metalandcoffee
4 years ago

Tested on WordPress 5.7-alpha-49644-src.

#16 @whyisjake
4 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 50031:

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.

This brings the changes from [49807] to the 5.6 branch.

Props rodrigosprimo, jonathanstegall, kevin940726, azaozz, metalandcoffee, ifnoob.

Fixes #52038.

#18 @papazetis
4 years ago

I now got this weird message on Pages and CPTs after updating wp to 5.6.1

I checked posts and products and no pop up message is shown.

#19 @QantumThemes
4 years ago

Clearly a core bug that needs fixing. Very annoying

#20 @georgecarvill
4 years ago

  • Version set to 5.6.1

This bug is NOT fixed in 5.6.1.

Last edited 4 years ago by georgecarvill (previous) (diff)

#21 @busylizzycreations
2 years ago

This bug is NOT fixed with version: 6.0.3

Note: See TracTickets for help on using tickets.