WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.36k stars 4.13k forks source link

Site Editor: Unexpected "undo" behavior in StrictMode #63167

Open Mamaduka opened 2 months ago

Mamaduka commented 2 months ago

I noticed unexpected behavior when undoing changes in the Site Editor and React StrictMode is enabled.

After undoing the recently made changes, there are extra history records, and the template part content is gone after the changes are entirely undone. The issue affects unmodified template parts with the Navigation block.

[!NOTE]
The bug doesn't affect WP 6.6 or production websites running the Gutenberg plugin.

Testing Instructions

  1. Enabled SCRIPT_DEBUG so React code runs in a StrictMode.
  2. Using TT4.
  3. Ensure that the Header template part and template used for testing have no changes. They're loaded from a file.
  4. Open a template like "Page: 404".
  5. Make changes to the content or template part.
  6. Undo the changes.
  7. Notice that there are more "undo" steps than actual changes.
  8. Fully undoing clears out the header template part.

Screencast

https://github.com/WordPress/gutenberg/assets/240569/3684a74c-9f79-4af8-b9eb-f770dede21dc

https://github.com/WordPress/gutenberg/assets/240569/fa50dc77-b086-4984-ab9f-360cc2d49acb

Mamaduka commented 2 weeks ago

I noticed similar behavior with the File block in the post editor, which updates attributes on the mount.

  1. Enabled SCRIPT_DEBUG so React code runs in a StrictMode.
  2. Insert some content.
  3. Insert a file block and select file.
  4. Disable the "Show download button".
  5. Reload the page.
  6. Notice there's an "Undo" action active.
  7. Undo the changes, and the whole content disappears.

Screencast

https://github.com/user-attachments/assets/f6e2c1a8-5d7e-4b9e-8db4-06cf58a58f3b