Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#63959: Add title attribute to post save action #68537

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

dhananjaykuber
Copy link
Contributor

@dhananjaykuber dhananjaykuber commented Jan 7, 2025

Fixes #63959

What?

Add post title to save payload regardless of modification status to ensure consistent title synchronization across multiple editor sessions.

Why?

Currently, the post title is only included in the save payload when it has been modified in the current editing session. This creates inconsistent behavior when editing a post in multiple windows/tabs:

Changes to the title in one window can be inadvertently overwritten when saving content from another window
Users experience unexpected title changes when saving, leading to confusion
The current behavior violates the principle of least surprise - users expect all post content (including title) to be saved consistently

How?

Modified the savePost action to always include the current post title in the save payload by adding:

const title = select.getEditedPostAttribute( 'title' );

let edits = {
	id: previousRecord.id,
	title,
	...registry
		.select( coreStore )
		.getEntityRecordNonTransientEdits(
			'postType',
			previousRecord.type,
			previousRecord.id
		),
	content,
};

Testing Instructions

  1. Create a new post with a title and some content
  2. Save the post
  3. Open the same post in two different browser windows/tabs (Window A and Window B)
  4. In Window B, change the post title and save
  5. In Window A, make a change to the post content (without modifying the title)
  6. Save changes in Window A
  7. Verify that the title remains unchanged in Window A (previously, it would revert to the title from Window B)

Screenshots or screencast

screen-capture.1.webm

Copy link

github-actions bot commented Jan 7, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: dhananjaykuber <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Post title should be saved to DB on every save event
1 participant