WordPress.org

Make WordPress Core

Opened 6 months ago

Closed 2 months ago

Last modified 2 months ago

#53813 closed defect (bug) (fixed)

Do not provide initial_edits for properties that are not supported by the current post type.

Reported by: youknowriad Owned by: audrasjb
Milestone: 5.9 Priority: normal
Severity: normal Version: 5.8
Component: Editor Keywords: good-first-bug has-patch commit
Focuses: Cc:

Description

I noticed that edit-form-blocks.php (block editor initialization) always provides "title", "content" and "excerpt" initial edits in the initializeEditor call even though these properties might not be supported by the current post type being edited.

This creates a subtle bug in the post editor where as soon as you open a "new post", the editor considers the content "dirty", meaning changes are applied and you can't "leave" the editor without having the "unsaved changes" notice.

I think we should consider updating the $initial_edits variable declaration to only add the properties that are supported by the current CPT.

Attachments (3)

53813.diff (1.1 KB) - added by h71 4 months ago.
53813.2.diff (1.1 KB) - added by h71 4 months ago.
Empty line removed.
a36db167e65d579d6d25f42a79a09567.mp4 (2.4 MB) - added by audrasjb 2 months ago.
Reproducing the issue by removing "excerpt" support in a custom post type

Change History (22)

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


4 months ago

This ticket was mentioned in PR #1743 on WordPress/wordpress-develop by hectorfarahani.


4 months ago

  • Keywords has-patch added

@h71
4 months ago

@h71
4 months ago

Empty line removed.

#3 @h71
4 months ago

My first patch! I had to wait for Github checks. The new diff is attached after passing all checks.

This ticket was mentioned in Slack in #core-editor by h71. View the logs.


3 months ago

#5 @audrasjb
2 months ago

  • Owner set to audrasjb
  • Status changed from new to reviewing

Self-assigning for review.

@audrasjb
2 months ago

Reproducing the issue by removing "excerpt" support in a custom post type

#6 @audrasjb
2 months ago

I can confirm the proposed patch fixes the issue.

Marking for commit.

#7 @audrasjb
2 months ago

  • Keywords commit added

#9 @audrasjb
2 months ago

Tests are passing well.

#10 @audrasjb
2 months ago

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

In 52230:

Editor: Do not provide initial_edits for properties that are not supported by the current post type.

Previously, the block editor initialization always provided "title", "content" and "excerpt" initial edits in the initializeEditor call even though these properties might not be supported by the current post type being edited. This leads to a bug in the post editor where as soon as one would open a "new post", the editor considers the content "dirty", meaning changes are applied and it is not possible to leave the editor without encountering an "unsaved changes" notice.

This change updates the $initial_edits variable declaration to only provide the properties that are supported by the current post type.

Props youknowriad, h71.
Fixes #53813.

#11 @prbot
2 months ago

audrasjb commented on PR #1927:

Fixed in 52230

#12 @prbot
2 months ago

audrasjb commented on PR #1743:

Fixed in 52230

#13 @talldanwp
2 months ago

Just want to surface my comment on the PR here - https://github.com/WordPress/wordpress-develop/pull/1743#discussion_r754031590

Looks like this fix caused a bug.

I've created a PR to fix the problem - https://github.com/WordPress/wordpress-develop/pull/1929

Last edited 2 months ago by talldanwp (previous) (diff)

This ticket was mentioned in PR #1929 on WordPress/wordpress-develop by talldan.


2 months ago

Trac ticket: https://core.trac.wordpress.org/ticket/53813

This PR fixes an issue with the already submitted patch for that trac ticket.

See https://github.com/WordPress/wordpress-develop/pull/1743#discussion_r754031590 for details.

#15 @prbot
2 months ago

audrasjb commented on PR #1929:

Thanks for the fix @talldan, I'll commit this in few mins

#16 @SergeyBiryukov
2 months ago

In 52231:

Editor: Check the correct post type support property for initial_edits.

The property to check should be editor instead of content, as posts don't have a content support property.

This addresses an e2e test failure in Gutenberg.

Follow-up to [52230].

Props talldanwp.
See #53813.

#17 @prbot
2 months ago

audrasjb commented on PR #1929:

Committed by @SergeyBiryukov in the meantime 😉

#18 @prbot
2 months ago

SergeyBiryukov commented on PR #1929:

Sorry, didn't know you were around too 😅

#19 @prbot
2 months ago

audrasjb commented on PR #1929:

No worries, and thank you for jumping into this :)

Note: See TracTickets for help on using tickets.