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

Attempting to rename Template Part deletes Template Part #24000

Closed
annezazu opened this issue Jul 16, 2020 · 16 comments · Fixed by #24500
Closed

Attempting to rename Template Part deletes Template Part #24000

annezazu opened this issue Jul 16, 2020 · 16 comments · Fixed by #24500
Assignees
Labels
[Feature] Templates API Related to API powering block template functionality in the Site Editor [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended

Comments

@annezazu
Copy link
Contributor

Describe the bug

When trying to edit the template part name, the entire template section is removed. cc @epiqueras since this might be resolved with your PR #23661

To reproduce
Steps to reproduce the behavior:

  1. Enable Full Site Editing and the demo content.
  2. Head to Site Editor (beta) tab.
  3. Try to edit the template part name
  4. The entire template part will be removed.

Expected behavior

I expected the template part to be renamed.

Screenshots

Here's a video of me walking through this (44 seconds): https://cloudup.com/cc_RpdQWy8F

Editor version (please complete the following information):

  • WordPress version: 5.4.2
  • Does the website has Gutenberg plugin installed, or is it using the block editor that comes by default? Gutenberg plugin
  • If the Gutenberg plugin is installed, which version is it? 8.5.1

Desktop (please complete the following information):

  • OS: iOS
  • Browser: Chrome
  • Version: 83.0.4103.116
@annezazu annezazu added [Type] Bug An existing feature does not function as intended [Feature] Templates API Related to API powering block template functionality in the Site Editor [Feature] Full Site Editing labels Jul 16, 2020
@epiqueras
Copy link
Contributor

Does #23661 fix it?

@noahtallen
Copy link
Member

Possibly related: #22639

@ZebulanStanphill
Copy link
Member

Does #23661 fix it?

No. Interestingly, I can only reproduce this bug with the template parts created by the Full Site Editing Demo Templates experiment. If I create a new Template Part, I have no trouble renaming it, even after a save and refresh.

@ZebulanStanphill
Copy link
Member

The issue also happens with Template Parts provided by a block-based theme, so I think the issue may have something to do with the difference between those and user-created Template Parts.

@Addison-Stavlo
Copy link
Contributor

Addison-Stavlo commented Jul 22, 2020

The issue also happens with Template Parts provided by a block-based theme

Interesting, I am able to reproduce as well without demo-templates. It seems that the renaming is problematic if we haven't saved a custom version of the template part.

Template part disappears when:

  • Navigate to site editor.
  • Immediately rename the 'fresh' theme supplied template part.

Does not have an issue when:

  • Navigate to site editor.
  • Edit the template part and 'save' (or have done this with the template part in the past).
  • Rename the template part.

@ZebulanStanphill
Copy link
Member

I guess once you edit and save the content of a template part originally provided by a theme, it stops being sourced from the theme since its been modified, so I guess that's why renaming works afterwards.

@Addison-Stavlo
Copy link
Contributor

Addison-Stavlo commented Jul 22, 2020

I guess once you edit and save the content of a template part originally provided by a theme, it stops being sourced from the theme since its been modified, so I guess that's why renaming works afterwards.

Right.. something along those lines.

So initially the theme references the template part by a name and has a template-part file with that name. When we change the name to something else, the file with that new name is not found and the template part disappears from the editor.

When we edit the template part first and 'save', the Template is also updated and saved to reference the new template part cpt with a given ID. So when that name is updated it still has the ID to display the template part.

@epiqueras
Copy link
Contributor

Renaming it needs to save as well then.

@Addison-Stavlo
Copy link
Contributor

Addison-Stavlo commented Jul 22, 2020

Renaming it needs to save as well then.

Or maybe we shouldn't allow renaming if it's not saved? Or a more elegant way of handling this?

I feel like the forcing a save is going to be problematic? It would need to save the template part and template as soon as the user types into the name input. If there are already changes dirtied in the template or template part the forced save would either overwrite those changes to only save the new TP name / how the template references it, or will save all those other dirty changes without user confirmation? Either case seems problematic.

Perhaps what needs to happen is in the case that the Template Part is being referenced by slug and has no id, then when the input is changed it will need to continue to reference by that old slug until we are able to save. The fact that it's looking for that new slug as soon as we edit the input is what is causing it to disappear.

@epiqueras
Copy link
Contributor

Good points. That sounds like a sensible solution.

@ZebulanStanphill
Copy link
Member

ZebulanStanphill commented Jul 23, 2020

Perhaps a theme-supplied template part should be in read-only mode by default, with a button exposed to enable customizing it. Upon pressing this button, a user-created clone of the template part will be created and the block will be updated to reference the user one rather than the theme one. That makes the action a bit more explicit, which makes it clearer that you're no longer using the unmodified theme template part.

@MichaelArestad
Copy link
Contributor

I would expect to be able to rename a template part without hitting save until I am ready. I expect the template part to remain in place with the new name.

@noahtallen
Copy link
Member

It would need to save the template part and template as soon as the user types into the name input.

Should we just delay persistent changes to the title until clicking save? Doesn't it currently update the actual title in the DB just when typing in the field?

@ZebulanStanphill
Copy link
Member

ZebulanStanphill commented Aug 11, 2020

It would need to save the template part and template as soon as the user types into the name input.

Should we just delay persistent changes to the title until clicking save? Doesn't it currently update the actual title in the DB just when typing in the field?

If it is currently updating the DB immediately upon typing, then that's inefficient, and it should definitely be changed to only happen upon save.

@Addison-Stavlo
Copy link
Contributor

Should we just delay persistent changes to the title until clicking save? Doesn't it currently update the actual title in the DB just when typing in the field?

I think whats happening is when you type in to change the name, it uses setAttribute on the block to change the slug attribute (not necessarily save it). But since there is no ID at this stage, the slug is the only thing used to find the template part. The component tries to retrieve this after the block updates from setAttribute, but a template part file corresponding to this new slug doesn't exist. So we need to NOT re-retrieve the entity when the slug changes (probably only when an Id is not present?)

@Addison-Stavlo
Copy link
Contributor

Addison-Stavlo commented Aug 11, 2020

Edit - I think #24500 has a good working fix now.

#24500 fixes the issue with the template part disappearing, but it surfaces another issue in the next step of the process.

I am noticing once I go to 'save', the template part can be replaced with a different auto-draft template part of the same initial slug. It seems like its an issue with the template saving with undefined as the value for the template part block's postId attribute.

It works as expected when:

  • The template is already saved.
  • We re-name and save ONLY the template part
  • We then save the template

It can replace with a different auto-drafted template part by the same slug when:

  • The template has never been saved.
  • Or the template and unsaved template part are saved at the same time.

Reloading brings the proper template part back into place. 🤔

@github-actions github-actions bot added the [Status] In Progress Tracking issues with work in progress label Aug 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Templates API Related to API powering block template functionality in the Site Editor [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants