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

Full Site Editing: Fix Site Title Save Bug #24302

Merged
merged 1 commit into from
Aug 5, 2020
Merged

Full Site Editing: Fix Site Title Save Bug #24302

merged 1 commit into from
Aug 5, 2020

Conversation

jeyip
Copy link
Contributor

@jeyip jeyip commented Jul 31, 2020

Fixes #24003

Description

Users could not save updates to the Site Title block in Full Site Editing.

There were changes introduced in a previous PR #22876 that aimed to avoid dirtying un-customized templates on first load. The modifications introduced metadata to be evaluated before saving block editor updates. These included record title and record status as seen here.

Unfortunately, Site Title also uses the title attribute, which, inadvertently, was being overridden by the record title.

// When the save button is clicked, the stack trace eventually leads here
// packages/core-data/src/actions.js:234

// the edits param looks like { status: 'publish', title: record.slug }
// it was introduced in #22876
// when saving a site title, record.slug will be undefined (there is no "slug" attribute for the site settings record)
Object.keys( edits ).reduce( ( acc, key ) => {
	const recordValue = record[ key ];
        
        // editedRecord looks like { title: 'My brand spanking new site title', ...rest }
	const editedRecordValue = editedRecord[ key ];
        
        // Where the record title overrides the site title
	const value = mergedEdits[ key ]
		? { ...editedRecordValue, ...edits[ key ] }
		: edits[ key ];
	acc[ key ] = isEqual( recordValue, value ) ? undefined : value;
	return acc;
}, {} ),

More context can be seen here in the core/data library.

Solution

Note: I am going to lean on the expertise of others because I may be missing some context, and my solution may not be ideal.

The fix ensures that, if the record slug does not exist, then an undefined title is not included as metadata. This prevents the undefined title from overriding updates to site title.

How has this been tested?

  1. Navigate to the full site editor
  2. Modify any instance of the site title block
  3. Click on the "Update Design" button
  4. Click on the "Save" button
  5. Refresh the page to ensure that the Site Title has been persisted
  6. Navigate to a separate page or post and add the Site Title block. Ensure that it reflects the updated site title.

Screenshots

site title bug

Types of changes

Bug fix

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR.

@jeyip jeyip requested a review from youknowriad as a code owner July 31, 2020 01:21
@jeyip jeyip changed the title Prevent title override when saving entities Fix Site Title Save Bug Jul 31, 2020
@jeyip jeyip self-assigned this Aug 4, 2020
@jeyip jeyip added the [Type] Bug An existing feature does not function as intended label Aug 4, 2020
@jeyip jeyip requested review from noahtallen and epiqueras August 5, 2020 16:32
@jeyip jeyip changed the title Fix Site Title Save Bug Full Site Editing: Fix Site Title Save Bug Aug 5, 2020
@jeyip jeyip merged commit 5660e7b into WordPress:master Aug 5, 2020
@jeyip jeyip deleted the fix/site-title-block-not-saving branch August 5, 2020 17:37
@github-actions github-actions bot added this to the Gutenberg 8.8 milestone Aug 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Site Title Block changes not saving
2 participants